#define DEBOUNCE_TIME 15
#define STATE_TO_TRIGGER 0
bool currState;
bool prevState;
unsigned long previousRead = 0;
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
pinMode(7, INPUT_PULLUP);
currState = digitalRead(7);
prevState = currState;
}
void loop() {
// ทำให้ไมโครคอนโทรลเลอร์สามารถอ่านปุ่มเมื่อเวลาผ่านไปครบเท่านั้น
if(millis() - previousRead >= DEBOUNCE_TIME){
currState = digitalRead(7);
previousRead = millis();
}
if(currState != prevState){
if(currState == STATE_TO_TRIGGER){
Serial.println("Hello");
}
}
prevState = currState;
}