#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels
#define OLED_RESET -1 // Reset pin # (or -1 if sharing Arduino reset pin)
#define SCREEN_ADDRESS 0x3C ///< See datasheet for Address; 0x3D for 128x64, 0x3C for 128x32
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
int selected = 0;
int entered = -1;
int menuexit = 0;
unsigned long lastDebounceTime = 0;
unsigned long debounceDelay = 50;
unsigned long longpressDelay = 1000;
unsigned long buttonLongStartTime = 0;
// Bitmap of wave Image
const unsigned char wave [] PROGMEM = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7c, 0x00, 0x03, 0xff, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0xf0, 0x00, 0x07, 0xf3, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0xe0, 0x00, 0x0f, 0xc7, 0xf8, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0xc0, 0x00, 0x1f, 0x0e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x0f, 0x80, 0x00, 0x3f, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0x80, 0x00, 0x3e, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0x00, 0x00, 0x7c, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0x00, 0x00, 0xf8, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0x00, 0x01, 0xf0, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x1d, 0x80, 0x03, 0xe0, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x0d, 0x80, 0x07, 0xc0, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x0c, 0xc0, 0x1f, 0x80, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x60, 0xfd, 0x00, 0x02, 0x1c, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0xbf, 0xfc, 0x00, 0x00, 0xff, 0xc0, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3f, 0xff, 0x00, 0x03, 0xfd, 0xe0, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3f, 0x1f, 0x80, 0x07, 0xe3, 0xf0, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7e, 0x3c, 0x40, 0x0f, 0x87, 0x80, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfc, 0x70, 0x00, 0x1f, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0xf8, 0x60, 0x00, 0x1e, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0xf0, 0xc0, 0x00, 0x3c, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0xe0, 0xc0, 0x00, 0x78, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0xc0, 0xc0, 0x00, 0xf0, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x0f, 0x80, 0xc0, 0x01, 0xe0, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0x00, 0x40, 0x03, 0xc0, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x7e, 0x00, 0x60, 0x0f, 0x80, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x01, 0xf8, 0x00, 0x30, 0x3f, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x0f, 0xf0, 0x00, 0x1f, 0xff, 0x00, 0x01, 0x80, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x3f, 0xc0, 0x00, 0x03, 0xf8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
void displaymainmenu(void) {
int down = digitalRead(3);
int up = digitalRead(4);
int enter = digitalRead(2);
int back = digitalRead(5);
if (up == LOW && down == LOW) {
};
if (( (millis() - lastDebounceTime) > debounceDelay)) {
if (up == LOW) {
selected = selected + 1;
delay(20);
}
if (down == LOW) {
selected = selected - 1;
};
if (enter == LOW) {
entered = selected;
};
if (back == LOW) {
entered = -1;
};
lastDebounceTime = millis();
delay(100);
};
const char *options[6] = {
" Select Beach",
" Connect to Wifi",
" Alarm Settings",
" Support",
" Information ",
" Exit "
};
Serial.println(selected);
if (selected == 6){
selected = 5;
} else if (selected < 0){
selected = 0;
}
if (entered == -1) {
display.clearDisplay();
display.setTextSize(2);
display.setTextColor(SSD1306_WHITE);
display.setCursor(0, 0);
display.println(F("Settings"));
display.setTextSize(1);
for (int i = 0; i < 6; i++) {
if (i == selected) {
display.setTextColor(SSD1306_BLACK, SSD1306_WHITE);
display.println(options[i]);
} else if (i != selected) {
display.setTextColor(SSD1306_WHITE);
display.println(options[i]);
}
}
} else if (entered == 0) {
selectbeach();
} else if (entered == 1) {
display.clearDisplay();
display.setTextSize(1);
display.setTextColor(SSD1306_WHITE);
display.setCursor(0, 0);
display.println(F("Dsn menu test"));
display.println("Menu option 2");
display.setTextColor(SSD1306_WHITE);
display.setTextSize(2);
display.println("Dsn Menu system :)");
} else if (entered == 2) {
display.clearDisplay();
display.setTextSize(1);
display.setTextColor(SSD1306_WHITE);
display.setCursor(0, 0);
display.println(F("Dsn menu test"));
display.println("Menu option 3");
display.setTextColor(SSD1306_WHITE);
display.setTextSize(2);
display.println("Dsn Menu system:)");
} else if (entered == 3) {
display.clearDisplay();
display.setTextSize(1);
display.setTextColor(SSD1306_WHITE);
display.setCursor(0, 0);
display.println(F("Dsn menu test"));
display.println("Menu option 4");
display.setTextColor(SSD1306_WHITE);
display.setTextSize(2);
display.println("Dsn Menu system:)");
} else if (entered == 4) {
display.clearDisplay();
display.setTextSize(1);
display.setTextColor(SSD1306_WHITE);
display.setCursor(0, 0);
display.println(F("Dsn menu test"));
display.println("Menu option 5");
display.setTextColor(SSD1306_WHITE);
display.setTextSize(2);
display.println("Dsn Menu system:)");
} else if (entered == 5) {
menuexit = 1;
selected = 0;
entered = -1;
}
display.display();
}
void displaybeachmenu(void) {
int down = digitalRead(3);
int up = digitalRead(2);
int enter = digitalRead(4);
int back = digitalRead(5);
if (up == LOW && down == LOW) {
};
if (( (millis() - lastDebounceTime) > debounceDelay)) {
if (up == LOW) {
selected = selected + 1;
delay(20);
}
if (down == LOW) {
selected = selected - 1;
};
if (enter == LOW) {
entered = selected;
};
if (back == LOW) {
entered = -1;
};
lastDebounceTime = millis();
delay(100);
};
const char *options[6] = {
" 1) Portreath",
" 2) Gwithian",
" 3) Portreath",
" 4) Portreath",
" 5) Portreath",
" 6) Exit "
};
Serial.println(selected);
if (selected == 6){
selected = 5;
} else if (selected < 0){
selected = 0;
}
if (entered == -1) {
display.clearDisplay();
display.setTextSize(2);
display.setTextColor(SSD1306_WHITE);
display.setCursor(0, 0);
display.println(F("Settings"));
display.setTextSize(1);
for (int i = 0; i < 6; i++) {
if (i == selected) {
display.setTextColor(SSD1306_BLACK, SSD1306_WHITE);
display.println(options[i]);
} else if (i != selected) {
display.setTextColor(SSD1306_WHITE);
display.println(options[i]);
}
}
} else if (entered == 0) {
display.clearDisplay();
display.setTextSize(1);
display.setTextColor(SSD1306_WHITE);
display.setCursor(0, 0);
display.println(F("You selected Portreath"));
display.display();
delay(4000);
menuexit = 1;
selected = 0;
entered = -1;
} else if (entered == 1) {
display.clearDisplay();
display.setTextSize(1);
display.setTextColor(SSD1306_WHITE);
display.setCursor(0, 0);
display.println(F("You selected Gwithian"));
display.display();
delay(4000);
menuexit = 1;
selected = 0;
entered = -1;
} else if (entered == 2) {
display.clearDisplay();
display.setTextSize(1);
display.setTextColor(SSD1306_WHITE);
display.setCursor(0, 0);
display.println(F("Dsn menu test"));
display.println("Menu option 3");
display.setTextColor(SSD1306_WHITE);
display.setTextSize(2);
display.println("Dsn Menu system:)");
} else if (entered == 3) {
display.clearDisplay();
display.setTextSize(1);
display.setTextColor(SSD1306_WHITE);
display.setCursor(0, 0);
display.println(F("Dsn menu test"));
display.println("Menu option 4");
display.setTextColor(SSD1306_WHITE);
display.setTextSize(2);
display.println("Dsn Menu system:)");
} else if (entered == 4) {
display.clearDisplay();
display.setTextSize(1);
display.setTextColor(SSD1306_WHITE);
display.setCursor(0, 0);
display.println(F("Dsn menu test"));
display.println("Menu option 5");
display.setTextColor(SSD1306_WHITE);
display.setTextSize(2);
display.println("Dsn Menu system:)");
} else if (entered == 5) {
menuexit = 1;
selected = 0;
entered = -1;
}
display.display();
}
void setup() {
const char* TideTitle = "Tide Clock";
int textPosition = (SCREEN_WIDTH - strlen(TideTitle))/2;
pinMode(2, INPUT_PULLUP);
pinMode(3, INPUT_PULLUP);
pinMode(4, INPUT_PULLUP);
pinMode(5, INPUT_PULLUP);
Serial.begin(9600);
if (!display.begin(SSD1306_SWITCHCAPVCC, SCREEN_ADDRESS)) {
Serial.println(F("SSD1306 allocation failed"));
for (;;); // Don't proceed, loop forever
}
uint16_t time = millis();
time = millis() - time;
display.clearDisplay();
// Draw a single pixel in white
display.drawBitmap(0, 0, wave, 128, 64, WHITE);
display.display();
delay(2000); // Pause for 2 seconds
}
void selectbeach(){;
entered = -1;
delay(200);
do {
displaybeachmenu();
} while (menuexit == 0);
}
void loop() {
int selected = 0;
display.clearDisplay();
display.setTextSize(2); // Normal 1:1 pixel scale
display.setTextColor(SSD1306_WHITE); // Draw white text
display.setCursor(5,25); // Start at top-left corner
display.println("Tide Clock");
display.display();
int enter = digitalRead(4);
if (( (millis() - lastDebounceTime) > debounceDelay)) {
if (enter == LOW) {
//while (digitalRead(4 == LOW)) {}
display.clearDisplay();
delay(200);
menuexit =0;
Serial.println(selected);
// put your main code here, to run repeatedly:
do {
displaymainmenu();
} while (menuexit == 0);
}
lastDebounceTime = millis(); //Reset debounce lastButtonState = buttonState; //Reset buttonState
}
}
Loading
esp32-s2-devkitm-1
esp32-s2-devkitm-1
Loading
ssd1306
ssd1306