#define PCB1 2
#define LED1 8
#define MAX_PCB 2
#define MAX_LED 2
byte switches[MAX_PCB][MAX_LED];
void setup() {
for (int led = LED1; led < LED1 + MAX_LED; led++) {
pinMode(led, OUTPUT);
}
switches[0][0] = 1;
Serial.begin(115200);
Serial.println("Welcome to the Serial Playground!");
Serial.println("---------------------------------");
printleds();
}
void clearleds() {
switches[0][0] = 0;
switches[0][1] = 0;
switches[1][0] = 0;
switches[1][1] = 0;
}
void printleds() {
Serial.print(switches[0][0]);
Serial.print(switches[0][1]);
Serial.print(switches[1][0]);
Serial.println(switches[1][1]);
}
#define SW
void loop() {
int a;
for (int pcb = PCB1; pcb < PCB1 + MAX_PCB; pcb++) {
for (int led = LED1; led < LED1 + MAX_LED; led++) {
// read switch
#ifdef SW
digitalWrite(led, 1);
pinMode(pcb, INPUT);
a = digitalRead(pcb);
if (a && (a != switches[pcb - PCB1][led - LED1])) {
clearleds();
switches[pcb - PCB1][led - LED1] = a;
printleds();
}
#endif
// output led
pinMode(pcb, OUTPUT);
digitalWrite(led, !switches[pcb - PCB1][led - LED1]);
digitalWrite(pcb, switches[pcb - PCB1][led - LED1]);
// delay(10);
// digitalWrite(pcb, 0);
}
}
}