홍유진

6월 면담, 최종보고서, 소스코드 업로드

1 +int right_I = 13; // Air Input(Right)
2 +int right_O = 12; // Air Output(Right)
3 +int left_I = 9; // Air Input(Left)
4 +int left_O = 10; // Air Output(Left)
5 +int control_R = A0; // Trigger Input(Right)
6 +int control_L = A1; // Trigger Input(Left)
7 +int control_R_I; // Reading Right trigger signal
8 +int control_L_I; // Reading left trigger signal
9 +int count_R = 0; // 우측 활성화 변수
10 +int count_L = 0; // 좌측 활성화 변수
11 +int count_B = 0; // 양측 활성화 변수
12 +
13 +// 우측 피드백 활성화
14 +void RB(){
15 + digitalWrite(right_I, HIGH);
16 + delay(150);
17 + digitalWrite(right_I, LOW);
18 + count_R = 1;
19 + Serial.println("right");
20 + return;
21 +}
22 +// 우측 피드백 비활성화
23 +void RBO(){
24 + digitalWrite(right_O,HIGH);
25 + delay(300);
26 + digitalWrite(right_O,LOW);
27 + count_R = 0;
28 + Serial.println("rightDOWN");
29 + return;
30 +}
31 +
32 +// 좌측 피드백 활성화
33 +void LB(){
34 + digitalWrite(left_I, HIGH);
35 + delay(150);
36 + digitalWrite(left_I, LOW);
37 + count_L = 1;
38 + Serial.println("left");
39 + return;
40 +}
41 +// 좌측 피드백 비활성화
42 +void LBO(){
43 + digitalWrite(left_O,HIGH);
44 + delay(300);
45 + digitalWrite(left_O, LOW);
46 + count_L = 0;
47 + Serial.println("leftDOWN");
48 + return;
49 +}
50 +
51 +// 양측 피드백 활성화
52 +void both(){
53 + digitalWrite(left_I, HIGH);
54 + digitalWrite(right_I, HIGH);
55 + delay(150);
56 + digitalWrite(right_I, LOW);
57 + digitalWrite(left_I, LOW);
58 + count_B = 1;
59 + Serial.println("both");
60 + return;
61 +}
62 +
63 +// 양측 피드백 비활성화
64 +void bothO(){
65 + digitalWrite(right_O,HIGH);
66 + digitalWrite(left_O,HIGH);
67 + delay(300);
68 + digitalWrite(left_O,LOW);
69 + digitalWrite(right_O,LOW);
70 + count_B = 0;
71 + Serial.println("bothDOWN");
72 + return;
73 +}
74 +// 양측 피드백 활성화 확인
75 +void setBoth(){
76 + count_B = 1;
77 +}
78 +// 양측 비피드백 활성화 확인
79 +void setSingle(){
80 + count_B = 0;
81 +}
82 +
83 +void setup() {
84 + // put your setup code here, to run once:
85 + pinMode(right_I, OUTPUT);
86 + pinMode(right_O, OUTPUT);
87 + pinMode(left_I, OUTPUT);
88 + pinMode(left_O, OUTPUT);
89 + pinMode(control_R, INPUT);
90 + pinMode(control_L, INPUT);
91 + Serial.begin(4800);
92 +}
93 +
94 +void loop() {
95 + // 양측 트리거 신호를 수치화
96 + control_R_I = analogRead(control_R);
97 + Serial.print("right : ");
98 + Serial.println(control_R_I);
99 + control_L_I = analogRead(control_L);
100 + Serial.print("left : ");
101 + Serial.println(control_L_I);
102 +
103 + //UP
104 + if((control_R_I > 900 and control_R_I <= 927) and (control_L_I > 900 and control_L_I <= 927) and count_R == 0){
105 + RB();
106 + }
107 + 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){
108 + LB();
109 + }
110 + else if(control_R_I >= 970 and control_L_I >= 970 and count_B == 0 and count_R == 1 and count_L == 0){
111 + LB();
112 + setBoth();
113 + }
114 + else if(control_R_I >= 970 and control_L_I >= 970 and count_B == 0 and count_R == 0 and count_L == 1){
115 + RB();
116 + setBoth();
117 + }
118 + else if(control_R_I >= 970 and control_L_I >= 970 and count_B == 0){
119 + both();
120 + }
121 +
122 + //DOWN
123 + if((control_R_I > 900 and control_R_I <= 927) and (control_L_I > 900 and control_L_I <= 927) and count_L == 1){
124 + setSingle();
125 + LBO();
126 + }
127 + 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){
128 + setSingle();
129 + RBO();
130 + }
131 +
132 + //DOWN2
133 + if(control_R_I < 890 and control_L_I < 890 and count_R == 1){
134 + RBO();
135 + }
136 + else if(control_R_I < 890 and control_L_I < 890 and count_L == 1){
137 + LBO();
138 + }
139 + else if(control_R_I < 890 and control_L_I < 890 and count_B == 1){
140 + bothO();
141 + }
142 +}
No preview for this file type