#include #include #include #define SCREEN_WIDTH 128 // OLED display width, in pixels #define SCREEN_HEIGHT 64 // OLED display height, in pixels #define LED 10 #define ButtonL 12 #define ButtonR 11 // Declaration for an SSD1306 display connected to I2C (SDA, SCL pins) Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1); //VARIABLES int Lstate; int Rstate; int LButtonValue; int RButtonValue; void setup() { Serial.begin(9600); //Start the serial connection for Serial Monitor display.begin(SSD1306_SWITCHCAPVCC, 0x3C); //Start up and initialize the display pinMode(LED,OUTPUT); pinMode(ButtonL,INPUT); pinMode(ButtonR,INPUT); //Clear the display buffer display.clearDisplay(); //Always need to call this to make anything show on the screen display.display(); Lstate = 0; Rstate = 0; } void loop() { //DECIDE WHAT STATE TO BE IN int prevLbuttonValue = LButtonValue; LButtonValue = digitalRead(ButtonL); if (LButtonValue == HIGH && prevLbuttonValue == LOW) { if (Lstate == 0) { Lstate = 1; } else if (Lstate == 1) { Lstate = 0; } } int prevRbuttonValue = RButtonValue; RButtonValue = digitalRead(ButtonR); if (RButtonValue == HIGH && prevRbuttonValue == LOW) { if (Rstate == 0) { Rstate = 1; } else if (Rstate == 1) { Rstate = 0; } } //DRAW THE STATE WE'RE IN display.clearDisplay(); if (Lstate == 1) { drawLcircle(); } if (Rstate == 1) { drawRcircle(); } display.display(); delay(10); } //DRAWING FUNCTIONS void drawLcircle() { display.fillCircle(40,30,8,WHITE); } void drawRcircle() { display.fillCircle(90,30,8,WHITE); }