3 volatile uint8_t timer_en = 0;
5 void button_pressed_ISR(void);
9 // Stop reception of interrupts
10 noInterrupts(); //cli();
12 pinMode(BTN_PIN, INPUT_PULLUP);
13 attachInterrupt(digitalPinToInterrupt(BTN_PIN), button_pressed_ISR, FALLING);
15 // Set PB1 to be an output (Pin9 Arduino UNO)
18 // Clear Timer/Counter Control Registers
23 // Set non-inverting mode - Table 15-3 (page 108)
24 TCCR1A |= (1 << COM1A1);
26 // Set Fast-PWM Mode (Mode 14) - Table 15-5 (page 109)
27 TCCR1A |= (1 << WGM11);
28 TCCR1B |= (1 << WGM12);
29 TCCR1B |= (1 << WGM13);
31 // Clear Timer 1 Counter
34 // Set PWM frequency/top value - Output PWM 1Hz
43 // some useless code here
46 void button_pressed_ISR(void)
51 // Disable the timer by selecting "none" as the clock source
52 TCCR1B &= ~((1 << CS11) | (1 << CS12) | (1 << CS10));
58 TCCR1B |= (1 << CS12) | (1 << CS10);
59 TCCR1B &= ~(1 << CS11);