Bonjour, je suis en train de concevoir un dispositif avec un Arduino Uno, un bouton et une matrice led 8x8 soudée sur un module MAX7219.

J'aimerais pouvoir charger différentes boucles animées sur l'arduino et passer de l'un à l'autre en pressant le bouton.

Je vous montre le schematics ainsi que le code que j'ai développé en m'appuyant sur un cours traitant des State Machine et des corrections qu'on m'a données mais qui n'ont pas forcément fonctionné (le code compile néanmoins) et ce que j'ai trouvé sur un [générateur de sprites pour LedMatrix](https://xantorohara.github.io) :

Pour le moment quand je charge le programme, je n'ai que mon state "default" qui se charge et qui boucle... le fait d'appuyer sur le bouton ne change rien.. avant tout ça j'étais arrivé à un point où mon bouton fonctionnait et permettait de passer d'un état à un autre mais il fallait appuyer avec un certain timing... et j'avais des glitch dans mes animations (surement du fait qu'elle ne comportent pas le même nombre de sprites)

Est-ce que quelqu'un qui s'y connaît avec les LedMatrix 8x8 pourrait m'éclairer?

Nom : Capture d’écran 2022-02-16 à 16.09.45.png
Affichages : 349
Taille : 145,7 Ko


Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
#include <LedControl.h>
#include <MD_MAX72xx.h>
 
 
//There will be 3 states, ONE, TWO, THREE, (+ one default called ZERO), each state is a sprite animation on the 8x8 LedMatrix,
//with the push of a button the states will go from one to an other
//Using a MAX7219
// pin 12 is connected to the DataIn
//pin 11 is connected to the CLK
//pin 10 is connected to LOAD
//pin 2 is connected to switch
#define button 2
 
 
LedControl display = LedControl(12, 11, 10, 1);
 
int state = 0;              //integrer to hold current state
int ButtonState = 0;        //take current button state
int LastButtonState = 0;    //take last button state
int ControlState = 0;       //take control unit status
 
int old = 0;                //integrer to hold last state
int buttonPoll = 0;         //integrer to hold button state
 
 
 
 
const uint64_t ZERO[] PROGMEM = {
  0x3c4281818181423c,
  0x003c424242423c00,
  0x0000182424180000,
  0x0000001818000000,
  0x0000182424180000,
  0x0018244242241800,
  0x003c424242423c00,
  0x3c4281818181423c,
  0x6681810000818166,
  0x8100000000000081,
  0x4281000000008142
};
const int ZERO_LEN = sizeof(ZERO) / 8;
 
 
const uint64_t ONE[] PROGMEM = {
  0x3c4201010101023c,
  0x3c0201010101423c,
  0x1c0201010181423c,
  0x0c0201018181423c,
  0x040201818181423c,
  0x000281818181423c,
  0x004081818181423c,
  0x204080818181423c,
  0x304080808181423c,
  0x384080808081423c,
  0x3c4080808080423c,
  0x3c4280808080403c,
  0x3c42818080804038,
  0x3c42818180804030,
  0x3c42818181804020,
  0x3c42818181814000,
  0x3c42818181810200,
  0x3c42818181010204,
  0x3c4281810101020c,
  0x3c4281010101021c
};
const int ONE_LEN = sizeof(ZERO) / 8;
 
const uint64_t TWO[] PROGMEM = {
  0x0c0e0c0800000000,
  0x0002070f00000000,
  0x000000000f070200,
  0x00000000080c0e0c,
  0x0000000010307030,
  0x00000000f0e04000,
  0x0040e0f000000000,
  0x3070301000000000
};
const int TWO_LEN = sizeof(ZERO) / 8;
 
const uint64_t THREE[] PROGMEM = {
  0x3c4299a5a599423c,
  0x0018244242241800,
  0x003c665a5a663c00
};
const int THREE_LEN = sizeof(ZERO) / 8;
 
void setup() {
 
  pinMode (button, INPUT);        //button set as input
  display.shutdown(0, false);
  /* Set the brightness to a medium values */
  display.setIntensity(0, 7);
  /* and clear the display */
  display.clearDisplay(0);
}
 
 
 
void displayImage(uint64_t image) {
  for (int i = 0; i < 8; i++) {
    byte row = (image >> i * 8) & 0xFF;
    for (int j = 0; j < 8; j++) {
      display.setLed(0, i, j, bitRead(row, j));
    }
  }
}
 
int i = 0;
void loop() {
  //debouncing routine to read button
  buttonPoll = digitalRead(button);                   //poll the state of button
  ButtonState;
  LastButtonState;
 
  if (ButtonState == LOW && LastButtonState == HIGH)
  { //check if it has been pressed
    ControlState = old + 1;                                   //increase state by 1
    i = 0;
    LastButtonState = ButtonState;
 
  }
 
  switch (state) {                         //react to button press & state
    case 1:                                // if state is 1
      //insert ONE
      /*wheel pattern */
      uint64_t one;
      memcpy_P(&one, &ONE[i], 8);
 
      displayImage(one);
      if (++i >= ONE_LEN ) {
        i = 0;
      }
 
 
      delay(100);
 
 
      old = state;
 
 
 
      break;
    case 2:
      uint64_t two;
      memcpy_P(&two, &TWO[i], 8);
 
      displayImage(two);
      if (++i >= TWO_LEN ) {
        i = 0;
      }
      delay(100);
 
 
      old = state;
 
 
 
      break;
    case 3:
      //insert THREE
      uint64_t three;
      memcpy_P(&three, &THREE[i], 8);
 
      displayImage(three);
      if (++i >= THREE_LEN ) {
        i = 0;
      }
      delay(100);
 
      old = state;
 
 
 
      break;
 
 
    default:
      //insert ZERO
      //if state is not 1,2,3
      uint64_t zero;
      memcpy_P(&zero, &ZERO[i], 8);
 
      displayImage(zero);
      if (++i >= ZERO_LEN ) {
        i = 0;
      }
      delay(100);
 
 
      old = 0;
 
 
 
      break;
 
 
 
 
  }
}
Je précise que je suis novice en Arduino mais que j'arrive à démêler pas mal de chose en regardant des sketchs et que j’espérais trouver plus de tutoriels ou de documentation concernant les Led à Matrice mais après plusieurs semaines à tourner en rond je bloque.. Je vois des projets bien plus compliqués fonctionner et des librairies qui regorgent de super effets (comme Parola) mais rien permettant d'incorporer proprement ses propres sprites/animations.