-
Notifications
You must be signed in to change notification settings - Fork 2
/
Arduino_Code_Sample.ino
249 lines (196 loc) · 5.87 KB
/
Arduino_Code_Sample.ino
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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
//Include libraries
#include <Servo.h>
#include <DRV8833.h>
//create motor objects
DRV8833 driver = DRV8833();
Servo myservo;
//define constants and variables
const int red=6, green=7, blue=8;
const int inputA1 = 5, inputA2 = 4, inputB1 = 12, inputB2 = 11;
const int servopin = 9;
const int motorSpeedslow = 140;
const int motorSpeedfast = 200;
bool ce= LOW;
bool bit1=LOW;
bool bit2=LOW;
bool bit3=LOW;
int flag=0;
//initialize pins
void setup()
{
Serial.begin(9600);
pinMode(red, OUTPUT);
pinMode(green, OUTPUT);
pinMode(blue, OUTPUT);
pinMode(inputA1, OUTPUT);
pinMode(inputA2, OUTPUT);
pinMode(inputB1, OUTPUT);
pinMode(inputB2, OUTPUT);
pinMode(servopin, OUTPUT);
pinMode(A1, INPUT);
pinMode(A2, INPUT);
pinMode(A3, INPUT);
pinMode(A4, INPUT);
while (!Serial);
myservo.attach(servopin); // attaches the servo on pin 9 to the servo object
myservo.write(0);
delay(300);
// Attach the motors to the input pins:
driver.attachMotorA(inputA1, inputA2);
driver.attachMotorB(inputB1, inputB2);
}
//process code
void loop()
{
ce = digitalRead(A1);
Serial.println("CE: ");
Serial.println(ce);
if (ce == HIGH)
{
bit1=digitalRead(A2);
bit2=digitalRead(A3);
bit3=digitalRead(A4);
Serial.println("Bit1: ");
Serial.println(bit1);
Serial.println("Bit2: ");
Serial.println(bit2);
Serial.println("Bit3: ");
Serial.println(bit3);
//Happiness - done
if(bit1==HIGH and bit2==LOW && bit3 == LOW){
Serial.println("Happy");
driver.motorBReverse(motorSpeedslow);
driver.motorAForward(motorSpeedslow);
digitalWrite(red,HIGH);
digitalWrite(blue, LOW);
digitalWrite(green, LOW);
delay(1000);
digitalWrite(red,LOW);
digitalWrite(blue, HIGH);
digitalWrite(green, LOW);
delay(1000);
digitalWrite(red,LOW);
digitalWrite(blue, LOW);
digitalWrite(green, HIGH);
delay(3500);
driver.motorBStop();
driver.motorAStop();
delay(1000);
digitalWrite(red,LOW);
digitalWrite(blue, LOW);
digitalWrite(green, LOW);
Serial.println("Happy 1");
}
//Sadness - done
if(bit1==LOW and bit2==HIGH && bit3 == LOW){
Serial.println("Sad");
digitalWrite(red,LOW);
digitalWrite(blue, HIGH);
digitalWrite(green, LOW);
}
//Fear - done
if(bit1==HIGH and bit2==HIGH && bit3 == LOW)
{
Serial.println("Fear");
digitalWrite(red,HIGH);
digitalWrite(blue, HIGH);
digitalWrite(green, LOW);
//cover eyes with tentacles
myservo.write(180);
// Put the motors in reverse using the speed:
driver.motorAForward(motorSpeedslow);
driver.motorBForward(motorSpeedslow);
// Wait to see the effect:
delay(500);
//Stop
driver.motorAStop();
driver.motorBStop();
//Forward
delay(2000);
myservo.write(0);
driver.motorAReverse(motorSpeedslow);
driver.motorBReverse(motorSpeedslow);
delay(500);
//Stop
driver.motorAStop();
driver.motorBStop();
//uncover eyes
delay(2000);
}
//Disgust - done
if(bit1==LOW and bit2==LOW && bit3 == HIGH)
{
Serial.println("Disgust");
digitalWrite(red,HIGH);
digitalWrite(blue, HIGH);
digitalWrite(green, LOW);
if (flag == 0) {
myservo.write(0); // tell servo to go to position in variable 'pos'
delay(400); // waits 15ms for the servo to reach the position
myservo.write(180); // tell servo to go to position in variable 'pos'
// wait for a second
delay(1100); // waits 15ms for the servo to reach the position
flag=1;
}
for (int j=0; j<5;j++){
myservo.write(0); // tell servo to go to position in variable 'pos'
delay(100); // waits 15ms for the servo to reach the position
myservo.write(180); // tell servo to go to position in variable 'pos'
delay(100);
}
myservo.write(180); // tell servo to go to position in variable 'pos'
delay(500); // waits 15ms for the servo to reach the position
flag=1;
for (int j=0; j<5;j++){
myservo.write(0); // tell servo to go to position in variable 'pos'
delay(100); // waits 15ms for the servo to reach the position
myservo.write(180); // tell servo to go to position in variable 'pos'
delay(100);
}
myservo.write(0);
}
//Anger
if(bit1==HIGH and bit2==LOW && bit3 == HIGH){
Serial.println("Anger");
digitalWrite(red,HIGH);
digitalWrite(blue, LOW);
digitalWrite(green, LOW);
// Put the motors in reverse using the speed:
driver.motorAReverse(motorSpeedslow);
driver.motorBReverse(motorSpeedslow);
// Wait to see the effect:
delay(100);
//Stop
driver.motorAReverse(motorSpeedslow);
driver.motorBStop();
//Forward
delay(200);
driver.motorAReverse(motorSpeedslow);
driver.motorBReverse(motorSpeedslow);
delay(100);
driver.motorAStop();
driver.motorBReverse(motorSpeedslow);
delay(200);
driver.motorAStop();
driver.motorBStop();
// 8 path code
/*
_ _
/ \
/ \
\ /
\ _ _ / <- an 8
/ \
/ \
\ /
\ _ _ /
*/
}
}
else
{
digitalWrite(red,HIGH);
digitalWrite(blue, HIGH);
digitalWrite(green, HIGH);
}
}