-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
196 lines (169 loc) · 4.04 KB
/
main.cpp
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
#include <Adafruit_CircuitPlayground.h>
float X, Y, Z;
int stage = 0;
float value;
int light_value;
bool start(){
if ((PINF & (1<<6)) == 0){ // if not pressed
return false;
}
else { // pressed
return true;
}
}
bool up(float X, float Y, float Z){
return (Z > 9);
}
bool down(float X, float Y, float Z){
return (Z < -9);
}
bool left(float X, float Y, float Z){
return (Y > 9);
}
bool right(float X, float Y, float Z){
return (Y < -9);
}
bool forward(float X, float Y, float Z){
return (X > 9);
}
bool backward(float X, float Y, float Z){
return (X < -9);
}
bool shake(float X, float Y, float Z){
return (Y > 15 || Y < -15);
}
bool goDown(float X, float Y, float Z){
return (Z < 12);
}
bool goUp(float X, float Y, float Z){
return (Z > 12);
}
bool blow(float val){
return (val > 90);
}
bool dark(float val){
return (val < 10);
}
void setup() {
// set right button as input (PF6)
DDRF &= ~(1<<6);
Serial.begin(9600);
CircuitPlayground.begin();
}
void loop() {
delay(100);
value = CircuitPlayground.mic.soundPressureLevel(10);
X = CircuitPlayground.motionX();
Y = CircuitPlayground.motionY();
Z = CircuitPlayground.motionZ();
light_value = CircuitPlayground.lightSensor(); // dark approaches 0
Serial.print("X: ");
Serial.print(X);
Serial.print(" Y: ");
Serial.print(Y);
Serial.print(" Z: ");
Serial.println(Z);
Serial.print("Stage ");
Serial.println(stage);
// Serial.print("Sound Sensor SPL: ");
// Serial.println(value);
// Serial.print("Light Sensor: ");
// Serial.println(light_value);
// 10 gesture stages check
if (stage == -1){
CircuitPlayground.setPixelColor(0, 255, 0, 0);
}
if (stage == -2){
CircuitPlayground.setPixelColor(1, 128, 128, 0);
}
if (stage == -3){
CircuitPlayground.setPixelColor(2, 0, 255, 0);
}
if (stage == -4){
CircuitPlayground.setPixelColor(3, 0, 128, 128);
}
if (stage == -5){
CircuitPlayground.setPixelColor(4, 0, 0, 255);
}
if (stage == -6){
CircuitPlayground.setPixelColor(5, 0xFF0000);
}
if (stage == -7){
CircuitPlayground.setPixelColor(6, 0x808000);
}
if (stage == -8){
CircuitPlayground.setPixelColor(7, 0x00FF00);
}
if (stage == -9){
CircuitPlayground.setPixelColor(8, 0x008080);
}
if (stage == -10){
CircuitPlayground.setPixelColor(9, 0x0000FF);
}
if (start()){
if (stage == 0){
if (up(X, Y, Z)) { stage = 1; }
if (down(X, Y, Z)) { stage = 2; }
if (forward(X, Y, Z)) { stage = 9; }
if (left(X, Y, Z)) { stage = 11; }
if (backward(X, Y, Z)) { stage = 13; }
if (right(X, Y, Z)) { stage = 15;}
}
if (stage == 1){
if (left(X, Y, Z)) { stage = 3; }
if (right(X, Y, Z)) { stage = 4; }
if (forward(X, Y, Z)) { stage = 5; }
if (backward(X, Y, Z)) { stage = 6; }
if (goUp(X, Y, Z)) { stage = 14; }
}
if (stage == 2){
if (goDown(X, Y, Z)) { stage = 7; }
}
if (stage == 3){
if (down(X, Y, Z)) { stage = -1; }
}
if (stage == 4){
if (down(X, Y, Z)) { stage = -2; }
}
if (stage == 5){
if (down(X, Y, Z)) { stage = -3; }
}
if (stage == 6){
if (down(X, Y, Z)) { stage = -4; }
}
if (stage == 7){
if (left(X, Y, Z)) { stage = 8; }
}
if (stage == 8){
if (shake(X, Y, Z)) { stage = -6; }
}
if (stage == 9){
if (blow(value)) { stage = 10; }
}
if (stage == 10){
if (shake(X, Y, Z)) { stage = -7; }
}
if (stage == 11){
if (dark(light_value)) { stage = -8; }
}
if (stage == 12){
if (dark(light_value)) { stage = -9; }
}
if (stage == 13){
if (blow(value)) { stage = 12; }
}
if (stage == 14){
if (dark(light_value)) { stage = -10; }
}
if (stage == 15){
if (up(X, Y, Z)) { stage = 16; }
}
if (stage == 16){
if (shake(X, Y, Z)) { stage = -5; }
}
}
// else{ // This is only for testing, in project we only need to reach one gesture stage
// CircuitPlayground.clearPixels();
// stage = 0;
// }
}