#include <Wire.h> // Include Wire if you're using I2C
#include <Adafruit_GFX.h> // Include core graphics library for the display
#include <Adafruit_SSD1306.h> // Include the OLED display driver
#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)
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire);
int ledBlinkCount = 0; // Counter for the number of LED blinks
void setup() {
pinMode(2, OUTPUT);
Serial.begin(9600); // Start serial communication at 9600 baud rate
// Initialize the display
if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) { // Check your display's I2C address
Serial.println("SSD1306 allocation failed");
for(;;); // Don't proceed, loop forever
}
display.display(); // Show initial display buffer contents on the screen
delay(2000); // Pause for 2 seconds
display.clearDisplay(); // Clear the buffer
}
void loop() {
// Blink the LED
digitalWrite(2, HIGH);
delay(200);
digitalWrite(2, LOW);
delay(500);
ledBlinkCount++; // Increment the LED blink counter
// Update the display with the current count
display.clearDisplay(); // Clear the display buffer
display.setTextSize(1); // Set text size to 1
display.setTextColor(SSD1306_WHITE); // Set the text color to white
display.setCursor(0,0); // Set the cursor position to top-left
display.print("LED Blink Count: ");
display.println(ledBlinkCount);
display.display(); // Display the text
// Optional: Print the count to the Serial Monitor as well
Serial.println("LED has blinked " + String(ledBlinkCount) + " times");
}