Code.ino
3.38 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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
int right_I = 13; // Air Input(Right)
int right_O = 12; // Air Output(Right)
int left_I = 9; // Air Input(Left)
int left_O = 10; // Air Output(Left)
int control_R = A0; // Trigger Input(Right)
int control_L = A1; // Trigger Input(Left)
int control_R_I; // Reading Right trigger signal
int control_L_I; // Reading left trigger signal
int count_R = 0; // 우측 활성화 변수
int count_L = 0; // 좌측 활성화 변수
int count_B = 0; // 양측 활성화 변수
// 우측 피드백 활성화
void RB(){
digitalWrite(right_I, HIGH);
delay(150);
digitalWrite(right_I, LOW);
count_R = 1;
Serial.println("right");
return;
}
// 우측 피드백 비활성화
void RBO(){
digitalWrite(right_O,HIGH);
delay(300);
digitalWrite(right_O,LOW);
count_R = 0;
Serial.println("rightDOWN");
return;
}
// 좌측 피드백 활성화
void LB(){
digitalWrite(left_I, HIGH);
delay(150);
digitalWrite(left_I, LOW);
count_L = 1;
Serial.println("left");
return;
}
// 좌측 피드백 비활성화
void LBO(){
digitalWrite(left_O,HIGH);
delay(300);
digitalWrite(left_O, LOW);
count_L = 0;
Serial.println("leftDOWN");
return;
}
// 양측 피드백 활성화
void both(){
digitalWrite(left_I, HIGH);
digitalWrite(right_I, HIGH);
delay(150);
digitalWrite(right_I, LOW);
digitalWrite(left_I, LOW);
count_B = 1;
Serial.println("both");
return;
}
// 양측 피드백 비활성화
void bothO(){
digitalWrite(right_O,HIGH);
digitalWrite(left_O,HIGH);
delay(300);
digitalWrite(left_O,LOW);
digitalWrite(right_O,LOW);
count_B = 0;
Serial.println("bothDOWN");
return;
}
// 양측 피드백 활성화 확인
void setBoth(){
count_B = 1;
}
// 양측 비피드백 활성화 확인
void setSingle(){
count_B = 0;
}
void setup() {
// put your setup code here, to run once:
pinMode(right_I, OUTPUT);
pinMode(right_O, OUTPUT);
pinMode(left_I, OUTPUT);
pinMode(left_O, OUTPUT);
pinMode(control_R, INPUT);
pinMode(control_L, INPUT);
Serial.begin(4800);
}
void loop() {
// 양측 트리거 신호를 수치화
control_R_I = analogRead(control_R);
Serial.print("right : ");
Serial.println(control_R_I);
control_L_I = analogRead(control_L);
Serial.print("left : ");
Serial.println(control_L_I);
//UP
if((control_R_I > 900 and control_R_I <= 927) and (control_L_I > 900 and control_L_I <= 927) and count_R == 0){
RB();
}
else if((control_R_I > 927 and control_R_I < 970) and (control_L_I > 927 and control_L_I < 970)and count_L == 0){
LB();
}
else if(control_R_I >= 970 and control_L_I >= 970 and count_B == 0 and count_R == 1 and count_L == 0){
LB();
setBoth();
}
else if(control_R_I >= 970 and control_L_I >= 970 and count_B == 0 and count_R == 0 and count_L == 1){
RB();
setBoth();
}
else if(control_R_I >= 970 and control_L_I >= 970 and count_B == 0){
both();
}
//DOWN
if((control_R_I > 900 and control_R_I <= 927) and (control_L_I > 900 and control_L_I <= 927) and count_L == 1){
setSingle();
LBO();
}
else if((control_R_I > 927 and control_R_I < 970) and (control_L_I > 927 and control_L_I < 970)and count_R == 1){
setSingle();
RBO();
}
//DOWN2
if(control_R_I < 890 and control_L_I < 890 and count_R == 1){
RBO();
}
else if(control_R_I < 890 and control_L_I < 890 and count_L == 1){
LBO();
}
else if(control_R_I < 890 and control_L_I < 890 and count_B == 1){
bothO();
}
}