-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.c
54 lines (48 loc) · 1022 Bytes
/
main.c
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
46
47
48
49
50
51
52
53
54
#include <avr/io.h>
#include <util/delay.h>
#include <avr/sleep.h>
#define LED0 PA0
#define LED1 PA1
#define LED2 PA2
#define LED3 PA3
int main(void)
{
// Set LEDs as outputs
DDRA |= _BV(LED0);
DDRA |= _BV(LED1);
DDRA |= _BV(LED2);
DDRA |= _BV(LED3);
// Set BUTTON as input (active low)
DDRA &= ~_BV(PA7);
_delay_ms(100);
PORTA ^= 0xF;
_delay_ms(100);
PORTA ^= 0xF;
_delay_ms(100);
PORTA ^= 0xF;
_delay_ms(100);
PORTA ^= 0xF;
uint8_t advent = 0;
while (1) {
PORTA &= ~0xF;
_delay_ms(2);
if(advent >= 0)
PORTA |= _BV(LED0);
if(advent >= 1)
PORTA |= _BV(LED1);
if(advent >= 2)
PORTA |= _BV(LED2);
if(advent >= 3)
PORTA |= _BV(LED3);
_delay_ms(1);
if((PINA & _BV(PA7)) == 0)
{
PORTA |= 0xF;
advent++;
advent%=4;
_delay_ms(100);
PORTA &= ~0xF;
}
}
return 0;
}