File tree Expand file tree Collapse file tree 1 file changed +35
-0
lines changed Expand file tree Collapse file tree 1 file changed +35
-0
lines changed Original file line number Diff line number Diff line change
1
+ volatile boolean state;
2
+ boolean state13;
3
+
4
+ #define LEDPIN 6
5
+
6
+ // toggles every 2ms
7
+ ISR (TIMER2_COMPA_vect)
8
+ {
9
+ state = !state;
10
+ digitalWrite (LEDPIN, state);
11
+ }
12
+
13
+ void setup ()
14
+ {
15
+ pinMode (LEDPIN, OUTPUT);
16
+ pinMode (13 , OUTPUT);
17
+ state = true ;
18
+ state13 = true ;
19
+
20
+ cli ();
21
+ // set up Timer 2:
22
+ TCCR2A = 0 ; // normal operation
23
+ TCCR2B = bit (WGM22) | bit (CS20) | bit (CS22); // CTC, pre-scaling = 128
24
+ OCR2A = 249 * clockCyclesPerMicrosecond () / 16 ; // compare A register value (8-Bit!) (250 * clock speed / 128)
25
+ TIMSK2 = bit (OCIE2A); // interrupt on Compare A Match
26
+
27
+ sei (); // set interrupts flag
28
+ }
29
+
30
+ void loop ()
31
+ {
32
+ // toggles prox. all 4.1µs
33
+ state13 = !state13;
34
+ digitalWrite (13 , state13);
35
+ }
You can’t perform that action at this time.
0 commit comments