mirror of
https://github.com/Crocmagnon/buzzer.git
synced 2024-11-24 08:58:06 +01:00
Setup oled display
This commit is contained in:
parent
0b2a0c702a
commit
14f4b14948
2 changed files with 39 additions and 4 deletions
|
@ -19,3 +19,5 @@ lib_deps =
|
||||||
AsyncTCP
|
AsyncTCP
|
||||||
bblanchon/ArduinoJson
|
bblanchon/ArduinoJson
|
||||||
https://github.com/schreibfaul1/ESP32-audioI2S.git
|
https://github.com/schreibfaul1/ESP32-audioI2S.git
|
||||||
|
adafruit/Adafruit SSD1306
|
||||||
|
adafruit/Adafruit GFX Library
|
||||||
|
|
41
src/main.cpp
41
src/main.cpp
|
@ -3,6 +3,10 @@
|
||||||
#include <SPIFFS.h>
|
#include <SPIFFS.h>
|
||||||
#include <AsyncJson.h>
|
#include <AsyncJson.h>
|
||||||
#include <Audio.h>
|
#include <Audio.h>
|
||||||
|
#include <SPI.h>
|
||||||
|
#include <Wire.h>
|
||||||
|
#include <Adafruit_GFX.h>
|
||||||
|
#include <Adafruit_SSD1306.h>
|
||||||
#include "creds.h"
|
#include "creds.h"
|
||||||
|
|
||||||
// #define B_WIFI_AP
|
// #define B_WIFI_AP
|
||||||
|
@ -14,6 +18,17 @@
|
||||||
#define LED 2
|
#define LED 2
|
||||||
#define BUTTON 18
|
#define BUTTON 18
|
||||||
|
|
||||||
|
#define SSD1306_NO_SPLASH
|
||||||
|
#define SCREEN_WIDTH 128
|
||||||
|
#define SCREEN_HEIGHT 64
|
||||||
|
#define OLED_RESET -1
|
||||||
|
#define SCREEN_ADDRESS 0x3C
|
||||||
|
|
||||||
|
#define LOGO_HEIGHT 16
|
||||||
|
#define LOGO_WIDTH 16
|
||||||
|
|
||||||
|
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
|
||||||
|
|
||||||
String selectedFile = "";
|
String selectedFile = "";
|
||||||
|
|
||||||
AsyncWebServer server(80);
|
AsyncWebServer server(80);
|
||||||
|
@ -104,8 +119,8 @@ void setup()
|
||||||
#ifdef B_WIFI_AP
|
#ifdef B_WIFI_AP
|
||||||
Serial.println("Setting up AP...");
|
Serial.println("Setting up AP...");
|
||||||
WiFi.softAP(ssid, password);
|
WiFi.softAP(ssid, password);
|
||||||
Serial.print("IP address: ");
|
String wifiIP = WiFi.softAPIP().toString();
|
||||||
Serial.println(WiFi.softAPIP());
|
String wifiMode = "AP";
|
||||||
#else
|
#else
|
||||||
Serial.print("Connecting to wifi...");
|
Serial.print("Connecting to wifi...");
|
||||||
WiFi.begin(ssid, password);
|
WiFi.begin(ssid, password);
|
||||||
|
@ -115,9 +130,11 @@ void setup()
|
||||||
delay(500);
|
delay(500);
|
||||||
}
|
}
|
||||||
Serial.println();
|
Serial.println();
|
||||||
Serial.print("IP address: ");
|
String wifiIP = WiFi.localIP().toString();
|
||||||
Serial.println(WiFi.localIP());
|
String wifiMode = "client";
|
||||||
#endif
|
#endif
|
||||||
|
String wifiMessage = wifiMode + " IP: " + wifiIP;
|
||||||
|
Serial.println(wifiMessage);
|
||||||
|
|
||||||
// Server
|
// Server
|
||||||
server.on("/play", HTTP_GET, onPlay);
|
server.on("/play", HTTP_GET, onPlay);
|
||||||
|
@ -130,9 +147,25 @@ void setup()
|
||||||
|
|
||||||
Serial.println("Server ready!");
|
Serial.println("Server ready!");
|
||||||
|
|
||||||
|
// Audio
|
||||||
audio.setPinout(I2S_BCLK, I2S_LRC, I2S_DOUT);
|
audio.setPinout(I2S_BCLK, I2S_LRC, I2S_DOUT);
|
||||||
audio.setVolume(21); // Max 21
|
audio.setVolume(21); // Max 21
|
||||||
|
|
||||||
|
// Screen
|
||||||
|
|
||||||
|
// SSD1306_SWITCHCAPVCC = generate display voltage from 3.3V internally
|
||||||
|
if(!display.begin(SSD1306_SWITCHCAPVCC, SCREEN_ADDRESS)) {
|
||||||
|
Serial.println(F("SSD1306 allocation failed"));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
display.clearDisplay();
|
||||||
|
display.setTextSize(1);
|
||||||
|
display.setTextColor(WHITE);
|
||||||
|
display.setCursor(0, 0);
|
||||||
|
display.println(wifiMessage);
|
||||||
|
display.display();
|
||||||
|
|
||||||
|
// Setup is done, light up the LED
|
||||||
digitalWrite(LED, HIGH);
|
digitalWrite(LED, HIGH);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue