#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#define OLED_RESET 4
Adafruit_SSD1306 display(OLED_RESET);
// initialize interrupt pin
const int buttonPin = 3;
// initialize symbol counter
int symbolCount = 0;
void setup() {
// initialize OLED display
display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
display.display();
delay(1000);
display.clearDisplay();
// set up interrupt pin as input
pinMode(buttonPin, INPUT_PULLUP);
// attach interrupt to the pin, trigger on falling edge
attachInterrupt(digitalPinToInterrupt(buttonPin), changeSymbol, FALLING);
}
void loop() {
// clear display and set text size
display.clearDisplay();
display.setTextSize(2);
// display current symbol on OLED
switch (symbolCount) {
case 0:
display.drawCircle(32, 16, 10, WHITE);
break;
case 1:
display.drawRect(20, 8, 30, 20, WHITE);
break;
case 2:
display.fillTriangle(0, 0, 30, 30, 60, 0, WHITE);
break;
// add more cases for additional symbols
default:
break;
}
// display OLED
display.display();
}
void changeSymbol() {
// increment symbol counter
symbolCount++;
// reset counter when it reaches the last symbol
if (symbolCount > 2) {
symbolCount = 0;
}
}