Hello arduino community, I have made an led matrix code that works very well but i'm not really sure about how to get it to scroll. The only thing i could think of would be to use the bitshift function but i'm not really sure how to implement that into the code. If anyone could just guide me on how to go about making the matrix scroll i would be very appreciative.
Thanks in advance
-Chris
Here's my code
/* Hopefully the last LED matrix code I ever make
BY: Chris Yambo
*/
int CPR = 8; // clock pin row
int DPR = 10; // data pin row
int CPC = 11; // clock pin column
int DPC = 12; // data pin column
int LP = 9; // combined the latch pins so theres only one
byte RA[] = { B10000000, B01000000, B00100000, B00010000, B00001000,}; // way to address rows individually
byte letters[26][5] = {
{B10001000, B10001000, B11111000, B10001000, B11111000}, // A
{B11111000, B10001000, B11110000, B10001000, B11111000}, // B
{B11111000, B10001000, B10000000, B10001000, B11111000}, // C
{B11110000, B10001000, B10001000, B10001000, B11110000}, // D
{B11111000, B10000000, B11110000, B10000000, B11111000}, // E
{B10000000, B10000000, B11110000, B10000000, B11111000}, // F
{B11111000, B10001000, B10011000, B10000000, B11111000}, // G
{B10001000, B10001000, B11111000, B10001000, B10001000}, // H
{B01000000, B01000000, B01000000, B01000000, B01000000}, // I
{B11111000, B10001000, B00001000, B00001000, B00001000}, // J
{B10001000, B10010000, B11100000, B10010000, B10001000}, // K
{B11111000, B10000000, B10000000, B10000000, B10000000}, // L
{B10101000, B10101000, B10101000, B10101000, B11011000}, // M
{B10001000, B10011000, B10101000, B11001000, B10001000}, // N
{B11111000, B10001000, B10001000, B10001000, B11111000}, // O
{B10000000, B10000000, B11111000, B10001000, B11111000}, // P
{B11111000, B10011000, B10001000, B10001000, B11111000}, // Q
{B10001000, B10010000, B11111000, B10001000, B11111000}, // R
{B11111000, B00001000, B11111000, B10000000, B11111000}, // S
{B00100000, B00100000, B00100000, B00100000, B11111000}, // T
{B11111000, B10001000, B10001000, B10001000, B10001000}, // U
{B00100000, B01010000, B10001000, B10001000, B10001000}, // V
{B11011000, B10101000, B10101000, B10101000, B10101000}, // W
{B10001000, B01010000, B00100000, B01010000, B10001000}, // X
{B11111000, B00001000, B11111000, B10001000, B10001000}, // Y
{B11111000, B01000000, B00100000, B00010000, B11111000}, // Z
};
byte space[1][5] = {
{B00000000, B00000000, B00000000, B00000000, B00000000}, // Space
};
int letdelay = 650; // delay between letters
String message = "HELLO WORLD "; //----------------------------------------------------------------WHATS GOING TO BE DISPLAYED Most important part of code-----------------------------------------------------
int msglength = message.length();
void setup() {
pinMode(CPR, OUTPUT);
pinMode(DPR, OUTPUT);
pinMode(CPC, OUTPUT); // setting pins as outputs
pinMode(DPC, OUTPUT);
pinMode(LP, OUTPUT);
Serial.begin(9600);
}
void loop(){
show();
}
void show(){
for(int j=0; j<msglength; j++) // counts up to the number of characters in the message
{
int character = message.charAt(j); // puts the letter of the whatever character the counter is on into an integer called character
unsigned long start = millis(); //Begin timing the animation
while(start + letdelay > millis()) // display each letter for duraton period
{
if(character == 32) // if the character is a space display a zero. If you dont do this it glitches on spaces
{
digitalWrite(LP, LOW); // PUT LATCH PIN LOW
shiftOut(DPR, CPR, LSBFIRST, 0); //This whole if statement is just to make sure when theres a zero
shiftOut(DPC, CPC, LSBFIRST, 0); //The shift registers get zeros shifted in
digitalWrite(LP, HIGH); // Put latch pin high displayig everything shifted in
delay(2);
}
else // this displays letters
{
for(int j=0; j<5; j++) // starts a count from 0- 4 and makes it j
{
int y = character - 'A'; //the int character is in ascii which makes a the number 65 of the array. to make it number 0 of the array we subtract A which is 65 from whatever letter is going to be shown
digitalWrite(LP, LOW); // PUT LATCH PIN LOW
shiftOut(DPR, CPR, LSBFIRST, RA[j]); // shift out ruw number 'J'
shiftOut(DPC, CPC, LSBFIRST, letters[y][j]); //SHIFT OUT COULMN 'J' FROM THE ARRAY OF WHATEVER CHARACTER WE CHOSE TO SHOW Y IS THE LETTER ITS DOING
digitalWrite(LP, HIGH); // Put latch pin high displayig everything shifted in
delay(2);
}
}
}
if(message.charAt(j + 1) == character) //this is for words with two of the same letter next to each other like the word hello. it puts a small space between the two letters that are the same
{
digitalWrite(LP, LOW); // PUT LATCH PIN LOW
shiftOut(DPR, CPR, LSBFIRST, 0); //This whole if statement is just to make sure when theres a zero
shiftOut(DPC, CPC, LSBFIRST, 0); //The shift registers get zeros shifted in
digitalWrite(LP, HIGH); // Put latch pin high displayig everything shifted in
delay(100);
}
}
}