-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathblink.c
More file actions
48 lines (38 loc) · 1.42 KB
/
blink.c
File metadata and controls
48 lines (38 loc) · 1.42 KB
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
// Josh Silva
// ECE 231 Lab 1
// 03/07/23
#include <avr/io.h>
#include <util/delay.h> //defines _delay_ms
#define DELAY 100 //100ms delay, Frquency: 5Hz
/*
D4 = Button 1
D5 = Button 2
D3 = Button 3
*/
int main(void){
DDRD =1<<PORTD6|1<<PORTD7; // Outputs D6 & D7
PORTD = 1<<PORTD4|1<<PORTD3|1<<PORTD5; // setting D4 D5 D3
while(1){
if (((PIND & ( 1<<PORTD4)) == 0) && ((PIND & ( 1<<PORTD5)) != 0) && ((PIND & ( 1<<PORTD3)) != 0)) { //checking that D4 was selected
PORTD |= 1<<PORTD6; //sets pin to high (LED On)
_delay_ms(MYDELAY);
PORTD &= ~ (1<<PORTD6); // sets pin to low (LED off)
_delay_ms(MYDELAY); // Flashes LED
}
else if (((PIND & ( 1<<PORTD5)) == 0) && ((PIND & ( 1<<PORTD4)) != 0) && ((PIND & ( 1<<PORTD3)) != 0)){
PORTD |= 1<<PORTD7; //sets pin to high (LED On)
_delay_ms(MYDELAY);
PORTD &= ~ (1<<PORTD7); // Sets pin to low (LED Off)
_delay_ms(MYDELAY); // Flashes LED
}
else if (((PIND & ( 1<<PORTD3)) == 0) && ((PIND & ( 1<<PORTD5)) != 0) && ((PIND & ( 1<<PORTD5)) != 0)){
PORTD |= 1<<PORTD7 ;
PORTD |= 1<<PORTD6 ;
_delay_ms(MYDELAY);
PORTD &= ~ (1<<PORTD6) ;
PORTD &= ~ (1<<PORTD7) ;
_delay_ms(MYDELAY);
}
}
return 0;
}