/* Flickering LED light with some given frequency */ /* Works on 16MHz AVR-based Arduinos (tested on Micro) */ /* Default is 500 Hz (clock / 8, OCR1A = 2000 - 1) */ #define LED_PIN 3 void setup() { pinMode(LED_PIN, OUTPUT); TCCR1A = 0; TCCR1B = (1 << WGM12) | (1 << CS11); /* CTC, clock / 8 */ TIMSK1 = (1 << OCIE1A); /* output compare interrupt */ OCR1A = 2000 - 1; /* 10000 = 100 Hz, 5000 = 200 Hz, 2000 = 500 Hz and so on */ } void loop() { /* nothing to do */ } ISR(TIMER1_COMPA_vect) { /* toggle LED state */ digitalWrite(LED_PIN, !digitalRead(LED_PIN)); }