-
Notifications
You must be signed in to change notification settings - Fork 0
/
백업-모드전환.ino
156 lines (137 loc) · 2.95 KB
/
백업-모드전환.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
#include <Arduino_APDS9960.h>
#define PIXEL 0
#define EQUALIZER 1
#define EMOTION 2
#define HEART 3
#define ANDROID 10
#define TREE 11
#define RAINBOW 12
#define SNOW 13
// 프로그램 전반
int prevMenu(int menu);
int nextMenu(int menu);
void switchMenu(int menu);
// 메뉴0 : 픽셀모드
void pixelMode(int pixel);
void showAndroid();
void showTree();
void showRainbow();
void showSnow();
int prevPixel(int pixel);
int nextPixel(int pixel);
// 메뉴1 : 이퀄라이저모드
void equalizerMode();
// 메뉴2 : 감정모드
void emotionMode();
// 메뉴3 : 심박모드
void heartMode();
int menu = 0;
int pixel = 10;
void setup() {
Serial.begin(9600);
while (!Serial);
if (!APDS.begin()) {
Serial.println("APDS9960센서 오류!");
while (1);
}
//APDS.setSensitivity(80); //감도 조절 (1~100)
Serial.println("제스처 인식 시작!");
}
void loop() {
if (APDS.gestureAvailable()) {
int gesture = APDS.readGesture();
// XXX : if gesture up/down 고려할 필요 없는가?
switch (gesture) {
case GESTURE_UP:
Serial.println("위로!");
menu=prevMenu(menu);
switchMenu(menu);
break;
case GESTURE_DOWN:
Serial.println("아래로!");
menu=nextMenu(menu);
switchMenu(menu);
break;
case GESTURE_LEFT:
Serial.println("왼쪽으로!");
if(menu == PIXEL){
pixel=prevPixel(pixel);
pixelMode(pixel);
}
break;
case GESTURE_RIGHT:
Serial.println("오른쪽으로!");
if(menu == PIXEL){
pixel=nextPixel(pixel);
pixelMode(pixel);
}
break;
}
}
}
void switchMenu(int menu){
if(menu==PIXEL) pixelMode(pixel);
else if(menu == EQUALIZER) equalizerMode();
else if(menu == EMOTION) emotionMode();
else if(menu == HEART) heartMode();
}
int prevMenu(int menu){
if(menu == 0) return 3;
return menu-1;
}
int nextMenu(int menu){
if(menu == 3) return 0;
return menu+1;
}
void switchPixel(int pixel){
if(pixel==PIXEL) pixelMode(pixel);
else if(pixel == EQUALIZER) equalizerMode();
else if(pixel == EMOTION) emotionMode();
else if(pixel == HEART) heartMode();
}
int prevPixel(int pixel){
if(pixel == 10) return 13;
return pixel-1;
}
int nextPixel(int pixel){
if(pixel == 13) return 10;
return pixel+1;
}
void pixelMode(int pixel){
Serial.println("0. 픽셀모드");
switch (pixel) {
case ANDROID:
showAndroid();
break;
case TREE:
showTree();
break;
case RAINBOW:
showRainbow();
break;
case SNOW:
showSnow();
break;
}
}
void showAndroid(){
Serial.println("10.Android");
}
void showTree(){
Serial.println("11.tree");
}
void showRainbow(){
Serial.println("12.rainbow");
}
void showSnow(){
Serial.println("13.snow");
}
void equalizerMode(){
Serial.println("1.이퀄라이저");
}
void emotionMode(){
Serial.println("2.이모션");
}
void heartMode(){
Serial.println("3.하트");
}