//REF: https://www.youtube.com/watch?v=K74WRW9XY8c&ab_channel=dianartanto
int prev = 0;
void setup() {
Serial.begin(9600);
pinMode(17, INPUT_PULLUP);
pinMode(16, OUTPUT);
}
void loop() {
int press = !digitalRead(17);
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(16, HIGH);
else digitalWrite(16, LOW);
}
}