const byte PinLeds [] = { 12, 11, 10, 9 };
const int Nleds = sizeof(PinLeds);
bool ledState [Nleds]; // default false (off)
void setup() {
Serial.begin(115200);
Serial.println ("rdy");
}
void loop() {
if (Serial.available()) {
char c = Serial.read ();
int i = c - '0';
if (i < Nleds) {
if (ledState [i]) { // if on
ledState [i] = false;
digitalWrite (PinLeds [i], LOW); // off
}
else {
ledState [i] = true;
digitalWrite (PinLeds [i], HIGH); // on
}
}
}
}