C'est le printemps ! Fleur.gif

Jeu tetris arduino nano

De Les Fabriques du Ponant
Aller à : navigation, rechercher

jeu Tetris avec un Arduino NANO

Inspiration

Je me suis inspiré de 2 travaux, celui de Laurent Marchal à l'UBO open factory ainsi que celui de Prathamesh Barik sur circuitdigest https://circuitdigest.com/microcontroller-projects/creating-tetris-game-with-arduino-and-oled-display

l'idée est de créer un jeu de Tetris en utilisant un écran OLED et un Arduino NANO

matériel

  • Arduino NANO et son câble
  • 4 boutons poussoir
  • un écran OLED
  • un buzzer
  • câbles
  • embases à souder
  • plaques de prototypages
  • batterie

Schéma de câblage

Point de vigilance
Dans un premier temps faire les câblages à vide sur une breadboard, puis une fois tout est ok faire les soudures pour un projet qui tienne, j'ai utilisé une planque de prototypage qui permet de souder les masses et l'alimentation sur les côtés et j'ai utilisé des embases afin de pouvoir changer d'Arduino " au cas où ".


schema 1 2 3
Schema de cablage tetris nano.png
Tetris 1.jpg
Tetris 2.jpg
Tetris 3.jpg

Code

Point de vigilance
faire attention au emplacement des boutons poussoirs; au moment du televersement attention a bien mettre la carte , le port COM

