const byte PinButUp = 2;
const byte PinButRst = 3;
const byte PinLeds [] = { 12, 11, 10, 9 };
const int Nled = 4;
int idx;
const int Off = LOW;
const int On = HIGH;
void loop() {
if (LOW == digitalRead(PinButUp)) {
if (idx < Nled)
idx++;
}
else if (LOW == digitalRead (PinButRst)) {
idx = 0;
Serial.println ("reset");
}
for (int n = 0; n < Nled; n++)
digitalWrite (PinLeds [n], Off);
for (int n = 0; n < idx; n++)
digitalWrite (PinLeds [n], On);
delay (500); // recognize single buttton presses
}
void setup() {
Serial.begin(115200);
pinMode (PinButUp, INPUT_PULLUP);
pinMode (PinButRst, INPUT_PULLUP);
for (int n = 0; n < Nled; n++)
pinMode (PinLeds [n], OUTPUT);
for (int n = 0; n < Nled; n++) {
digitalWrite (PinLeds [n], On);
delay (500);
}
for (int n = 0; n < Nled; n++) {
digitalWrite (PinLeds [n], Off);
delay (500);
}
}