/* ---- Example using Arduino Interrupt Timer ---- * (Atmega 168 and 328 have 3 timers) * Setup: -- Wire an LED from digital pin 7 * through a 330 ohm resistor to gnd *-------------------------------------------------------*/ int LEDpin = 7; void setup() { pinMode(LEDpin, OUTPUT); TIMSK1 = 0x01; // enable timer 1 overflow interrupt TCNT1 = 0x000; // reset timer to 0 at start TCCR1A = 0x00; // set TCCRIA - turn off PWM TCCR1B = 0x04; // set TCCRIB - prescalar value to /256 // start serial access. -This is to get around a bug on some // systems that don't initialize data reads properly Serial.begin(9600); } void loop() { // Do useful stuff here, independent of timing } //-------------------------------------------------------- ISR(TIMER1_OVF_vect){ // Here is the interrupt code PORTD ^= _BV(PD7); } |