void setup pinMode OUTPUT pinMode OUTPUT pinMode OUTPUT pinMode OUTPUT

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
void setup()
{
pinMode(0, OUTPUT);
pinMode(1, OUTPUT);
pinMode(3, OUTPUT);
pinMode(4, OUTPUT);
TCCR0A = (1 << WGM00) | (1<<WGM01);
TCCR0B = (1 << CS01) | (1<<WGM02);
OCR0A = 254;
OCR0B = 0;
TIMSK = _BV(OCIE0A) |_BV(OCIE0B);
}
void loop()
{
}
int state = 0;
unsigned int oncounter = 0;
unsigned int offcounter = 0;
ISR(TIM0_COMPA_vect)
{
if (state != 0) return;
if (++oncounter == 80) {
oncounter = 0;
state = 1;
PORTB |= 1<<3;
PORTB |= 1<<4;
OCR0A = 80;
}
}
ISR(TIM0_COMPB_vect)
{
if (state != 1) return;
if(++offcounter == 9) {
state = 0;
offcounter = 0;
PORTB &= ~(1<<3);
PORTB &= ~(1<<4);
OCR0A = 254;
}
}