Table des matières

Afficheur défillant à matrices de 8*8 LED

C'est un petit test fait à l'arrache mais avec brio et toute berzingue par Remy et Josselin.

Du coup on a commandé une palanqué de resistances pour les LEDs. On va aussi tenter de soigner la police de caractères, finir le montage sur breakboard et lancer le design que qqch bien packagé avec un zoli PCB.

Le point de départ

lien : Scrolling sur matrice à LED sur le site blogule.net . Merci M. Blogule.net !

Le premier jet en image

Le premier jet en code

#include <TimerOne.h>
 
unsigned char col[8]={2,3,4,5,6,7,8,9}; // pins for columns
unsigned char row[8]={10,11,12,13,14,15,16,17}; // pins for rows
unsigned char refreshRow=0; // set index
unsigned char lastRefreshRow=7; // for the refresh
unsigned int scrollIndex=0; // render starting column in bigMatrix
bool matrix [8] [8]; // image of the screen
bool bigMatrix [112] [8]; // image of complete message
 
// character set
unsigned char carSp[8]={0,0,0,0,0,0,0,0}; // Space
unsigned char carEx[8]={24,24,24,24,24,0,24,0}; // !
unsigned char carH[8]={102,102,102,126,102,102,102,0}; // H
unsigned char care[8]={0,0,60,102,126,96,60,0}; // e
unsigned char carl[8]={56,24,24,24,24,24,60,0}; // l
unsigned char caro[8]={0,0,60,102,102,102,60,0}; // o
unsigned char carw[8]={0,0,198,214,214,254,108,0}; // w
unsigned char carr[8]={0,0,216,108,96,96,240,0}; // r
unsigned char card[8]={28,12,124,204,204,204,118,0}; // d
unsigned char carF[8]={254,98,104,120,104,96,120,0}; // F
unsigned char cara[8]={0,0,120,12,124,204,118,0}; // a
unsigned char carb[8]={224,224,124,102,102,102,188,0}; // b
unsigned char car5[8]={126,98,96,60,12,108,60,0}; // 5
 
// fablab_web_5
 
 
void setup() {
Timer1.initialize(2500); // initialize the timer to refresh the screen (in microsecond)
test_matrix(10); // do a matrix led test
 
// write message " Hello world !" in BigMatrix table
char2BigMatrix(carSp,0); // [Space]
char2BigMatrix(carF,8); // F
char2BigMatrix(cara,16); // a
char2BigMatrix(carb,24); // b
char2BigMatrix(carl,32); // l
char2BigMatrix(cara,40); // a
char2BigMatrix(carb,48); //b
char2BigMatrix(carSp,56); // [Space]
char2BigMatrix(carw,64); // w
char2BigMatrix(care,72); // e
char2BigMatrix(carb,80); // b
char2BigMatrix(carSp,88); // [Space]
char2BigMatrix(car5,96); // 5
char2BigMatrix(carEx,104); // !(
Timer1.attachInterrupt(refresh_matrix); // rely interruption to refresh_matrix function and start the timer
 
 
}
 
void loop() {
  // put your main code here, to run repeatedly:
bigMatrice2matrice(scrollIndex); // take 8 columns of bigMatrix and send them to matrix
scrollIndex+=1; // shift one column for next call
if(scrollIndex>111){ // if end of big matrix reached
  scrollIndex=0; // return to start
}
delay(100); // delay in ms between one column scrolling
}
 
void init_matrix(){ // set power for each rows and columns
  for (int i=0;i<8;i++){
  pinMode(col[i],OUTPUT);
  digitalWrite(col[i],HIGH);
  pinMode(row[i],OUTPUT);
  digitalWrite(row[i],LOW);
}
}
 
void test_matrix(int lasting){ // light up each led alternatively
    init_matrix();
    for (int y=0;y<8;y++){
  digitalWrite(row[y],HIGH);
  for (int x=0;x<8;x++){
    digitalWrite(col[x],LOW);
    delay(lasting);
    digitalWrite(col[x],HIGH);
  }
  digitalWrite(row[y],LOW);
  }
}
 
void char2BigMatrix(unsigned char character[8],unsigned char colInsert){ // insert a character in specified column of bigMatrix
  for(int x=colInsert;x<colInsert+8;x++){
    for(int y=0;y<8;y++){
      bigMatrix[x][y]=!(bitRead(character[y],7-(x-colInsert)));
    }
  }
}
 
void refresh_matrix(){ // draw matrix state on physical leds
  digitalWrite(row[lastRefreshRow],LOW);
  for (int i=0;i<8;i++){
    digitalWrite(col[i],matrix[i][refreshRow]);
  }
  digitalWrite(row[refreshRow],HIGH);
 refreshRow++;
 if (refreshRow>7){
 refreshRow=0;
 lastRefreshRow=7; 
 }else{
  lastRefreshRow=refreshRow-1;
 }
}
 
void bigMatrice2matrice(unsigned int colStart){ // copy part of bigMatrix to matrix
  for(int x=0;x<8;x++){
    for(int y=0;y<8;y++){
      if (x+colStart>111){
        colStart=-x;
      }
      matrix[x][y]=bigMatrix[x+colStart][y];
    }
  }
}