forked from rt-net/RaspberryPiMouse
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstep3.c
More file actions
83 lines (71 loc) · 1.82 KB
/
Copy pathstep3.c
File metadata and controls
83 lines (71 loc) · 1.82 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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#include "fcntl.h"
char get_SW0(void){
char buf[2];
int SW0;
SW0 = open("/dev/rtswitch0",O_RDONLY);
read(SW0,buf,2);
close(SW0);
return buf[0];
}
char get_SW1(void){
char buf[2];
int SW1;
SW1 = open("/dev/rtswitch1",O_RDONLY);
read(SW1,buf,2);
close(SW1);
return buf[0];
}
char get_SW2(void){
char buf[2];
int SW2;
SW2 = open("/dev/rtswitch2",O_RDONLY);
read(SW2,buf,2);
close(SW2);
return buf[0];
}
void main(void){
int state0,state1,state2;
int LED0,LED1,LED2,LED3;
LED0 = open("/dev/rtled0",O_WRONLY);
LED1 = open("/dev/rtled1",O_WRONLY);
LED2 = open("/dev/rtled2",O_WRONLY);
LED3 = open("/dev/rtled3",O_WRONLY);
state0 = state1 = state2 = 0;
while(1){
if (get_SW0() =='0'){
usleep(10000);
while (get_SW0() == '0');
usleep(10000);
state0=(state0+1)&0x01;
if(state0==0){
write(LED3,"0",1);
}else{
write(LED3,"1",1);
}
}
if (get_SW1() =='0'){
usleep(10000);
while (get_SW1() == '0');
usleep(10000);
state1=(state1+1)&0x01;
if(state1==0){
write(LED2,"0",1);
write(LED1,"0",1);
}else{
write(LED2,"1",1);
write(LED1,"1",1);
}
}
if (get_SW2() =='0'){
usleep(10000);
while (get_SW2() == '0');
usleep(10000);
state2=(state2+1)&0x01;
if(state2==0){
write(LED0,"0",1);
}else{
write(LED0,"1",1);
}
}
}
}