#include <LiquidCrystal.h>
const int RED_BUTTON_PIN = 4;
const int GREEN_BUTTON_PIN = 3;
const int BLUE_BUTTON_PIN = 2;
uint16_t BLUE_BUTTON_BUFFER = 0;
unsigned long LAST_TIMESTAMP = 0;
uint16_t DISPLAY_STATE = 0;
const String WELCOME_MSG = "Welcome!";
char buffer[40];
LiquidCrystal lcd(12, 11, 10, 9, 8, 7);
uint16_t debounce_high(uint16_t *state, uint16_t raw_event) {
*state = (*state << (uint16_t) 1) | !raw_event | 0xE000;
//sprintf(buffer, "%#08x", *state);
//Serial.println(buffer);
if (*state == 0xF000)
return 1;
return 0;
}
void setup() {
pinMode(RED_BUTTON_PIN, INPUT);
pinMode(GREEN_BUTTON_PIN, INPUT);
pinMode(BLUE_BUTTON_PIN, INPUT);
Serial.begin(115200);
lcd.begin(16, 1);
lcd.print(WELCOME_MSG);
lcd.setCursor(0, 1);
}
void loop() {
digitalWrite(LED_BUILTIN,
digitalRead(RED_BUTTON_PIN) | digitalRead(GREEN_BUTTON_PIN) | digitalRead(BLUE_BUTTON_PIN)
);
if (debounce_high(&BLUE_BUTTON_BUFFER, digitalRead(BLUE_BUTTON_PIN))) {
lcd.print(":) ");
lcd.setCursor(0, 1);
Serial.println("ONCE!");
LAST_TIMESTAMP = micros();
DISPLAY_STATE = 1;
} else if (DISPLAY_STATE && micros() - LAST_TIMESTAMP >= 500000) {
Serial.println("RESET...");
lcd.print(WELCOME_MSG);
lcd.setCursor(0, 1);
DISPLAY_STATE = 0;
}
}