#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <ezButton.h>
#define DEBOUNCE_TIME 50 // the debounce time in millisecond, increase this time if it still chatters
#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels
ezButton button(23); // create ezButton object that attach to pin GPIO21
int count=0;
Adafruit_SSD1306 oled(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);
void setup() {
Serial.begin(9600);
Serial.println("hello starting");
button.setDebounceTime(50); // set debounce time to 50 milliseconds
// initialize OLED display with I2C address 0x3C
if (!oled.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {
Serial.println(F("failed to start SSD1306 OLED"));
while (1);
}
delay(2000); // wait two seconds for initializing
oled.clearDisplay(); // clear display
oled.setTextSize(1); // set text size
oled.setTextColor(WHITE); // set text color
oled.setCursor(0, 10); // set position to display
oled.println("esp32io.com"); // set text
oled.display(); // display on OLED
}
void loop() {
button.loop(); // MUST call the loop() function first
if (button.isPressed()){
Serial.println("The button is pressed");
Serial.println(count);
count++;}
if (button.isReleased()){
Serial.println("The button is released");
oled.clearDisplay();
oled.setCursor(0, 30); // set position to display
oled.println(count); // set text
oled.display();}
}