-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsamuelsays.ino
230 lines (215 loc) · 4.47 KB
/
samuelsays.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
#include <Button.h>
#include "SoftwareSerial.h"
#include "DFRobotDFPlayerMini.h"
#define SOFT_SERIAL_TX 2
#define SOFT_SERIAL_RX 3
#define PIN_BOTON_1 4
#define PIN_BOTON_2 5
#define PIN_BOTON_3 6
#define PIN_BOTON_4 7
#define PIN_BOTON_5 8
#define PIN_LED_1 9
#define PIN_LED_2 10
#define PIN_LED_3 11
#define PIN_LED_4 12
#define PIN_LED_5 13
Button b1(PIN_BOTON_1);
Button b2(PIN_BOTON_2);
Button b3(PIN_BOTON_3);
Button b4(PIN_BOTON_4);
Button b5(PIN_BOTON_5);
#define SONIDO_START_JUEGO 0
#define SONIDO_NUM_JUGADORES_1 1
#define SONIDO_NUM_JUGADORES_2 2
#define SONIDO_NUM_JUGADORES_3 3
#define SONIDO_NUM_JUGADORES_4 4
#define SONIDO_ELIJA_NUM_JUG 5
#define SONIDO_LO_HAS_PETADO 6
#define SONIDO_PULSAR_B1 7
#define SONIDO_PULSAR_B2 8
#define SONIDO_PULSAR_B3 9
#define SONIDO_PULSAR_B4 10
#define SONIDO_PULSAR_B5 11
#define SONIDO_ERES_UN_PAQUETE 12
const byte MAX_SECUENCIA=255;
byte secuencia[255];
byte modo=0;
byte num_jugadores = 0;
byte jugador_turno=0;
byte fase = 0;
int velocidad = 1000;
int espera = 1000;
SoftwareSerial soft_serial(SOFT_SERIAL_RX, SOFT_SERIAL_TX); // RX, TX
DFRobotDFPlayerMini mp3;
void setup()
{
b1.begin();
b2.begin();
b3.begin();
b4.begin();
b5.begin();
pinMode(PIN_LED_1,OUTPUT);
pinMode(PIN_LED_2,OUTPUT);
pinMode(PIN_LED_3,OUTPUT);
pinMode(PIN_LED_4,OUTPUT);
pinMode(PIN_LED_5,OUTPUT);
mp3.begin(soft_serial);
}
void loop()
{
switch (fase)
{
case 0:
prejuego();
break;
case 1: //juego
juego();
break;
case 2: // fin
fin();
break;
}
}
void prejuego()
{
apagarLeds();
if (b1.released()) // Un jugador
{
num_jugadores = 1;
apagarLeds();
digitalWrite(PIN_LED_1,HIGH);
mp3.play(SONIDO_NUM_JUGADORES_1);
}
if (b2.released()) // dos jugadores
{
num_jugadores = 2;
apagarLeds();
digitalWrite(PIN_LED_2,HIGH);
mp3.play(SONIDO_NUM_JUGADORES_2);
}
if (b3.released()) // 3 jugadores
{
num_jugadores = 3;
apagarLeds();
digitalWrite(PIN_LED_3,HIGH);
mp3.play(SONIDO_NUM_JUGADORES_3);
}
if (b4.released()) // 4 jugadores
{
num_jugadores = 4;
apagarLeds();
digitalWrite(PIN_LED_4,HIGH);
mp3.play(SONIDO_NUM_JUGADORES_4);
}
if (b5.released()) // Start
{
if (num_jugadores != 0) {
fase = 1;
//tocarSonido Start
mp3.play(SONIDO_START_JUEGO);
}
else
{
mp3.play(SONIDO_ELIJA_NUM_JUG);
}
}
}
void apagarLeds()
{
digitalWrite(PIN_LED_1,LOW);
digitalWrite(PIN_LED_2,LOW);
digitalWrite(PIN_LED_3,LOW);
digitalWrite(PIN_LED_4,LOW);
digitalWrite(PIN_LED_5,LOW);
}
void juego()
{
static byte i= 0;
secuencia[i] = random(1,6);
// tocar secuencia
for (byte j=0; j<=i; j++)
{
apagarLeds();
switch (secuencia[j])
{
case 1:
digitalWrite(PIN_LED_1,HIGH);
mp3.play(SONIDO_PULSAR_B1);
break;
case 2:
digitalWrite(PIN_LED_2,HIGH);
mp3.play(SONIDO_PULSAR_B2);
break;
case 3:
digitalWrite(PIN_LED_3,HIGH);
mp3.play(SONIDO_PULSAR_B3);
break;
case 4:
digitalWrite(PIN_LED_4,HIGH);
mp3.play(SONIDO_PULSAR_B4);
break;
case 5:
digitalWrite(PIN_LED_5,HIGH);
mp3.play(SONIDO_PULSAR_B4);
break;
}
delay(velocidad);
}
//esperar jugador
static byte boton=0;
for (byte k=0; k<=i; k++)
{
while (b1.toggled() || b2.toggled() || b3.toggled() || b4.toggled() || b5.toggled())
{
if (b1.released())
{
boton=1;
digitalWrite(PIN_LED_1,HIGH);
mp3.play(SONIDO_PULSAR_B1);
}
else
{
if (b2.released())
{
boton=2;
digitalWrite(PIN_LED_2,HIGH);
mp3.play(SONIDO_PULSAR_B2);
}
else
{
if (b3.released())
{
boton=3;
digitalWrite(PIN_LED_3,HIGH);
mp3.play(SONIDO_PULSAR_B3);
}
else
{
if (b4.released())
{
boton=4;
digitalWrite(PIN_LED_4,HIGH);
mp3.play(SONIDO_PULSAR_B4);
}
else
{
boton=5;
digitalWrite(PIN_LED_5,HIGH);
mp3.play(SONIDO_PULSAR_B5);
}
}
}
}
}
if (boton != secuencia[k])
{
modo=2;
break;
}
}
}
void fin()
{
mp3.play(SONIDO_ERES_UN_PAQUETE);
delay(300);
}