MainQuiPointeDroite.png Bonne année 2025 ! Meilleursvoeux.gif

ENIB 2025 : Jack Box

De Les Fabriques du Ponant
Aller à : navigation, rechercher

Titre de la fiche expérience :

Description

Notre équipe

Louis MELOU
Thomas BOURDAIS
Ethan GUILLET

Dans le cadre de l'hackathon organisé par les Petits Débrouillards, nous vous présentons notre magnifique Jack Box !

Outil et Matériel

Liste des outils et du matériel nécessaires
**Quantité** **Matériel/Outil**
1 Support
  • Carton pour le prototype
  • Bois pour le produit final
1 Carte Arduino LOLIN(WEMOS) D1 R2 &mini
1 Lecteur DFPlayer mini MP3
1 Batterie externe pour l'alimentation
1 Câble USB-A vers USB-B mini
1 Carte SD
1 Hautparleur
4 Boutons Poussoirs
4 LED RGB
1 Breadboard
/ Fils

Code Arduino

Premier code arduino permettant de créer des sons:

 1  
 2 /**
 3                                 _________________
 4                                /     D1 mini     \
 5                               |[ ]RST        TX[ ]|
 6                               |[ ]A0  -GPIO  RX[ ]|
 7                               |[ ]D0-16    5-D1[ ]| SCL
 8                               |[ ]D5-14    4-D2[ ]| SDA
 9                               |[ ]D6-12    0-D3[ ]|
10                               |[ ]D7-13    2-D4[ ]| LED_BUILTIN
11                               |[ ]D8-15     GND[ ]|
12                               |[ ]3V3 .      5V[ ]|
13                               |       +---+       |
14                               |_______|USB|_______|
15 
16 */
17 #include <SoftwareSerial.h>
18 #include <DFRobotDFPlayerMini.h> 
19 
20 SoftwareSerial mySoftwareSerial(D5, D6);  // TX, RX
21 DFRobotDFPlayerMini myDFPlayer ; 
22 
23 const int start = 16; //start D0
24 const int bpJ = 5; //bouton 1 D1
25 const int bpB = 4; //bouton 2 D2
26 const int bpR = 0; //bouton 3 D3
27 const int bpG = 2; //bouton 4 D4
28 
29 
30 
31 const int led = 15; //led D8
32 
33 const int busy = 13; //etat son busy D7
34 
35 int player = 0;
36 int player1 = 0;
37 int player2 = 0;
38 int player3 = 0;
39 int player4 = 0;
40 
41 unsigned long previousTime = 0;
42 unsigned long timer = 0;
43 const unsigned long frequency=100;
44 
45 int randNumber = 0;
46 int musicState = 0;
47 int isUp = 0;
48 
49 //char game[]="";
50 
51 void setup() {
52   // put your setup code here, to run once:
53   Serial.begin(115200);
54   /*pinMode(start, INPUT);
55   pinMode(bpJ, INPUT);
56   pinMode(bpB, INPUT);  
57   pinMode(bpR, INPUT);
58   pinMode(bpG, INPUT);
59   pinMode(ledJ, OUTPUT);
60   pinMode(ledB, OUTPUT);
61   pinMode(ledR, OUTPUT);
62   pinMode(ledG, OUTPUT);*/
63   pinMode(busy, INPUT);
64   mySoftwareSerial.begin(9600) ;
65   myDFPlayer.begin(mySoftwareSerial) ;
66 }
67 
68 void loop() {
69   // put your main code here, to run repeatedly:
70   // Joue la premiere chanson de la carte SD pendant 10 secondes
71   myDFPlayer.setTimeOut(500) ;
72 
73   myDFPlayer.volume(10) ; // fixe le son à 10 (maximum)
74 
75   test();
76 }
77 
78 
79 void test(){
80   timer = millis();
81 
82   //presentation jeu
83     myDFPlayer.play(1); //intro jeu
84 
85 
86   Serial.println(digitalRead(busy));
87 
88 }

