The logic in your switchScan()
function is flawed. glow()
will only be executed one single time. See code comments:
void switchScan() {
static int counter=0;
if (~(PINA & 0x01)) {
counter++;
// 1st button press: counter will be 1
// 2nd and all following button presses: counter will be 2
if (counter < 2)
// can only be called once!
glow();
else {
// counter will always go from 2 to 1 at this point
counter--;
off();
}
}
}
However, you should also consider the de-bouncing that Brett mentioned in the comments.