Hi, I need to complete a project by creating a programming code to let the led matrix display the required number from left to right when push button pressed from the first time and displaying another string character when the same push button pressed for second time. I can only figure out on how to make it scroll from right to left and using two different push button to change between (animation1) and (animation2). Could I get help with the same push button pressed for second time and the text scrolling from left to right?
int c[8] = {14,15,16,17,18,19,20,21};
int r[8] = {6,7,8,9,10,11,12,13};
const int but1 = 2;
const int but2 = 3;
int buttoncount = 0;
int but1State = 0;
int but2State = 0;
int but1Now;
int but2Now;
int value1;
int value2;
int matrix1[8][8] = {};
int matrix2[8][8] = {};
//Array variable for output
int position = 0;
long t = 0;
#define scrolltime 90
int all_num[8] [54] = {
{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,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,1,1,0,0,0,0,1,0,0,0,0,1,1,0,0,0,1,1,0,0,0,0,0,1,0,0,1,1,1,1,0,0,0,1,0,0,1,1,1,1,0,0,1,1,0,0,0,1,1,0,0,0},
{0,1,0,0,1,0,0,1,1,0,0,0,1,0,0,1,0,1,0,0,1,0,0,0,1,1,0,0,1,0,0,0,0,0,1,0,0,0,0,0,1,0,0,1,0,0,1,0,1,0,0,1,0,0},
{0,1,0,0,1,0,1,0,1,0,0,0,0,0,0,1,0,0,0,1,0,0,0,1,0,1,0,0,1,1,1,0,0,1,1,1,0,0,0,1,0,0,0,0,1,1,0,0,1,0,0,1,0,0},
{0,1,0,0,1,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,1,0,1,1,1,1,1,0,0,0,0,1,0,1,0,0,1,0,0,1,0,0,0,1,0,0,1,0,0,1,1,1,0,0},
{0,1,0,0,1,0,0,0,1,0,0,0,0,1,0,0,0,1,0,0,1,0,0,0,0,1,0,0,1,0,0,1,0,1,0,0,1,0,0,1,0,0,0,1,0,0,1,0,0,0,1,0,0,0},
{0,0,1,1,0,0,1,1,1,1,1,0,1,1,1,1,0,0,1,1,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,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
};
void setup() {
//Pin initialization
for (int i = 0; i<8; i++){
pinMode(r[i], OUTPUT);
pinMode(c[i], OUTPUT);
digitalWrite(c[i], LOW);
digitalWrite(r[i], HIGH);
}
pinMode(but1, INPUT_PULLUP);
pinMode(but2, INPUT_PULLUP);
but1State = digitalRead(but1);
but2State = digitalRead(but2);
for (int i=0; i<8 ; ++i) {
for (int j=0; j<8 ; ++j) {
matrix1[i][j] = 0;
}
}
for (int i=0; i<8 ; ++i) {
for (int j=0; j<8 ; ++j) {
matrix2[i][j] = 0;
}
}
//Store initial elapsed time
t = millis();
}
void loop() {
int but1Now = digitalRead(but1);
delay(5);
int but1Now1 = digitalRead(but1);
if(but1Now == but1Now1)
{
if(but1Now != but1State)
{
value1 = 1;
value2 = 0;
//show(img1);
}
but1State = but1Now;
}
int but2Now = digitalRead(but2);
delay(5);
int but2Now1 = digitalRead(but2);
if(but2Now == but2Now1)
{
if(but2Now != but2State)
{
value1 = 0;
value2 = 1;
//show(img2);
}
but2State = but2Now;
}
if(value1 == 1)
{
animation1();
}
if(value2 == 1)
{
animation2();
}
}
void animation1() {
//Store the character data in the output array for each elapsed time
if (t+scrolltime <= millis()) {
for (int i=0; i<8 ; i++) {
for (int j=0; j<8 ; j++) {
matrix1[i][j] = all_num[i][j+position];
}
}
//Slide the storage location and return to the beginning when you reach the end
if (position<52) {
++position; }
else {
position=0; }
//Remeasure the elapsed time
t=millis();
}
// Character data output processing
for (int i=0; i<8; i++) {
digitalWrite(r[i], LOW);
for (int j=0; j<8; j++) {
digitalWrite(c[j], matrix1[j][i]); }
for (int j=0; j<8; j++) {
digitalWrite(c[j], LOW); }
digitalWrite(r[i], HIGH); } }
void animation2() {
//Store the character data in the output array for each elapsed time
if (t+scrolltime <= millis()) {
for (int i=0; i<8 ; i++) {
for (int j=0; j<8 ; j++) {
matrix2[i][j] = Eng20009[i][j+position];
}
}
//Slide the storage location and return to the beginning when you reach the end
if (position<52) {
++position; }
else {
position=0; }
//Remeasure the elapsed time
t=millis();
}
// Character data output processing
for (int i=0; i<8; i++) {
digitalWrite(r[i], LOW);
for (int j=0; j<8; j++) {
digitalWrite(c[j], matrix2[j][i]); }
for (int j=0; j<8; j++) {
digitalWrite(c[j], LOW); }
digitalWrite(r[i], HIGH); } }