Code arduino non fonctionels des 2 mini-jeux

  1  
  2 /**
  3                                                   +-----+
  4          +----------| USB |----------+
  5          |          +-----+          |
  6          | [ ]D13/SCK    MISO/D12[ ] |
  7          | [ ]3.3V       MOSI/D11[ ]~|
  8          | [ ]V.ref    _   SS/D10[ ]~|
  9          | [ ]A0     / N \     D9[ ]~|
 10          | [ ]A1   /   A   \   D8[ ] |
 11          | [ ]A2   \   N   /   D7[ ] |
 12          | [ ]A3     \ 0 /     D6[ ]~|
 13          | [ ]A4/SDA           D5[ ]~|
 14          | [ ]A5/SCL           D4[ ] |
 15          | [ ]A6          INT1/D3[ ]~|
 16          | [ ]A7          INT0/D2[ ] |
 17          | [ ]5V              GND[ ] |
 18          | [ ]RST             RST[ ] |
 19          | [ ]GND 5V MOSI GND TX1[ ] |
 20          | [ ]Vin [ ] [ ] [ ] RX1[ ] |
 21          |        [ ] [ ] [ ]        |
 22          |        MISO SCK RST       |
 23          | NANO-V3                   |
 24          +---------------------------+
 25 */
 26 #include <SoftwareSerial.h>
 27 #include <FastLED.h>// TX, RX
 28 #define DATA_PIN 8
 29 
 30 const int start = 2; //start D0
 31 const int bpJ = 3; //bouton 1 D1
 32 const int bpB = 4; //bouton 2 D2
 33 const int bpR = 5; //bouton 3 D3
 34 const int bpG = 6; //bouton 4 D4
 35 
 36 
 37 
 38 int player = 0;
 39 int player1 = 0;
 40 int player2 = 0;
 41 int player3 = 0;
 42 int player4 = 0;
 43 
 44 
 45 int gameLen[100];
 46 int playerLen[100];
 47 int i=0;
 48 int isOk=0;
 49 int isPressed = 0;
 50 
 51 #define MAX_GAME_LENGTH 100
 52 
 53 
 54 /* Global variables - store the game state */
 55 byte gameSequence[MAX_GAME_LENGTH] = {0};
 56 byte gameIndex = 0;
 57 
 58 
 59 unsigned long previousTime = 0;
 60 unsigned long timer = 0;
 61  unsigned long t = 0;
 62 const unsigned long frequency=500;
 63 
 64 int randNumber = 0;
 65 int musicState = 0;
 66 int isUp = 0;
 67 int home = 0;
 68 
 69 void main_menu() {
 70 
 71   Serial.println("bouton appuyé !!!");
 72 
 73   home = 1;
 74   /*detachInterrupt(digitalPinToInterrupt(bpJ));
 75   detachInterrupt(digitalPinToInterrupt(bpB));
 76   detachInterrupt(digitalPinToInterrupt(bpR));
 77   detachInterrupt(digitalPinToInterrupt(bpG));*/
 78 }
 79 
 80 /*ICACHE_RAM_ATTR void rep_1(){
 81   t = millis();
 82   while(t+3000>millis()){
 83     if (digitalRead(bpJ)== 1){
 84       player1 +=1;
 85       break;
 86     }
 87     if (digitalRead(bpR)== 1 || digitalRead(bpB)== 1 || digitalRead(bpG)== 1){
 88       break;
 89     }
 90   }
 91 }*/
 92 CRGB leds[4];
 93 
 94 //char game[]="";
 95 
 96 
 97 
 98 void setup() {
 99   // put your setup code here, to run once:
100   Serial.begin(115200);
101   pinMode(start, INPUT);
102   pinMode(bpJ, INPUT);
103   pinMode(bpB, INPUT);
104   pinMode(bpR, INPUT);
105   pinMode(bpG, INPUT);
106   FastLED.addLeds<NEOPIXEL, DATA_PIN>(leds, 4);
107 }
108 
109 void loop() {
110   // put your main code here, to run repeatedly:
111   // Joue la premiere chanson de la carte SD pendant 10 secondes
112  //myDFPlayer.setTimeOut(500) ;
113 
114   //myDFPlayer.volume(10) ; // fixe le son à 10 (maximum)
115 
116   //test();
117   truc();
118 }
119 
120 
121 void truc(){
122 
123   while(true){
124     leds[0] = CRGB::Black;
125     leds[1] = CRGB::Black;
126     leds[2] = CRGB::Black;
127     leds[3] = CRGB::Black;
128     FastLED.show();
129   home = 0;
130   player= 0;
131   player1 = 0;
132   player2 = 0;
133   player3 = 0;
134   Serial.println(digitalRead(bpB));
135   player4 = 0;
136   if(digitalRead(bpJ)==1){
137     simon();
138   }
139   else if(digitalRead(bpB)==1){
140     
141     mastermind();
142     
143   }
144   else if(digitalRead(bpR)==1){
145     //quiz();
146   }
147   else if(digitalRead(bpG)==1){
148     //GMF();
149   }
150   }
151 }
152 
153 void simon(){
154   gameLen[i] = random(0,3);
155   playSequence();
156   buttonPressed();
157   verifSimon();
158   
159   i=i+1;
160 }
161 
162 void playSequence() {
163     for(int j = 0; j<i+1; j++){
164       if(gameLen[j]==0){
165         leds[gameLen[j]] = CRGB::Yellow;
166         FastLED.show();
167         delay(100);
168         leds[gameLen[j]] = CRGB::Black;
169         FastLED.show();
170       }
171       if(gameLen[j]==1){
172         leds[gameLen[j]] = CRGB::Blue;
173         FastLED.show();
174         delay(100);
175         leds[gameLen[j]] = CRGB::Black;
176         FastLED.show();
177       }
178       if(gameLen[j]==2){
179         leds[gameLen[j]] = CRGB::Red;
180         FastLED.show();
181         delay(100);
182         leds[gameLen[j]] = CRGB::Black;
183         FastLED.show();
184       }
185       if(gameLen[j]==3){
186         leds[gameLen[j]] = CRGB::Green;
187         FastLED.show();
188         delay(100);
189         leds[gameLen[j]] = CRGB::Black;
190         FastLED.show();
191       }
192     delay(200);
193     }
194   }
195 
196 void buttonPressed(){
197   for(int l = 0; l<i+1; l++){
198     while(isPressed=0){
199       if(digitalRead(bpJ)==1){
200         playerLen[l]=0;
201         leds[gameLen[l]] = CRGB::Yellow;
202         FastLED.show();
203         delay(100);
204         leds[gameLen[l]] = CRGB::Black;
205         FastLED.show();
206         isPressed = 1;
207       }
208       if(digitalRead(bpB)==1){
209         playerLen[l]=1;
210         leds[gameLen[l]] = CRGB::Blue;
211         FastLED.show();
212         delay(100);
213         leds[gameLen[l]] = CRGB::Black;
214         FastLED.show();
215         isPressed = 1;
216       }
217       if(digitalRead(bpR)==1){
218         playerLen[l]=2;
219         leds[gameLen[l]] = CRGB::Red;
220         FastLED.show();
221         delay(100);
222         leds[gameLen[l]] = CRGB::Black;
223         FastLED.show();
224         isPressed = 1;
225       }
226       if(digitalRead(bpG)==1){
227         playerLen[l]=3;
228         leds[gameLen[l]] = CRGB::Green;
229         FastLED.show();
230         delay(100);
231         leds[gameLen[l]] = CRGB::Black;
232         FastLED.show();
233         isPressed = 1;
234       }
235     }
236     isPressed = 0; 
237 
238   }
239 }
240 
241 void verifSimon(){
242   for(int k = 0; k<i+1; k++){
243     if(playerLen[k]==gameLen[k]){
244     }
245     else{
246       gameOver();
247     }  
248   }
249 }
250 
251 void gameOver(){
252         for(int m=0; m<5; m++)
253         leds[gameLen[0]] = CRGB::Yellow;
254         leds[gameLen[1]] = CRGB::Blue;
255         leds[gameLen[2]] = CRGB::Red;
256         leds[gameLen[3]] = CRGB::Green;
257         FastLED.show();
258         delay(100);
259         leds[gameLen[0]] = CRGB::Black;
260         leds[gameLen[1]] = CRGB::Black;
261         leds[gameLen[2]] = CRGB::Black;
262         leds[gameLen[3]] = CRGB::Black;
263         FastLED.show();
264         
265 }
266 
267 void mastermind(){
268   //presenter le jeu 
269   
270   while(home == 0){
271     int bouton;
272     int index = 0;
273     int reponse[4];
274     int essai[4];
275     previousTime = millis();
276     //Nombre de joueur 
277     delay(200);
278     while(player<1){
279       Serial.println("player");
280       if(digitalRead(bpJ)==1){
281         player = 1;
282       }
283       else if(digitalRead(bpB)==1){
284         player = 2;
285       }
286     }
287     //creation reponse
288     
289     if(player == 1){
290       reponse[0] = random(4);
291       reponse[1] = random(4);
292       reponse[2] = random(4);
293       reponse[3] = random(4);
294       
295     }
296     if( player == 2){
297       //audio pour dire de choisir 
298       while(index < 4){
299         timer = millis();
300         if (home == 1){
301           break;
302         }
303         if (timer - previousTime >= frequency ){
304           if(digitalRead(bpJ)==1){
305             reponse[index] = 0;
306             index += 1;
307             previousTime = timer;
308           }
309           else if(digitalRead(bpB)==1){
310             reponse[index] = 1;
311             index += 1;
312             previousTime = timer;
313           }
314           else if(digitalRead(bpR)==1){
315             reponse[index] = 2;
316             index += 1;
317             previousTime = timer;
318           }
319           else if(digitalRead(bpG)==1){
320             reponse[index] = 3;
321             index += 1;
322             previousTime = timer;
323           }
324         }
325       }
326     }
327     index = 0;
328     //lancement jeu
329     while(home == 0){
330       Serial.println("jdoezd");
331       timer = millis();
332       if (timer - previousTime >= frequency ){
333         if(digitalRead(bpJ)==1){
334           essai[index] = 0;
335           leds[index] = CRGB::Blue;
336           FastLED.show();
337           delay(200);
338           leds[index] = CRGB::Black;
339           FastLED.show();
340           index += 1;
341           previousTime = timer;
342         }
343         else if(digitalRead(bpB)==1){
344           essai[index] = 1;
345           leds[index] = CRGB::Purple;
346           FastLED.show();
347           delay(200);
348           leds[index] = CRGB::Black;
349           FastLED.show();
350           index += 1;
351           previousTime = timer;
352           
353         }
354         else if(digitalRead(bpR)==1){
355           essai[index] = 2;
356           leds[index] = CRGB::Pink;
357           FastLED.show();
358           delay(200);
359           leds[index] = CRGB::Black;
360           FastLED.show();
361           index += 1;
362           previousTime = timer;
363         }
364         else if(digitalRead(bpG)==1){
365           essai[index] = 3;
366           leds[index] = CRGB::LightYellow;
367           FastLED.show();
368           delay(200);
369           leds[index] = CRGB::Black;
370           FastLED.show();
371           index += 1;
372           previousTime = timer;
373         }
374       }
375       if(index == 4){
376         for (int i=0; i<4; i++){
377           int bon = 0;
378           if (home == 1){
379             break;
380           }
381           for (int j=0; i<4; i++){
382             if (i==j && reponse[i]==essai[j]){
383               //son bon
384               leds[essai[j]] = CRGB::Green;
385               FastLED.show();
386               delay(200);
387               leds[essai[j]] = CRGB::Black;
388               FastLED.show();
389               bon += 1;
390               break;
391             }
392             else if (reponse[i]==essai[j]){
393               //son bon mais mauvaise place
394               leds[essai[j]] = CRGB::Yellow;
395               FastLED.show();
396               delay(200);
397               leds[essai[j]] = CRGB::Black;
398               FastLED.show();
399               break;
400             }
401             else if (j==3){
402               //son mauvais
403               leds[essai[j]] = CRGB::Red;
404               FastLED.show();
405               delay(200);
406               leds[essai[j]] = CRGB::Black;
407               FastLED.show();
408             }
409             if (home == 1 || bon == 3){
410               main_menu();
411               break;
412             }
413             if (j==3){
414               index = 0;
415             }
416           }
417         }
418       }
419     }
420   }
421 }
422       //si 2 joueur choix de la combinaison 
423       //devine le jeu
424 
425 /*void quiz(){
426   attachInterrupt(digitalPinToInterrupt(bpJ), rep_1, RISING);
427   //attachInterrupt(digitalPinToInterrupt(bpB), rep_2, RISING);
428   //attachInterrupt(digitalPinToInterrupt(bpR), rep_3, RISING);
429   //attachInterrupt(digitalPinToInterrupt(bpG), rep_4, RISING);
430   while(home==0){
431     //presente le jeu
432     //question 1
433     t = millis();
434     while(t+3000>millis()){//temps de reponse}
435     if(player1 == 5 ||player2 == 5 ||player3 == 5 ||player4 == 5){
436       main_menu();
437     }
438   }  
439 }*/
440 /*
441 void GMF() {
442   timer = millis();
443 
444   //presentation jeu
445   myDFPlayer.play(1); //intro jeu
446 
447   //nb joueurs
448   if(bpJ==HIGH){
449     player = 1;
450     myDFPlayer.pause();
451   }
452   else if(bpB==HIGH){
453     player = 2;
454     myDFPlayer.pause();
455   }
456   else if(bpR==HIGH){
457     player = 3;
458     myDFPlayer.pause();
459   }
460   else if(bpG==HIGH){
461     player = 4;
462     myDFPlayer.pause();
463   }
464 
465   //lance le jeu, 1ere manche
466   randNumber = random(50);
467   myDFPlayer.play(randNumber);
468   digitalWrite(ledJ, HIGH);
469 
470   //fin du jeu à 5 points
471     if (timer - previousTime >= frequency ){
472     previousTime = timer;
473     if(isUp==0){
474       isUp=1;
475     }
476     else{
477       isUp==0;
478     }   
479   }
480 
481   if(player1==5){
482     if(isUp==0){
483       digitalWrite(ledJ, HIGH);
484     }
485     else{
486       digitalWrite(ledJ, LOW);
487     }
488   }
489 
490   else if(player2==5){
491     if(isUp==0){
492       digitalWrite(ledB, HIGH);
493     }
494     else{
495       digitalWrite(ledB, LOW);
496     }
497   }
498 
499   else if(player3==5){
500     if(isUp==0){
501       digitalWrite(ledR, HIGH);
502     }
503     else{
504       digitalWrite(ledR, LOW);
505     }
506   }
507 
508   else if(player4==5){
509     if(isUp==0){
510       digitalWrite(ledG, HIGH);
511     }
512     else{
513       digitalWrite(ledG, LOW);
514     }
515   }
516   //Stop du jeu par le bouton start et retour au départ
517 
518   if(start==HIGH){
519     state = "Home";
520   }
521 }*/
522 
523 
524 
525 /*void test(){
526   timer = millis();
527 
528   //presentation jeu
529     myDFPlayer.play(1); //intro jeu
530 
531 
532   Serial.println(digitalRead(busy));

}*/