Fichier:Code-tetris-ok-jan-25-arduino-nano.ino

  1  
  2 #include <Wire.h>
  3   #include <Adafruit_GFX.h>
  4   #include <Adafruit_SSD1306.h>
  5   #define WIDTH 64 // OLED display width, in pixels
  6   #define HEIGHT 128 // OLED display height, in pixels
  7   Adafruit_SSD1306 display(128, 64, &Wire, -1);
  8   static const unsigned char PROGMEM mantex_logo [] = {
  9   0x00, 0x00, 0x18, 0x06, 0x01, 0xc0, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 
 10     0x00, 0x00, 0x3c, 0x0f, 0x03, 0xe0, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 
 11     0x00, 0x00, 0x3e, 0x0f, 0x83, 0xe0, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 
 12     0x00, 0x00, 0x3e, 0x0f, 0x83, 0xe0, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 
 13     0x00, 0x00, 0x3e, 0x0f, 0x83, 0xe0, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 
 14     0x00, 0x00, 0x3e, 0x0f, 0x83, 0xe0, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 
 15     0x00, 0x00, 0x3e, 0x0f, 0x83, 0xe0, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 
 16     0x00, 0x00, 0x3e, 0x0f, 0x83, 0xe0, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 
 17     0x00, 0x00, 0xff, 0xff, 0xff, 0xf0, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 
 18     0x00, 0x03, 0xff, 0xff, 0xff, 0xfc, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 
 19     0x00, 0x0f, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 
 20     0x00, 0x1f, 0xff, 0xff, 0xff, 0xff, 0x80, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 
 21     0x00, 0x3f, 0x80, 0x00, 0x00, 0x0f, 0xc0, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 
 22     0x00, 0x3e, 0x00, 0x00, 0x00, 0x07, 0xe0, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 
 23     0x00, 0x7c, 0x00, 0x00, 0x00, 0x01, 0xe0, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 
 24     0x00, 0x78, 0x7f, 0xff, 0xff, 0xe1, 0xf0, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 
 25     0x00, 0xf8, 0xff, 0xff, 0xff, 0xf0, 0xf0, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 
 26     0x00, 0xf1, 0xff, 0xff, 0xff, 0xf8, 0xf0, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 
 27     0x00, 0xf1, 0xff, 0xff, 0xff, 0xfc, 0xf8, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 
 28     0x7f, 0xf1, 0xff, 0x0f, 0xff, 0xfc, 0xff, 0xf0, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 
 29     0xff, 0xf1, 0xfc, 0x01, 0xff, 0xfc, 0xff, 0xf0, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 
 30     0xff, 0xf1, 0xf0, 0x00, 0xff, 0xfc, 0xff, 0xf0, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 
 31     0x7f, 0xf1, 0xf0, 0x00, 0x7f, 0xfc, 0xff, 0xf0, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 
 32     0x01, 0xf1, 0xe0, 0x70, 0x3f, 0xfc, 0xf8, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 
 33     0x00, 0xf1, 0xe1, 0xf8, 0x3f, 0xfc, 0xf8, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 
 34     0x00, 0xf1, 0xe1, 0xff, 0xff, 0xfc, 0xf8, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 
 35     0x00, 0xf1, 0xe1, 0xff, 0xff, 0xfc, 0xf8, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 
 36     0x00, 0xf1, 0xc1, 0xff, 0xff, 0xfc, 0xf8, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 
 37     0x00, 0xf1, 0xe1, 0xe0, 0x07, 0xfc, 0xf8, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 
 38     0x7f, 0xf1, 0xe1, 0xe0, 0x01, 0xfc, 0xff, 0xf0, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 
 39     0xff, 0xf1, 0xe1, 0xe0, 0x00, 0xfc, 0xff, 0xf0, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 
 40     0xff, 0xf1, 0xe0, 0xe3, 0xf8, 0x7c, 0xff, 0xf0, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 
 41     0x7f, 0xf1, 0xe0, 0x63, 0xfc, 0x7c, 0xff, 0xf0, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 
 42     0x3f, 0xf1, 0xf0, 0x23, 0xfc, 0x3c, 0xff, 0xe0, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 
 43     0x00, 0xf1, 0xf8, 0x23, 0xfc, 0x3c, 0xf8, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 
 44     0x00, 0xf1, 0xff, 0x63, 0xfc, 0x3c, 0xf8, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 
 45     0x00, 0xf1, 0xff, 0xe3, 0xfc, 0x3c, 0xf8, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 
 46     0x00, 0xf1, 0xff, 0xe3, 0xfc, 0x7c, 0xf8, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 
 47     0x00, 0xf1, 0xff, 0xe3, 0xf8, 0x7c, 0xf8, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 
 48     0x7f, 0xf1, 0xff, 0xe1, 0xf0, 0x7c, 0xff, 0xe0, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 
 49     0xff, 0xf1, 0xff, 0xe0, 0x00, 0xfc, 0xff, 0xf0, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 
 50     0xff, 0xf1, 0xff, 0xe0, 0x03, 0xfc, 0xff, 0xf0, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 
 51     0xff, 0xf1, 0xff, 0xe0, 0x1f, 0xfc, 0xff, 0xf0, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 
 52     0x7f, 0xf1, 0xff, 0xff, 0xff, 0xfc, 0xff, 0xe0, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 
 53     0x00, 0xf1, 0xff, 0xff, 0xff, 0xf8, 0xf0, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 
 54     0x00, 0xf0, 0xff, 0xff, 0xff, 0xf8, 0xf0, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 
 55     0x00, 0x78, 0x7f, 0xff, 0xff, 0xf0, 0xf0, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 
 56     0x00, 0x7c, 0x1f, 0xff, 0xff, 0xc1, 0xf0, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 
 57     0x00, 0x3c, 0x00, 0x00, 0x00, 0x03, 0xe0, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 
 58     0x00, 0x3f, 0x00, 0x00, 0x00, 0x0f, 0xc0, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 
 59     0x00, 0x1f, 0xff, 0xff, 0xff, 0xff, 0xc0, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 
 60     0x00, 0x0f, 0xff, 0xff, 0xff, 0xff, 0x80, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 
 61     0x00, 0x07, 0xff, 0xff, 0xff, 0xfe, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 
 62     0x00, 0x01, 0xff, 0xff, 0xff, 0xf8, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 
 63     0x00, 0x00, 0x3e, 0x1f, 0x83, 0xe0, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 
 64     0x00, 0x00, 0x3e, 0x0f, 0x83, 0xe0, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 
 65     0x00, 0x00, 0x3e, 0x0f, 0x83, 0xe0, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 
 66     0x00, 0x00, 0x3e, 0x0f, 0x83, 0xe0, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 
 67     0x00, 0x00, 0x3e, 0x0f, 0x83, 0xe0, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 
 68     0x00, 0x00, 0x3e, 0x0f, 0x83, 0xe0, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 
 69     0x00, 0x00, 0x3c, 0x0f, 0x83, 0xe0, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 
 70     0x00, 0x00, 0x3c, 0x0f, 0x01, 0xc0, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 
 71     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 
 72     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
 73   };
 74   const char pieces_S_l[2][2][4] = {{
 75                                       {0, 0, 1, 1}, {0, 1, 1, 2}
 76                                     },
 77                                     {
 78                                       {0, 1, 1, 2}, {1, 1, 0, 0}
 79                                     }};
 80   const char pieces_S_r[2][2][4]{{
 81                                     {1, 1, 0, 0}, {0, 1, 1, 2}
 82                                   },
 83                                   {
 84                                     {0, 1, 1, 2}, {0, 0, 1, 1}
 85                                   }};                            
 86   const char pieces_L_l[4][2][4] = {{
 87                                     {0, 0, 0, 1}, {0, 1, 2, 2}
 88                                   },
 89                                   {
 90                                     {0, 1, 2, 2}, {1, 1, 1, 0}
 91                                   },
 92                                   {
 93                                     {0, 1, 1, 1}, {0, 0, 1, 2}
 94                                   },
 95                                   {
 96                                     {0, 0, 1, 2}, {1, 0, 0, 0}
 97                                   }};
 98   const char pieces_Sq[1][2][4] = {{
 99                                     {0, 1, 0, 1}, {0, 0, 1, 1}
100                                   }};
101   const char pieces_T[4][2][4] = {{
102                                     {0, 0, 1, 0},{0, 1, 1, 2}
103                                   },
104                                   {
105                                     {0, 1, 1, 2},{1, 0, 1, 1}
106                                   },
107                                   {
108                                     {1, 0, 1, 1},{0, 1, 1, 2}
109                                   },
110                                   {
111                                     {0, 1, 1, 2},{0, 0, 1, 0}
112                                   }};
113   const char pieces_l[2][2][4] = {{
114                                     {0, 1, 2, 3}, {0, 0, 0, 0}
115                                   },
116                                   {
117                                     {0, 0, 0, 0}, {0, 1, 2, 3}
118                                   }};
119   const short MARGIN_TOP = 19;
120   const short MARGIN_LEFT = 3;
121   const short SIZE = 5;
122   const short TYPES = 6;
123   #define SPEAKER_PIN 3
124   const int MELODY_LENGTH = 10;
125   const int MELODY_NOTES[MELODY_LENGTH] = {262, 294, 330, 262};
126   const int MELODY_DURATIONS[MELODY_LENGTH] = {500, 500, 500, 500};
127   int click[] = { 1047 };
128   int click_duration[] = { 100 };
129   int erase[] = { 2093 };
130   int erase_duration[] = { 100 };
131   word currentType, nextType, rotation;
132   short pieceX, pieceY;
133   short piece[2][4];
134   int interval = 20, score;
135   long timer, delayer;
136   boolean grid[10][18];
137   boolean b1, b2, b3;
138   int left=9;
139   int right=11;
140   int change=10;
141   int speed=12;
142   void checkLines(){
143     boolean full;
144     for(short y = 17; y >= 0; y--){
145       full = true;
146       for(short x = 0; x < 10; x++){
147         full = full && grid[x][y];
148       }
149       if(full){
150         breakLine(y);
151         y++;
152       }
153     }
154   }
155   void breakLine(short line){
156       tone(SPEAKER_PIN, erase[0], 1000 / erase_duration[0]);  
157       delay(100);
158       noTone(SPEAKER_PIN);
159     for(short y = line; y >= 0; y--){
160       for(short x = 0; x < 10; x++){
161         grid[x][y] = grid[x][y-1];
162       }
163     }
164     for(short x = 0; x < 10; x++){
165       grid[x][0] = 0;
166     }
167     display.invertDisplay(true);
168     delay(50);
169     display.invertDisplay(false);
170     score += 10;
171   }
172   void refresh(){
173       display.clearDisplay();
174       drawLayout();
175       drawGrid();
176       drawPiece(currentType, 0, pieceX, pieceY);
177       display.display();
178   }
179   void drawGrid(){
180     for(short x = 0; x < 10; x++)
181       for(short y = 0; y < 18; y++)
182         if(grid[x][y])
183           display.fillRect(MARGIN_LEFT + (SIZE + 1)*x, MARGIN_TOP + (SIZE + 1)*y, SIZE, SIZE, WHITE);
184   }
185   boolean nextHorizontalCollision(short piece[2][4], int amount){
186     for(short i = 0; i < 4; i++){
187       short newX = pieceX + piece[0][i] + amount;
188       if(newX > 9 || newX < 0 || grid[newX][pieceY + piece[1][i]])
189         return true;
190     }
191     return false;
192   }
193   boolean nextCollision(){
194     for(short i = 0; i < 4; i++){
195       short y = pieceY + piece[1][i] + 1;
196       short x = pieceX + piece[0][i];
197       if(y > 17 || grid[x][y])
198         return true;
199     }
200     return false;
201   }
202   void generate(){
203     currentType = nextType;
204     nextType = random(TYPES);
205     if(currentType != 5)
206       pieceX = random(9);
207     else
208       pieceX = random(7);
209     pieceY = 0;
210     rotation = 0;
211     copyPiece(piece, currentType, rotation);
212   }
213   void drawPiece(short type, short rotation, short x, short y){
214     for(short i = 0; i < 4; i++)
215       display.fillRect(MARGIN_LEFT + (SIZE + 1)*(x + piece[0][i]), MARGIN_TOP + (SIZE + 1)*(y + piece[1][i]), SIZE, SIZE, WHITE);
216   }
217   void drawNextPiece(){
218     short nPiece[2][4];
219     copyPiece(nPiece, nextType, 0);
220     for(short i = 0; i < 4; i++)
221       display.fillRect(50 + 3*nPiece[0][i], 4 + 3*nPiece[1][i], 2, 2, WHITE);
222   }
223   void copyPiece(short piece[2][4], short type, short rotation){
224     switch(type){
225     case 0: //L_l
226       for(short i = 0; i < 4; i++){
227         piece[0][i] = pieces_L_l[rotation][0][i];
228         piece[1][i] = pieces_L_l[rotation][1][i];
229       }
230       break;
231     case 1: //S_l
232       for(short i = 0; i < 4; i++){
233         piece[0][i] = pieces_S_l[rotation][0][i];
234         piece[1][i] = pieces_S_l[rotation][1][i];
235       }
236       break;
237     case 2: //S_r
238       for(short i = 0; i < 4; i++){
239         piece[0][i] = pieces_S_r[rotation][0][i];
240         piece[1][i] = pieces_S_r[rotation][1][i];
241       }
242       break;
243     case 3: //Sq
244       for(short i = 0; i < 4; i++){
245         piece[0][i] = pieces_Sq[0][0][i];
246         piece[1][i] = pieces_Sq[0][1][i];
247       }
248       break;
249       case 4: //T
250       for(short i = 0; i < 4; i++){
251         piece[0][i] = pieces_T[rotation][0][i];
252         piece[1][i] = pieces_T[rotation][1][i];
253       }
254       break;
255       case 5: //l
256       for(short i = 0; i < 4; i++){
257         piece[0][i] = pieces_l[rotation][0][i];
258         piece[1][i] = pieces_l[rotation][1][i];
259       }
260       break;
261     }
262   }
263   short getMaxRotation(short type){
264     if(type == 1 || type == 2 || type == 5)
265       return 2;
266     else if(type == 0 || type == 4)
267       return 4;
268     else if(type == 3)
269       return 1;
270     else 
271       return 0;
272   }
273   boolean canRotate(short rotation){
274     short piece[2][4];
275     copyPiece(piece, currentType, rotation);
276     return !nextHorizontalCollision(piece, 0);
277   }
278   void drawLayout(){
279     display.drawLine(0, 15, WIDTH, 15, WHITE);
280     display.drawRect(0, 0, WIDTH, HEIGHT, WHITE);
281     drawNextPiece();
282     char text[6];
283     itoa(score, text, 10);
284     drawText(text, getNumberLength(score), 7, 4);
285   }
286   short getNumberLength(int n){
287     short counter = 1;
288     while(n >= 10){
289       n /= 10;
290       counter++;
291     }
292     return counter;
293   }
294   void drawText(char text[], short length, int x, int y){
295     display.setTextSize(1);      // Normal 1:1 pixel scale
296     display.setTextColor(WHITE); // Draw white text
297     display.setCursor(x, y);     // Start at top-left corner
298     display.cp437(true);         // Use full 256 char 'Code Page 437' font
299     for(short i = 0; i < length; i++)
300       display.write(text[i]);
301   }
302   void setup() {
303     pinMode(left, INPUT_PULLUP);
304     pinMode(right, INPUT_PULLUP);
305     pinMode(change, INPUT_PULLUP);
306     pinMode(speed, INPUT_PULLUP);
307     pinMode(SPEAKER_PIN, OUTPUT);
308     Serial.begin(9600);
309     // SSD1306_SWITCHCAPVCC = generate display voltage from 3.3V internally
310     if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) { // Address 0x3D for 128x64
311       Serial.println(F("SSD1306 allocation failed"));
312       for(;;); // Don't proceed, loop forever
313     }
314     display.setRotation(1);
315     display.clearDisplay();
316     display.drawBitmap(3, 23, mantex_logo, 64, 82,  WHITE);
317     display.display();
318     delay(2000);
319     display.clearDisplay();
320     drawLayout(); 
321     display.display();    
322     randomSeed(analogRead(0));
323     nextType = random(TYPES);
324     generate();
325     timer = millis();
326   }
327   void loop() {
328     if(millis() - timer > interval){
329       checkLines();
330       refresh();
331       if(nextCollision()){
332         for(short i = 0; i < 4; i++)
333           grid[pieceX + piece[0][i]][pieceY + piece[1][i]] = 1;
334         generate();
335       }else
336         pieceY++;  
337       timer = millis();
338     }
339     if(!digitalRead(left)){
340       tone(SPEAKER_PIN, click[0], 1000 / click_duration[0]);
341       delay(100);
342       noTone(SPEAKER_PIN);
343       if(b1){
344         if(!nextHorizontalCollision(piece, -1)){
345           pieceX--;
346           refresh();
347         }
348         b1 = false;
349       }
350     }else{ 
351       b1 = true;
352     }
353     if(!digitalRead(right)){
354       tone(SPEAKER_PIN, click[0], 1000 / click_duration[0]);
355       delay(100);
356       noTone(SPEAKER_PIN);
357       if(b2){
358         if(!nextHorizontalCollision(piece, 1)){
359           pieceX++;
360           refresh();
361         }
362         b2 = false;
363       }
364     }else{ 
365       b2 = true;
366     }
367     if(!digitalRead(speed)){
368       interval = 20;
369     }else{
370       interval = 400;
371       }
372     if(!digitalRead(change)){
373       tone(SPEAKER_PIN, click[0], 1000 / click_duration[0]);
374       delay(100);
375       noTone(SPEAKER_PIN);
376       if(b3){
377         if(rotation == getMaxRotation(currentType) - 1 && canRotate(0)){
378           rotation = 0;
379         }else if(canRotate(rotation + 1)){
380           rotation++;
381         }     
382         copyPiece(piece, currentType, rotation);
383         refresh(); 
384         b3 = false;
385         delayer = millis();
386       }
387     } else if(millis() - delayer > 50){ 
388       b3 = true;
389     }}

reste à faire

une boite en decoupe laser ou en 3D