int prev = 0;
void setup() {
Serial.begin(9600);
pinMode(2, INPUT_PULLUP);
pinMode(3, OUTPUT);
}
void loop() {
int press = !digitalRead(2);
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(3, HIGH);
else digitalWrite(3, LOW);
}
}