-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathled.loop.c
More file actions
43 lines (36 loc) · 756 Bytes
/
led.loop.c
File metadata and controls
43 lines (36 loc) · 756 Bytes
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
#include <avr/io.h>
#include <util/delay.h>
#define BLINK_DELAY_ON_MS 1000
#define BLINK_DELAY_OFF_MS 700
int turn5OnQuicklyAndWait()
{
/* turn it back on */
PORTB |= _BV(PORTB5);
_delay_ms(200);
}
int turn5OffQuicklyAndWait()
{
// turn it back off quickly
PORTB &= ~_BV(PORTB5);
_delay_ms(200);
}
int main(void)
{
/* set pin 5 of PORTB for output*/
DDRB |= _BV(DDB5);
while (1)
{
/* set pin 5 high to turn led on */
PORTB |= _BV(PORTB5);
_delay_ms(BLINK_DELAY_ON_MS);
/* set pin 5 low to turn led off */
PORTB &= ~_BV(PORTB5);
_delay_ms(BLINK_DELAY_OFF_MS);
// blink it a bunch of times
for (int i = 0; i < 20; i++)
{
turn5OnQuicklyAndWait();
turn5OffQuicklyAndWait();
}
}
}