Code : Tout sélectionner
/**********************************************************************
Filename : LED Matrix Display
Description : Use 2 74HC595 to drive the LED Matrix display
Auther : www.freenove.com
Modification: 2024/06/19
**********************************************************************/
int latchPin = 39; // Pin connected to ST_CP of 74HC595(Pin12)
int clockPin = 40; // Pin connected to SH_CP of 74HC595(Pin11)
int dataPin = 38; // Pin connected to DS of 74HC595(Pin14)
// Define the pattern data for a smiling face
const int smilingFace[] = { //"^ⅴ^"
0x1C, 0x22, 0x51, 0x45, 0x45, 0x51, 0x22, 0x14
};
// Define the data of numbers and letters, and save them in flash area
const int data[] PROGMEM = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // " "
0x00, 0x00, 0x21, 0x7F, 0x01, 0x00, 0x00, 0x00, // "1"
0x00, 0x00, 0x23, 0x45, 0x49, 0x31, 0x00, 0x00, // "2"
0x00, 0x00, 0x22, 0x49, 0x49, 0x36, 0x00, 0x00, // "3"
0x00, 0x00, 0x0E, 0x32, 0x7F, 0x02, 0x00, 0x00, // "4"
0x00, 0x00, 0x79, 0x49, 0x49, 0x46, 0x00, 0x00, // "5"
0x00, 0x00, 0x3E, 0x49, 0x49, 0x26, 0x00, 0x00, // "6"
0x00, 0x00, 0x60, 0x47, 0x48, 0x70, 0x00, 0x00, // "7"
0x00, 0x00, 0x36, 0x49, 0x49, 0x36, 0x00, 0x00, // "8"
0x00, 0x00, 0x32, 0x49, 0x49, 0x3E, 0x00, 0x00, // "9"
0x00, 0x00, 0x3E, 0x41, 0x41, 0x3E, 0x00, 0x00, // "0"
0x00, 0x00, 0x3F, 0x44, 0x44, 0x3F, 0x00, 0x00, // "A"
0x00, 0x00, 0x7F, 0x49, 0x49, 0x36, 0x00, 0x00, // "B"
0x00, 0x00, 0x3E, 0x41, 0x41, 0x22, 0x00, 0x00, // "C"
0x00, 0x00, 0x7F, 0x41, 0x41, 0x3E, 0x00, 0x00, // "D"
0x00, 0x00, 0x7F, 0x49, 0x49, 0x41, 0x00, 0x00, // "E"
0x00, 0x00, 0x7F, 0x48, 0x48, 0x40, 0x00, 0x00 // "F"
};
void setup() {
// set pins to output
pinMode(latchPin, OUTPUT);
pinMode(clockPin, OUTPUT);
pinMode(dataPin, OUTPUT);
}
void loop() {
// Define a one-byte variable (8 bits) which is used to represent the selected state of 8 column.
int cols;
// Display the static smiling pattern
for (int i = 0; i < 8; i++) { // afficher les données de 8 colonnes en parcourant
matrixRowsVal(smilingFace[i]);// afficher les données de cette colonne
matrixColsVal(~cols);
delay(1);
}
// Display the dynamic patterns of numbers and letters
for (int i = 0; i < 128; i++) {
for (int k = 0; k < 10; k++) { // repeat image of each frame 10 times.
cols = 0x01; // Assign binary 00000001. Means the first column is selected.
for (int j = i; j < 8 + i; j++) { // display image of each frame
matrixRowsVal(pgm_read_word_near(data + j));// display the data in this column
matrixColsVal(~cols); // select this column
delay(1); // display them for a period of time
matrixRowsVal(0x00); // close the data of this column
cols <<= 1; // shift"cols" 1 bit left to select the next column
}
}
}
}
void matrixRowsVal(int value) {
// make latchPin output low level
digitalWrite(latchPin, LOW);
// Send serial data to 74HC595
shiftOut(dataPin, clockPin, LSBFIRST, value);
// make latchPin output high level, then 74HC595 will update the data to parallel output
digitalWrite(latchPin, HIGH);
}
void matrixColsVal(int value) {
// make latchPin output low level
digitalWrite(latchPin, LOW);
// Send serial data to 74HC595
shiftOut(dataPin, clockPin, MSBFIRST, value);
// make latchPin output high level, then 74HC595 will update the data to parallel output
digitalWrite(latchPin, HIGH);
}
Cela a été une galère pour arriver à un semblant de résultat positif. J'ai refait le câblage plusieurs fois et toujours des mauvais contacts ici et là. J'ai gardé le meilleur mais pas 100% top. Le breadboard est de très mauvaise qualité. J'ai contacté Freenove et la réponse a été qu'ils étaient conscient du soucis et en s'excusant me propose de renvoyer un breadboard gratuitement. Si c'est pour recevoir une pièce non fiable, ils peuvent se la garder.
En parcourant la totalité des exercices, celui publié ici est le seul avec autant de contacts.