Dunno why I can't write 5-10 lines of code to exit a VOID LOOP on a button push and call a function. I've tried WHILE, IFs, BREAK and more, but I just cant crack it.
It's gotta be simple. Help please.
My code snip below compiles OK and the sketch works, but the button push is ignored.
Perhaps because you never read that pin. Even you do in the code you failed to share, the while condition will always get the last value placed into pinSW.
Which, BTW, will happen to be HIGH, because you also erred in using = assignment instead of == test for equality.
You have to digitalRead(pinSW) any time you want to see if the value at the pin in changed.
Perhaps if you look in main.cpp in the hardware\arduino\avr\cores\arduino\ directory you can see how the GCC compiler sets things up (partial listing):
int main(void)
{
init();
initVariant();
#if defined(USBCON)
USBDevice.attach();
#endif
setup();
for (;;) {
loop();
if (serialEventRun)
serialEventRun();
}
return 0;
}
I have killed loops using inputs (buttons, sensors, etc.) with the interrupt features of Arduino. Not sure if this is applicable here but worth mentioning.
@OP, it looks like AA() is a function call outside loop(). I suggest that you use tools -> autoformat to properly indent your code. If AA() is placed at the beginning of a line, it's outside loop().