#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
int winSwitch = 5;
int macSwitch = 6;
int button3 = 9;
int button4 = 10;
int switching = 1;
#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels
Adafruit_SSD1306 oled(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);
int modeNumber = 1;
String modePrint = "Mode " + String(modeNumber);
String bZ = "Z View";
void setup() {
Serial.begin(9600);
pinMode(winSwitch, INPUT);
pinMode(macSwitch, INPUT);
pinMode(button3, INPUT_PULLUP);
pinMode(button4, INPUT_PULLUP);
// initialize OLED display with address 0x3C for 128x64
if (!oled.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {
Serial.println(F("SSD1306 allocation failed"));
while (true);
}
oled.clearDisplay(); // clear display
oled.setTextSize(2); // text size
oled.setTextColor(WHITE); // text color
oled.setCursor(0, 10); // position to display
}
void loop() {
modeScreen();
if (digitalRead(winSwitch) || digitalRead(macSwitch)) {
if (!digitalRead(button3)) {
// z-view
oledDisplayCenter(bZ);
// Serial.print("3:3 is working ");
endPress();
}
}
}
void endPress() {
delay(250);
modeScreen();
}
void modeScreen() {
oledDisplayCenter(modePrint);
if (!digitalRead(button4)) {
switching += 1;
if (switching > 3) {
switching = 1;
}
modeNumber = switching;
modePrint = "Mode " + String(modeNumber);
oledDisplayCenter(modePrint);
// Serial.print(modePrint + " ");
delay(250);
}
}
void oledDisplayCenter(String text) {
int16_t x1;
int16_t y1;
uint16_t width;
uint16_t height;
oled.getTextBounds(text, 0, 0, &x1, &y1, &width, &height);
// display on horizontal and vertical center
oled.clearDisplay(); // clear display
oled.setCursor((SCREEN_WIDTH - width) / 2, (SCREEN_HEIGHT - height) / 2);
oled.println(text); // text to display
oled.display();
}
#define BLACK 0x0000
#define BLUE 0x001F
#define RED 0xF800
#define GREEN 0x07E0
#define CYAN 0x07FF
#define MAGENTA 0xF81F
#define YELLOW 0xFFE0
#define WHITE 0xFFFF