Pouvez-vous me dire pourqoi ce programme ne fonctionne pas??
/* 29 mar 09 */
/* Text scrolling with a 5x7 led matrix.
/* ATTENTION: Copy Pattern.h file in ./hardware/libraries/Pattern/ directory */
#include <avr/pgmspace.h>
#include <Pattern.h>
#define DELAY 100
int dataIn = 2;
int load = 4;
int clock = 3;
int matrix[7][5]={{0,0,0,0,0},{0,0,0,0,0},{0,0,0,0,0},{0,0,0,0,0},{0,0,0,0,0},{0,0,0,0,0},{0,0,0,0,0},};
int e = 0; // just a varialble
// define max7219 registers
byte max7219_reg_noop = 0x00;
byte max7219_reg_digit0 = 0x01;
byte max7219_reg_digit1 = 0x02;
byte max7219_reg_digit2 = 0x03;
byte max7219_reg_digit3 = 0x04;
byte max7219_reg_digit4 = 0x05;
byte max7219_reg_digit5 = 0x06;
byte max7219_reg_digit6 = 0x07;
byte max7219_reg_digit7 = 0x08;
byte max7219_reg_decodeMode = 0x09;
byte max7219_reg_intensity = 0x0a;
byte max7219_reg_scanLimit = 0x0b;
byte max7219_reg_shutdown = 0x0c;
byte max7219_reg_displayTest = 0x0f;
void putByte(byte data) {
byte i = 8;
byte mask;
while(i > 0) {
mask = 0x01 << (i - 1); // get bitmask
digitalWrite( clock, LOW); // tick
if (data & mask){ // choose bit
digitalWrite(dataIn, HIGH);// send 1
}else{
digitalWrite(dataIn, LOW); // send 0
}
digitalWrite(clock, HIGH); // tock
--i; // move to lesser bit
}
}
void sendToMax( byte reg, byte value) {
digitalWrite(load, LOW); // begin
putByte(reg); // specify register
putByte(value);
digitalWrite(load, LOW); // and load da shit
digitalWrite(load,HIGH);
}
void setup () {
//wired up to max7219
pinMode(dataIn, OUTPUT);
pinMode(clock, OUTPUT);
pinMode(load, OUTPUT);
//initiation of the max 7219
sendToMax(max7219_reg_decodeMode, 0x00); // not using digits
sendToMax(max7219_reg_scanLimit, 0x06); //scan rows 1 2 3 4 5 6 7
sendToMax(max7219_reg_shutdown, 0x01); // not in shutdown mode
sendToMax(max7219_reg_displayTest, 0x00); // no display test
sendToMax(max7219_reg_intensity, 0xf); // range: 0x00 to 0x0f
for (e=1; e<=7; e++) { // empty registers, turn all LEDs off
sendToMax(e,0);
}
}
//I don't know why pow function doesn't work correctly.
//So i prefer to write my personal version of this.
int power(int base, int ex){
int i=1;
int tot=1;
if(i==0) return(1);
else{
while(i<=ex){
tot=tot*base;
i++;
}
return(tot);
}
}
void lightOn(){
int i,j,k;
//light on matrix
for(i=0;i<7;i++){
k=0;
for(j=0;j<5;j++){
if(matrix[i][j]==1) k=k+power(2,j);
}
sendToMax(i+1,k);
}
}
void scrollChar(const int pattern[7][5]){
int i,j,k=0;
while(k<5) //column of pattern
{
//shift rigidly columns from right to left
for(j=0;j<4;j++){ //column
for(i=0;i<7;i++){ //row
matrix[i][j]= matrix[i][j+1];
}
}
//queue k-th column of pattern
for(i=0;i<7;i++){ //row
matrix[i][4]=pgm_read_byte(&((pattern)[i][k]));
}
lightOn();
delay(DELAY);
k++;
}//end while
insertSpace();
}
//insert a space (two column filled with zeros) beetween two chars
void insertSpace(){
int i,j,k=0;
while(k<2) //queue two column of zero
{
//shift rigidly columns from right to left
for(j=0;j<4;j++){ //column
for(i=0;i<7;i++){ //row
matrix[i][j]= matrix[i][j+1];
}
}
//queue two column filled with zeros
for(i=0;i<7;i++){ //row
matrix[i][4]=0;
}
lightOn();
delay(DELAY);
k++;
}//end while
}
void scrollString(char * s){
int i=0;
while (s[i])
{
//symbols and letters
if(s[i]==' ')
scrollChar(PATTERN_BLANK);
if(s[i]=='A')
scrollChar(PATTERN_A);
if(s[i]=='B')
scrollChar(PATTERN_B);
if(s[i]=='C')
scrollChar(PATTERN_C);
if(s[i]=='D')
scrollChar(PATTERN_D);
if(s[i]=='E')
scrollChar(PATTERN_E);
if(s[i]=='F')
scrollChar(PATTERN_F);
if(s[i]=='G')
i++;
}//end while
}
void loop () {
scrollString("ABCDEFGHIJKLMNOPQRSTUVWXYZ 0123456789"); //use capital letters
}
Avec cette librairie
/* Source: http://ericlathrop.com/electronics/LedGrid.php */
/*SYMBOLS*/
const int PATTERN_BLANK [7][5] PROGMEM = {
{ 0, 0, 0, 0, 0 },
{ 0, 0, 0, 0, 0 },
{ 0, 0, 0, 0, 0 },
{ 0, 0, 0, 0, 0 },
{ 0, 0, 0, 0, 0 },
{ 0, 0, 0, 0, 0 },
{ 0, 0, 0, 0, 0 },
};
const int PATTERN_SOLID [7][5] PROGMEM = {
{ 1, 1, 1, 1, 1 },
{ 1, 1, 1, 1, 1 },
{ 1, 1, 1, 1, 1 },
{ 1, 1, 1, 1, 1 },
{ 1, 1, 1, 1, 1 },
{ 1, 1, 1, 1, 1 },
{ 1, 1, 1, 1, 1 },
};
const int PATTERN_DARWINIAN [7][5] PROGMEM = {
{ 0, 0, 1, 0, 0 },
{ 1, 1, 1, 1, 1 },
{ 0, 0, 1, 0, 0 },
{ 0, 0, 1, 0, 0 },
{ 0, 1, 1, 1, 0 },
{ 0, 1, 0, 1, 0 },
{ 0, 1, 0, 1, 0 },
};
const int PATTERN_HEART [7][5] PROGMEM = {
{ 0, 0, 0, 0, 0 },
{ 0, 1, 0, 1, 0 },
{ 1, 1, 1, 1, 1 },
{ 1, 1, 1, 1, 1 },
{ 0, 1, 1, 1, 0 },
{ 0, 1, 1, 1, 0 },
{ 0, 0, 1, 0, 0 },
};
const int PATTERN_EXCLAMATION [7][5] PROGMEM = {
{ 1, 1, 0, 1, 1 },
{ 1, 1, 0, 1, 1 },
{ 1, 1, 0, 1, 1 },
{ 1, 1, 0, 1, 1 },
{ 0, 0, 0, 0, 0 },
{ 1, 1, 0, 1, 1 },
{ 1, 1, 0, 1, 1 },
};
/*LETTERS*/
const int * PATTERN_A PROGMEM = {
{ 0, 0, 1, 0, 0 },
{ 0, 1, 0, 1, 0 },
{ 1, 0, 0, 0, 1 },
{ 1, 0, 0, 0, 1 },
{ 1, 1, 1, 1, 1 },
{ 1, 0, 0, 0, 1 },
{ 1, 0, 0, 0, 1 },
};
const int PATTERN_B [7][5] PROGMEM = {
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