My traffic light code for the Arduino doesn't run. I was wondering if anyone could point out where my issues lie. The red and green LEDs should be on for 15 seconds and the amber on for 5 seconds.
#include <avr/io.h>
#include <avr/interrupt.h>
#include <stdint-gcc.h>
/*15 second interrupt*/
#define INTERRUPTS 975
/*
* col = current colour of light.
* 'g', 'a', 'r', 'o'
*/
volatile uint8_t count;
volatile char col;
ISR(TIMER0_OVF_vect)
{
count++;
if (count >= INTERRUPTS){
if (col == 'g'){
/*switch to amber*/
col = 'a';
/*reset counter*/
count = 0;
/*timer counter to 171 as we only need 85 clicks for 5s*/
TCNT0 = 171;
PORTD = 0b00000010;
} else if(col == 'a'){
col = 'r';
count = 0;
TCNT0 = 0;
PORTD = 0b00000100;
} else if (col == 'r'){
col = 'o';
counter = 0;
TCNT0 = 171;
PORTD = 0b00000010;
} else if (col == 'o'){
col = 'g';
count = 0;
TCNT0 = 0;
PORTD = 0b00000001;
} else{
return;
}
} else{
if(col == 'g' || col == 'r'){
TCNT0 = 0;
} else if(col == 'a' || col == 'o'){
TCNT0 = 171;
}
}
return;
}
int main(void)
{
/* normal mode */
TCCR0A = 0b00000000;
/* prescaler = 1024 */
TCCR0B = 0b00000101;
/* enable overflow interrupts */
TIMSK0 = 0b00000001;
TCNT0 = 0;
sei();
/*Initialise output*/
DDRD = 0b11111111;
count = 0;
col = 'g';
PORTD = 0b00000001;
while (1){
}
}