0

currently I'm trying my best at programming a microcontroller.

int main()
{
    init_ports();

    while(1){
        if(gameStatus == 1){
            gameStatus = 2;
            beep(120);
        }
    }
}

is my main, gameStatus is a global uint_8. It gets set by an interrupt that is caused by pressing a button.

ISR(INT0_vect){
    if(gameStatus == 0)
        gameStatus = 1; // that works

}

The main however won't recognize gameStatus at all. Is there a reason why this could be?

Thanks!

3jfx
  • 75
  • 5

1 Answers1

2

Thanks to wildplasser!

Changing

uint8_t gameStatus = 0;

into

volatile uint8_t gameStatus = 0;

did the trick.

https://en.wikipedia.org/wiki/Volatile_(computer_programming)

3jfx
  • 75
  • 5