Hi all!
the menu is not displaying onto on the OLED and im not sure if there are any problems with the code.
there were no errors while compiling or uploading
#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SH110X.h>
#define i2c_Address 0x3C
#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 0x3D ///< See datasheet for Address; 0x3D for 128x64, 0x3C for 128x32
Adafruit_SH1107 display = Adafruit_SH1107(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
#define button_start 26
#define button_save 25
#define button_sel 33
int menuState = 0;
int menuItem = 1;
void setup() {
Serial.begin(9600);
display.begin(i2c_Address, true);
delay(2000);
display.clearDisplay();
// Set buttons as inputs
pinMode(button_start, INPUT);
pinMode(button_save, INPUT);
pinMode(button_sel, INPUT);
// Display menu
showMenu();
}
void loop() {
int startState = digitalRead(button_start);
int saveState = digitalRead(button_save);
int selState = digitalRead(button_sel);
// Loop to check which button is pressed
if (startState == HIGH) {
menuState = 1;
menuItem = 1;
}
if (selState == HIGH) {
menuItem = 2;
}
if (menuItem == 2 && startState == HIGH) {
menuState = 2;
}
// Update the display with the current menu state
showMenu();
}
void showMenu() {
display.clearDisplay();
display.setTextSize(1);
display.setTextColor(SH110X_WHITE);
display.setCursor(0, 0);
display.println("Menu");
// Display the options
display.setCursor(10, 10);
display.println("Start test");
display.setCursor(10, 20);
display.println("Menu");
switch (menuState) {
case 1:
display.setTextColor(SH110X_BLACK, SH110X_WHITE); // 'inverted' text
display.setCursor(10, 10);
display.println("Start test");
display.setTextColor(SH110X_WHITE);
display.setCursor(10, 20);
display.println("Menu");
//*add start test function*
break;
case 2:
display.setTextColor(SH110X_WHITE); // 'inverted' text
display.setCursor(10, 10);
display.println("Start test");
display.setTextColor(SH110X_BLACK, SH110X_WHITE);
display.setCursor(10, 20);
display.println("Menu");
display.clearDisplay();
break;
}
}