Hi!
I'm new to the community but not to programming. So, greetings to everybody!
I'm using Arduino IDE 1.8.9
Recently, I worked on an implementation of the game Snake on an Arduino Nano. Everything is working fine, the only problem I couldn't solve is a while loop which is executed as long as the start button was not pressed and should be left after the button was pressed.
As soon as the device gets powered on,the game starts, which is completely as expected to do.
When the game is over, the LCD shows "Game over", and then a while loop is executed.
If I comment it out, the game restarts immediately. So the empty while loop was not omitted by the compiler.
This is the while loop:
while(!tasten.getButtonCycle(buttonStart)) { //will be never left
}
If I declare a volatile variable before the loop and change it inside, e.g. var1++;, then nothing changes.
But, if I manipulate a PORT pin, then it works as expected?!
while(!tasten.getButtonCycle(buttonStart)) { //will be left as expected
digitalWrite(14, HIGH);
}
The buttons are read during a Timer1 interrupt which happens every 1ms. My lib, which reads the buttons using shift registers and using only one pin as input,does work as expected in every other case.
If the button is pressed, true is returned by getButtonCycle(), else it's false.
I have no clue, why it shows this behaviour, but maybe someone is able to explain this to me?
NanoGame.zip (17.5 KB)