//REF: https://www.youtube.com/watch?v=K74WRW9XY8c&ab_channel=dianartanto
int prev = 0;
void setup() {
Serial.begin(9600);
pinMode(5, INPUT_PULLUP);
pinMode(6, OUTPUT);
}
void loop() {
int press = !digitalRead(5);
if (press != prev) {
if (press) Serial.print("1");
else Serial.print("0");
}
prev = press;
if (Serial.available()) {
char light = Serial.read() - '0';
if (light) digitalWrite(6, HIGH);
else digitalWrite(6, LOW);
}
}