Add OLED Display
This commit is contained in:
@@ -14,5 +14,5 @@ board = esp32doit-devkit-v1
|
|||||||
framework = arduino
|
framework = arduino
|
||||||
lib_deps =
|
lib_deps =
|
||||||
ayushsharma82/AsyncElegantOTA@^2.2.7
|
ayushsharma82/AsyncElegantOTA@^2.2.7
|
||||||
#me-no-dev/ESP Async WebServer@^1.2.3
|
https://github.com/me-no-dev/ESPAsyncWebServer.git
|
||||||
https://github.com/me-no-dev/ESPAsyncWebServer.git
|
adafruit/Adafruit SSD1306@^2.5.7
|
||||||
|
|||||||
50
src/main.cpp
50
src/main.cpp
@@ -1,14 +1,9 @@
|
|||||||
|
#include <Adafruit_SSD1306.h>
|
||||||
#include <Arduino.h>
|
#include <Arduino.h>
|
||||||
#if defined(ESP8266)
|
|
||||||
#include <ESP8266WiFi.h>
|
|
||||||
#include <ESPAsyncTCP.h>
|
|
||||||
#elif defined(ESP32)
|
|
||||||
#include <AsyncTCP.h>
|
|
||||||
#include <WiFi.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include <AsyncElegantOTA.h>
|
#include <AsyncElegantOTA.h>
|
||||||
|
#include <AsyncTCP.h>
|
||||||
#include <ESPAsyncWebServer.h>
|
#include <ESPAsyncWebServer.h>
|
||||||
|
#include <WiFi.h>
|
||||||
|
|
||||||
const char* ssid = "JoNelsDarlings";
|
const char* ssid = "JoNelsDarlings";
|
||||||
const char* password = "Paris2016";
|
const char* password = "Paris2016";
|
||||||
@@ -19,10 +14,36 @@ unsigned long lastMillis = millis();
|
|||||||
|
|
||||||
AsyncWebServer server(80);
|
AsyncWebServer server(80);
|
||||||
|
|
||||||
|
// Declaration for an SSD1306 display connected to I2C (SDA, SCL pins)
|
||||||
|
// I connected SCL to D22 and SDA to D21
|
||||||
|
#define SCREEN_WIDTH 128 // OLED display width, in pixels
|
||||||
|
#define SCREEN_HEIGHT 64 // OLED display height, in pixels
|
||||||
|
|
||||||
|
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);
|
||||||
|
|
||||||
|
void writeToOled(String text) {
|
||||||
|
display.clearDisplay();
|
||||||
|
display.setTextColor(WHITE);
|
||||||
|
display.setCursor(0, 0);
|
||||||
|
display.setTextSize(2);
|
||||||
|
display.print(text);
|
||||||
|
display.display();
|
||||||
|
}
|
||||||
|
|
||||||
void setup(void) {
|
void setup(void) {
|
||||||
pinMode(LED_BUILTIN, OUTPUT);
|
pinMode(LED_BUILTIN, OUTPUT);
|
||||||
digitalWrite(LED_BUILTIN, LOW);
|
digitalWrite(LED_BUILTIN, LOW);
|
||||||
Serial.begin(115200);
|
Serial.begin(9600);
|
||||||
|
|
||||||
|
if (!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) { // Address 0x3D for 128x64
|
||||||
|
Serial.println(F("SSD1306 allocation failed"));
|
||||||
|
for (;;)
|
||||||
|
;
|
||||||
|
}
|
||||||
|
delay(2000);
|
||||||
|
|
||||||
|
writeToOled("Startup");
|
||||||
|
|
||||||
WiFi.mode(WIFI_STA);
|
WiFi.mode(WIFI_STA);
|
||||||
WiFi.begin(ssid, password);
|
WiFi.begin(ssid, password);
|
||||||
Serial.println("");
|
Serial.println("");
|
||||||
@@ -54,22 +75,21 @@ void setup(void) {
|
|||||||
server.begin();
|
server.begin();
|
||||||
Serial.println("HTTP server started");
|
Serial.println("HTTP server started");
|
||||||
|
|
||||||
pinMode(BUBBLE_GPIO, INPUT_PULLDOWN);
|
pinMode(BUBBLE_GPIO, INPUT_PULLUP);
|
||||||
digitalWrite(LED_BUILTIN, HIGH);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop(void) {
|
void loop(void) {
|
||||||
// digitalWrite(LED_BUILTIN, digitalRead(BUBBLE_GPIO));
|
digitalWrite(LED_BUILTIN, digitalRead(BUBBLE_GPIO));
|
||||||
|
|
||||||
// This runs real fast, so make sure that only the "first contact" is measured
|
// This runs real fast, so make sure that only the "first contact" is measured
|
||||||
if ((digitalRead(BUBBLE_GPIO) == HIGH) && isBubbleFirstContact) {
|
if ((digitalRead(BUBBLE_GPIO) == LOW) && isBubbleFirstContact) {
|
||||||
digitalWrite(LED_BUILTIN, LOW);
|
|
||||||
if (millis() > lastMillis) { // don't measure if we had an overflow...
|
if (millis() > lastMillis) { // don't measure if we had an overflow...
|
||||||
bubbleFreqSec = (millis() - lastMillis) / 1000;
|
bubbleFreqSec = (millis() - lastMillis) / 1000;
|
||||||
|
writeToOled("Freq: " + String(bubbleFreqSec));
|
||||||
}
|
}
|
||||||
lastMillis = millis();
|
lastMillis = millis();
|
||||||
isBubbleFirstContact = false;
|
isBubbleFirstContact = false;
|
||||||
} else if ((digitalRead(BUBBLE_GPIO) == LOW)) {
|
} else if ((digitalRead(BUBBLE_GPIO) == HIGH)) {
|
||||||
isBubbleFirstContact = true;
|
isBubbleFirstContact = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user