#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
// Declaration for an SSD1306 display connected to I2C (SDA, SCL pins)
#define OLED_RESET 4 // Reset pin # (or -1 if sharing Arduino reset pin)
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
// Interval between sensor readings. Learn more about ESP32 timers: https://RandomNerdTutorials.com/esp32-pir-motion-sensor-interrupts-timers/
unsigned long previousMillis = 0;
const long interval = 3000;
//Constants
const int screenPin = 4;
const int modePin = 2;
int screenState = 1;
int modeState = 1;
int OnOff = 0;
void setup();
void screenA();
void screenB();
void screenOff();
void loop() ;
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
// SSD1306_SWITCHCAPVCC = generate display voltage from 3.3V internally
if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3D)) { // Address 0x3D for 128x64
Serial.println(F("SSD1306 allocation failed"));
for(;;); // Don't proceed, loop forever
}
// Show initial display buffer contents on the screen --
// the library initializes this with an Adafruit splash screen.
display.display();
delay(2000); // Pause for 2 seconds
// Clear the buffer
display.clearDisplay();
pinMode(screenPin, INPUT_PULLUP);
pinMode(modePin, INPUT_PULLUP);
screenA();
screenB();
screenOff();
}
void screenA(){
//display.clearDisplay();
display.setTextColor(WHITE);
display.setTextSize(1);
display.setCursor(30,32);
display.print("Screen A On");
display.display();
delay(1);
display.clearDisplay();
}
void screenB(){
//display.clearDisplay();
display.setTextColor(WHITE);
display.setTextSize(1);
display.setCursor(30,32);
display.print("Screen B On");
display.display();
delay(5000);
display.clearDisplay();
}
void screenOff(){
display.display();
delay(1000);
display.clearDisplay();
}
void loop() {
unsigned long currentMillis = millis();
if (currentMillis - previousMillis >= interval) {
previousMillis = currentMillis;
int screenState = digitalRead(screenPin);
int modeVal = digitalRead(modePin);
//print out the value of the pushbutton
Serial.println(screenState);
Serial.println(modeVal);
if (screenState == HIGH && modeVal == HIGH){
screenA();
}
if (screenState == LOW && modeVal == HIGH) {
screenB();
}
if (modeVal == LOW) {
screenOff();
}
//delay(1);
}
}