#include <Arduino.h>
#include <avr/io.h>
#include <avr/interrupt.h>
void delay() {
TCCR1A = 0x00;
TCCR1B = 0x00;
// Set initial count (34286) so overflow happens after 2 seconds (prescaler 1024)
TCNT1 = 34286;
// TCNT1 = 0x85EE;
TCCR1B |= (1 << CS02) | (1 << CS10); // CS12 and CS10 set -> prescaler = 1024
//while ((TIFR1 & (1 << TOV1)) == 0);
//TCCR1B = 0x00;
//TIFR1 |= (1 << TOV1);
TIMSK1 |= (1 << TOIE1);
}
void setup() {
DDRB = 0xFF;
PORTB = 0x00;
delay();
}
void loop() {
// delay(); // Wait for 2 seconds
// PORTB = ~PORTB;
}
ISR(TIMER1_OVF_vect) // I misspelled the name of this timer overflow vector during the lecture.
{
PORTB = ~PORTB;
// TCNT1 = 0;
// TIFR1 |= (1<< TOV1);
}