-
Notifications
You must be signed in to change notification settings - Fork 0
/
interact_led_panel.ino
261 lines (253 loc) · 5.88 KB
/
interact_led_panel.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
250
251
252
253
254
255
256
257
258
259
260
261
#include "LedControlMS.h"
#include <Keypad.h>
#define NBR_MTX 2
LedControl lc = LedControl(12, 11, 10, NBR_MTX);
String digits = "1234567890";
int digitCounter = 0;
unsigned long delaytime = 300;
const byte ROWS = 4;
const byte COLS = 4;
char hexaKeys[ROWS][COLS] = {
{'1', '2', '3', 'A'},
{'4', '5', '6', 'B'},
{'7', '8', '9', 'C'},
{'*', '0', '#', 'D'}};
byte rowPins[ROWS] = {9, 8, 7, 6};
byte colPins[COLS] = {5, 4, 3, 2};
Keypad customKeypad = Keypad(makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS);
int VRx = A0;
int VRy = A1;
int SW = A2;
int xPosition = 0;
int yPosition = 0;
int SW_state = 0;
int mapX = 0;
int mapY = 0;
void setup()
{
Serial.begin(9600);
Serial.println("Setup");
digitCounter = 0;
for (int i = 0; i < NBR_MTX; i++)
{
lc.shutdown(i, false);
lc.setIntensity(i, 1);
lc.clearDisplay(i);
}
pinMode(VRx, INPUT);
pinMode(VRy, INPUT);
pinMode(SW, INPUT_PULLUP);
}
int string_in(const char *string, const char **strings, size_t strings_num)
{
for (size_t i = 0; i < strings_num; i++)
{
if (!strcmp(string, strings[i]))
{
return 1;
}
}
return -1;
}
int GetNumber(char key)
{
int num = 0;
switch (key)
{
case NO_KEY:
break;
case '0':
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '9':
num = num * 10 + (key - '0');
break;
case '*':
num = 0;
break;
}
return num;
}
/*
* 0: rien
* 1: poulpe
* 2 : alien
*/
int type = 0;
int new_type = 0;
int posXG = 0;
int posYG = 0;
void loop()
{
char customKey = customKeypad.getKey();
int v1 = GetNumber(customKey);
if (v1)
{
new_type = v1;
}
if (type != new_type)
{
digitCounter = 0;
for (int i = 0; i < NBR_MTX; i++)
{
lc.shutdown(i, false);
lc.setIntensity(i, 1);
lc.clearDisplay(i);
}
type = new_type;
delay(5);
int a[64] = {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1};
if (type == 1)
{
Serial.println("change to poulpe");
int poulpe[18] = {0, 1, 6, 7, 8, 15, 26, 29, 32, 39, 40, 41, 46, 47, 48, 55, 58, 61};
for (int z = 0; z < 18; z++)
{
a[poulpe[z]] = 0;
}
}
else if (type == 2)
{
Serial.println("change to alien");
int jean[34] = {0, 2, 3, 4, 5, 7, 8, 11, 12, 15, 16, 17, 19, 20, 22, 23, 24, 25, 26, 29, 30, 31, 32, 33, 38, 39, 40, 42, 45, 47, 56, 59, 60, 63};
for (int z = 0; z < 34; z++)
{
a[jean[z]] = 0;
}
}
else if (type == 3)
{
Serial.println("change to PD");
int jean[30] = {0, 1, 2, 4, 5, 8, 10, 12, 14, 16, 18, 20, 23, 24, 25, 26, 28, 31, 32, 36, 39, 40, 44, 47, 48, 52, 54, 56, 60, 61};
for (int z = 0; z < 64; z++)
{
a[z] = 0;
}
for (int z = 0; z < 30; z++)
{
a[jean[z]] = 1;
}
}
else if (type == 4)
{
Serial.println("change to game");
for (int z = 0; z < 64; z++)
{
a[z] = 0;
}
a[0] = 1;
lc.setLed(0, 0, 0, true);
}
else
{
Serial.println("change to othersss");
for (int z = 0; z < 64; z++)
{
a[z] = 0;
}
}
delay(10);
int c = -1;
int val = 0;
for (int i = 0; i < 8; i++)
{
for (int j = 0; j < 8; j++)
{
val = 8 * j + i;
//Serial.println("a[val]");
//Serial.println(val);
//Serial.println(a[val]);
if (a[val] == 1)
{
lc.setLed(0, j, i, true);
}
else
{
lc.setLed(0, j, i, false);
}
// delay(5);
}
}
Serial.println("------");
}
if (type == 4)
{
xPosition = analogRead(VRx);
yPosition = analogRead(VRy);
SW_state = digitalRead(SW);
mapX = map(xPosition, 0, 1023, -512, 512);
mapY = map(yPosition, 0, 1023, -512, 512);
int newPosXG = posXG;
int newPosYG = posYG;
if (mapX > 250)
{
if (posXG == 7)
{
newPosXG = 0;
}
else
{
newPosXG = newPosXG + 1;
}
}
else if (mapX < -250)
{
if (posXG == 0)
{
newPosXG = 7;
}
else
{
newPosXG = newPosXG - 1;
}
}
if (mapY > 250)
{
if (posYG == 7)
{
newPosYG = 0;
}
else
{
newPosYG = newPosYG + 1;
}
}
else if (mapY < -250)
{
if (posYG == 0)
{
newPosYG = 7;
}
else
{
newPosYG = newPosYG - 1;
}
}
lc.setLed(0, posXG, posYG, false);
lc.setLed(0, newPosXG, newPosYG, true);
posXG = newPosXG;
posYG = newPosYG;
/*
Serial.print("X: ");
Serial.print(mapX);
Serial.print(" | Y: ");
Serial.print(mapY);
Serial.print(" | Button: ");
Serial.println(SW_state);
*/
}
if (type == 3)
{
delay(100);
}
else
{
delay(200);
}
}