#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#define OLED_RESET 4
Adafruit_SSD1306 display(OLED_RESET);
const int buttonPin = 2;
int symbolIndex = 0;
char symbols[] = {'-','!', '@', '#', '$', '%', '&', '*', '?'};
unsigned long lastDebounceTime = 0;
unsigned long debounceDelay = 100;
int lastButtonState = HIGH;
void setup() {
Serial.begin(9600);
pinMode(buttonPin, INPUT_PULLUP);
if (!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {
Serial.println(F("SSD1306 allocation failed"));
for (;;);
}
display.clearDisplay();
display.setTextSize(2);
display.setTextColor(WHITE);
display.setCursor(20, 20);
display.print(symbols[symbolIndex]);
display.display();
}
void loop()
{
int reading = digitalRead(buttonPin);
if (reading != lastButtonState) {
lastDebounceTime = millis();
}
if ((millis() - lastDebounceTime) > debounceDelay) {
if (reading == LOW) {
symbolIndex = (symbolIndex + 1) % (sizeof(symbols) / sizeof(symbols[0]));
display.clearDisplay();
display.setCursor(20, 20);
display.print(symbols[symbolIndex]);
display.display();
}
}
lastButtonState = reading;
}