-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
404780b
commit b489a84
Showing
1 changed file
with
35 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
volatile boolean state; | ||
boolean state13; | ||
|
||
#define LEDPIN 6 | ||
|
||
// toggles every 2ms | ||
ISR(TIMER2_COMPA_vect) | ||
{ | ||
state = !state; | ||
digitalWrite(LEDPIN, state); | ||
} | ||
|
||
void setup() | ||
{ | ||
pinMode(LEDPIN, OUTPUT); | ||
pinMode(13, OUTPUT); | ||
state = true; | ||
state13 = true; | ||
|
||
cli(); | ||
// set up Timer 2: | ||
TCCR2A = 0; // normal operation | ||
TCCR2B = bit(WGM22) | bit(CS20) | bit(CS22); // CTC, pre-scaling = 128 | ||
OCR2A = 249 * clockCyclesPerMicrosecond() / 16; // compare A register value (8-Bit!) (250 * clock speed / 128) | ||
TIMSK2 = bit(OCIE2A); // interrupt on Compare A Match | ||
|
||
sei(); // set interrupts flag | ||
} | ||
|
||
void loop() | ||
{ | ||
// toggles prox. all 4.1µs | ||
state13 = !state13; | ||
digitalWrite(13, state13); | ||
} |