#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SH110X.h>
/* Uncomment the initialize the I2C address , uncomment only one, If you get a totally blank screen try the other*/
#define i2c_Address 0x3d //initialize with the I2C addr 0x3C Typically eBay OLED's
//#define i2c_Address 0x3d //initialize with the I2C addr 0x3D Typically Adafruit OLED's
#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels
#define OLED_RESET -1 // QT-PY / XIAO
Adafruit_SH1106G display = Adafruit_SH1106G(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
#define BUTTON_ONE_PIN 4 // pin for UP button
#define BUTTON_TWO_PIN 2 // pin for SELECT button
//#define BUTTON_DOWN_PIN 13
//Constants
//const int button_one = 4;
//const int button_two = 2;
unsigned long DELAY_TIME = 15000;
unsigned long delayStart = 0;
bool delayRunning = false;
bool ledOn = false;
int button_one_clicked = 0;
int button_two_clicked = 0;
int current_screen = 0;
void setup();
void screenA();
void screenB();
void screenC();
void screenOff();
void screenOn();
void loop() ;
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
delay(250); // wait for the OLED to power up
display.begin(i2c_Address, true); // Address 0x3C default
//display.setContrast (0); // dim display
display.display();
delay(2000);
// Clear the buffer
display.clearDisplay();
Wire.begin();
pinMode(BUTTON_ONE_PIN, INPUT_PULLUP);
pinMode(BUTTON_TWO_PIN, INPUT_PULLUP);
//screenA();
ledOn = false;
// start delay
delayStart = millis();
delayRunning = false;
}
void screenA(){
//display.clearDisplay();
display.setTextColor(SH110X_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(SH110X_WHITE);
display.setTextSize(1);
display.setCursor(30,32);
display.print("Screen B On");
display.display();
//delay(5000);
display.clearDisplay();
}
void screenC(){
//display.clearDisplay();
display.setTextColor(SH110X_WHITE);
display.setTextSize(1);
display.setCursor(30,32);
display.print("Screen C On");
display.display();
//delay(5000);
display.clearDisplay();
}
void screenOff(){
Wire.beginTransmission(0x3d);
Wire.write((uint8_t)0x80);
Wire.write((uint8_t)0xAE);
Wire.endTransmission();
Serial.print("Screen Off");
}
void screenOn(){
Wire.beginTransmission(0x3d);
Wire.write((uint8_t)0x80);
Wire.write((uint8_t)0xAF);
Wire.endTransmission();
Serial.print("Screen On");
}
void loop() {
int button_one_state = digitalRead(BUTTON_ONE_PIN);
int button_two_state = digitalRead(BUTTON_TWO_PIN);
//print out the value of the pushbutton
Serial.print("Button_One_State = ");
Serial.println(button_one_state);
Serial.print("Button_Two_State = ");
Serial.println(button_two_state);
if (delayRunning && ((millis() - delayStart) >= DELAY_TIME)) {
delayStart += DELAY_TIME; // this prevents drift in the delays
screenOff();
}
if ((digitalRead(BUTTON_ONE_PIN) == LOW) && (button_one_clicked == 0)){
button_one_clicked = 1;
if (current_screen == 0) {current_screen = 1;}
else if (current_screen == 1) {current_screen = 2;}
else {current_screen = 0;}
Serial.println(current_screen);
}
if ((digitalRead(BUTTON_ONE_PIN) == HIGH) && (button_one_clicked == 1)){
button_one_clicked = 0;
}
if (current_screen == 0){
screenA();
}
else if (current_screen == 1){
screenB();
}
else if (current_screen == 2){
screenC();
}
if (button_two_state == LOW) {
screenOn();
ledOn = false;
// start delay
delayStart = millis();
delayRunning = false;
}
}
Loading
wemos-s2-mini
wemos-s2-mini