étapes de fabrication

indiquer autant d'étape que nécessaire, chacune illustrée par des images (photo, dessins, ...)

étape 1

En premier lieu nous avons imaginé un hack sur la base du kit 'Boxson' donné par les Petits débrouillards.
Nous avons, au départ, choisi de construire la Jack Box une boîte à jeu contenant 4 mini-jeux qui sont les suivants :
Un Simon; Un Mastermind; Un Quiz et Un Guess My Fart.

IMG20250122110407.jpg

étape 2

Nous sommes ensuite passés au premier prototype ce qui nous a permis de nous rendre compte des dimensions nécessaires au bon fonctionnement de la Jack Box  :

1737621729479.jpg

étape 3

Une fois une idée claire du design de la Jack Box en tête, nous avons commencé à construire la version finale de notre projet tout en câblant les différents composants électroniques à la carte arduino :

Support Final
Câblage

Troubleshouting

Dans ce projet, c'est la carte qui nous a apporté le plus de difficultés.
En effet, la gestion des sons grâce au lecteur MP3 nous a donné du fil à retordre !
Nous avons beaucoup mis du temps avant de pouvoir entendre un son sortir du hautparleur et encore plus de temps pour le maîtriser.

A cause de ces malheureuses complications, nous n'avons pas pu finir ce projet.
Nous sommes passés de 4 mini-jeux à 2 mini-jeux dont les programmes ne sont pas fonctionnels.

Elément de présentation

Nous vous invitons à télécharger notre affiche de présentation de la JACK BOX