User talk:AP Thongkaysorn

int timer; void setup { Serial.begin(9600); pinMode(LEDPIN, OUTPUT); cli; // disable global interrupts
 * 1) define LEDPIN 13

// initialize Timer1 // ZERO Timer1 TCCR1A = 0; // set entire TCCR1A register to 0 TCCR1B = 0; // same for TCCR1B

// set compare match register to desired timer count: OCR1A = 15624; // turn on CTC mode:initial value changed in loop (LED ON) OCR1B = 1000; // turn on CTC mode:initial value changed in loop (LED OFF) TCCR1B |= (1 << WGM12); // Set CS10 and CS12 bits for 1024 prescaler: TCCR1B |= (1 << CS10); // prescaler 1024 TCCR1B |= (1 << CS12); // prescaler 1024 TIMSK1 |= (1 << OCIE1A); // enable timer compare interrupt TIMSK1 |= (1 << OCIE1B); // enable timer compare interrupt: sei; // Enable global interrupts }

void loop { }

ISR(TIMER1_COMPA_vect) { digitalWrite(LEDPIN, HIGH); Serial.println("LED ON"); //digitalWrite(LEDPIN, !digitalRead(LEDPIN)); } ISR(TIMER1_COMPB_vect) { digitalWrite(LEDPIN, LOW); Serial.println("LED OFF"); //digitalWrite(LEDPIN, !digitalRead(LEDPIN)); }