Hello, I wanted to be able to turn on the oled display ONLY when I push the button, then have it turn off after 7 seconds and not having the display on all the time. It will display "Door open" constantly and I wanted it to display for 7 seconds. What do I need to put in the code to do this?
#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#define OLED_RESET 4 // Reset pin # (or -1 if sharing Arduino reset pin)
Adafruit_SSD1306 display(OLED_RESET);
#define pushButtonPin 8
int buttonPushed = 0;
void setup()
{
display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
display.clearDisplay();
pinMode(pushButtonPin, INPUT_PULLUP);
void loop()
{
if (digitalRead(pushButtonPin) == LOW) {
buttonPushed = 1;
}
if ( buttonPushed ) {
display.setTextSize(2);
display.setTextColor(WHITE);
display.setCursor(0,0);
display.println("Door open come in!");
display.display();
delay(7500);
buttonPushed = 0;
}
}