// heartbeat.c // setup TCNT1 in PWM mode // setup TCNT3 in normal mode // set OC1A (PB5) as pwm output // pwm frequency: (16,000,000)/(1 * (61440 + 1)) = 260hz // #include #include uint16_t brightness[20] = { }; ISR( ) { static uint8_t index=0; //steps through the array ; //set bounds on index ; //sset OCR1A to new value } int main() { // setup TCNT1 in PWM mode //set PORTB bit 5 as the PWM output DDRB = 0x20; //fast PWM, set on match, clear at bottom, ICR1 holds value of TOP TCCR1A |= //use ICR1 as source for TOP, use clk/1 TCCR1B |= //no forced compare TCCR1C = //clear at 0xF000 ICR1 = // setup TCNT3 in normal mode to control the update rate // heartbeat update frequency = (16,000,000)/(8 * 2^16) = 30 cycles/sec //normal mode TCCR3A = //use clk/8 (30hz) TCCR3B = //no forced compare TCCR3C = //enable timer 3 interrupt on TOV ETIMSK = sei(); //set GIE while(1) {}; //loop forever waiting for interrupt } // main