// Timer Interrupts by ISR
//
// Variables
bool LED_STATE = LOW;
void setup() {
pinMode(5, OUTPUT);
cli(); //
TCCR1A = 0;
TCCR1B = 0;
// 2 Set the prescalar to desired value
TCCR1B |= B00000100; // Set CS12 to prescalar 256
// TIMSK1 |= (1 << CS12);
// 3 Enable compare match mode on register A
TIMSK1 |= B00000010; // Set OCIE1A to 1
// TIMSK1 |= (1 << OCIE1A);
// 4
OCR1A = 31250;
sei(); //
}
void loop() {
// put your main code here, to run repeatedly:
}
// 5 ISR will trigger each 500ms
ISR(TIMER1_COMPA_vect) {
TCNT1 = 0;
LED_STATE = !LED_STATE;
digitalWrite(5, LED_STATE);
}