Timer interrupts on Arduino game not working

Viewed 103

I have a ping pong game and I am trying to add a 60 second timer to it. So that if the round is not finished within 60 seconds it would end automatically.

The purpose is to count without using millis()

I tried to implement this but it didn't seem to be working.

So I tried to print out the seconds in the serial monitor and it just constantly shows 0000000000000000000000000

What is the issue here?

volatile uint16_t counter = 0;
volatile uint16_t seconds = 0;

void setup() 
{
  //timer1 for overflow interrupt
  noInterrupts();
  TCCR1A = 0;             //initialize timer1
  TCCR1B = 0;
  TCCR1B |= 0b00000100;   //256 prescaler
  TIMSK1 |= 0b00000001;   //enable overflow interrupt
  interrupts();
}

ISR(TIMER1_OVF_vect)  //timer overflow ISR: update counter
{
    counter++;
  if (counter == 62500)
  {
    counter = 0;
    seconds++;
  }
}

void loop() 
{
  Serial.print(seconds);
  game = update();
  lcd.clear(); 
  render();

I included the parts of the code which are directly related to the issue.

Help would be appreciated very much!

0 Answers
Related