Playing an animation while doing other functions (LED Matrix and Arduino/ESP8266)











up vote
0
down vote

favorite












i'm trying to write a sketch in C and i need to play an animation on my LED Matrix while initializing function for my program.
The problem is, because i need to play the animation in loop and because during delays function the board does not do anything else, i dont know how to loop it while keep doing my other functions.



Here is the animation:



void Animation(){ 
max7219.clr();
if(InternetStatus){ //This is to draw a circle if internet has connected during the animation
max7219.setColumn(0, B11111111);
for(int i=1; i<7; i++){
max7219.setColumn(i, B10000001);
}
AnUp = B10011101;
AnCenter = B10111001;
AnDown = B11110001;
max7219.setColumn(10, B10000001);
max7219.setColumn(11, B10000001);
max7219.setColumn(15, B10000001);
max7219.setColumn(16, B10000001);
max7219.setColumn(20, B10000001);
max7219.setColumn(21, B10000001);
for(int i=25; i<31; i++){
max7219.setColumn(i, B10000001);
}
max7219.setColumn(31, B11111111);
} else {
AnUp = B00011100;
AnCenter = B00111000;
AnDown = B01110000;
}
max7219.setColumn(7, AnCenter);
max7219.setColumn(8, AnCenter);
max7219.setColumn(9, AnCenter);
max7219.setColumn(12, AnCenter);
max7219.setColumn(13, AnCenter);
max7219.setColumn(14, AnCenter);
max7219.setColumn(17, AnCenter);
max7219.setColumn(18, AnCenter);
max7219.setColumn(19, AnCenter);
max7219.setColumn(22, AnCenter);
max7219.setColumn(23, AnCenter);
max7219.setColumn(24, AnCenter);
max7219.refreshAll();
delay(AnDelay); //delays are set between frames
AnIndex = 0;
max7219.setColumn(7+(AnIndex*5), AnUp);
max7219.setColumn(8+(AnIndex*5), AnUp);
max7219.setColumn(9+(AnIndex*5), AnUp);
max7219.refreshAll();
delay(AnDelay);
max7219.setColumn(7+(AnIndex*5), AnCenter);
max7219.setColumn(8+(AnIndex*5), AnCenter);
max7219.setColumn(9+(AnIndex*5), AnCenter);
AnIndex = 1;
max7219.setColumn(7+(AnIndex*5), AnUp);
max7219.setColumn(8+(AnIndex*5), AnUp);
max7219.setColumn(9+(AnIndex*5), AnUp);
max7219.refreshAll();
delay(AnDelay);
AnIndex=0;
max7219.setColumn(7+(AnIndex*5), AnDown);
max7219.setColumn(8+(AnIndex*5), AnDown);
max7219.setColumn(9+(AnIndex*5), AnDown);
AnIndex=1;
max7219.setColumn(7+(AnIndex*5), AnCenter);
max7219.setColumn(8+(AnIndex*5), AnCenter);
max7219.setColumn(9+(AnIndex*5), AnCenter);
AnIndex=2;
max7219.setColumn(7+(AnIndex*5), AnUp);
max7219.setColumn(8+(AnIndex*5), AnUp);
max7219.setColumn(9+(AnIndex*5), AnUp);
max7219.refreshAll();
delay(AnDelay);
AnIndex=0;
max7219.setColumn(7+(AnIndex*5), AnCenter);
max7219.setColumn(8+(AnIndex*5), AnCenter);
max7219.setColumn(9+(AnIndex*5), AnCenter);
AnIndex=1;
max7219.setColumn(7+(AnIndex*5), AnDown);
max7219.setColumn(8+(AnIndex*5), AnDown);
max7219.setColumn(9+(AnIndex*5), AnDown);
AnIndex=2;
max7219.setColumn(7+(AnIndex*5), AnCenter);
max7219.setColumn(8+(AnIndex*5), AnCenter);
max7219.setColumn(9+(AnIndex*5), AnCenter);
AnIndex=3;
max7219.setColumn(7+(AnIndex*5), AnUp);
max7219.setColumn(8+(AnIndex*5), AnUp);
max7219.setColumn(9+(AnIndex*5), AnUp);
max7219.refreshAll();
delay(AnDelay);
AnIndex=1;
max7219.setColumn(7+(AnIndex*5), AnCenter);
max7219.setColumn(8+(AnIndex*5), AnCenter);
max7219.setColumn(9+(AnIndex*5), AnCenter);
AnIndex=2;
max7219.setColumn(7+(AnIndex*5), AnDown);
max7219.setColumn(8+(AnIndex*5), AnDown);
max7219.setColumn(9+(AnIndex*5), AnDown);
AnIndex=3;
max7219.setColumn(7+(AnIndex*5), AnCenter);
max7219.setColumn(8+(AnIndex*5), AnCenter);
max7219.setColumn(9+(AnIndex*5), AnCenter);
max7219.refreshAll();
delay(AnDelay);
AnIndex=2;
max7219.setColumn(7+(AnIndex*5), AnCenter);
max7219.setColumn(8+(AnIndex*5), AnCenter);
max7219.setColumn(9+(AnIndex*5), AnCenter);
AnIndex=3;
max7219.setColumn(7+(AnIndex*5), AnDown);
max7219.setColumn(8+(AnIndex*5), AnDown);
max7219.setColumn(9+(AnIndex*5), AnDown);
max7219.refreshAll();
delay(AnDelay);
max7219.setColumn(7+(AnIndex*5), AnCenter);
max7219.setColumn(8+(AnIndex*5), AnCenter);
max7219.setColumn(9+(AnIndex*5), AnCenter);
max7219.refreshAll();
delay(AnDelay);
}


And i need to run that animation while executing these functions:



void Wait4Connection(){
Serial.println("Waiting for connection.");
InternetStatus = false;
WaitCon:
max7219.clr();
InternetStatus = false;
RetimeTry = 0;
Serial.println("Trying to connect.");
wifiManager.autoConnect("Clock Configuration");
ret = Ping.ping(ip);
if(ret){ //prova connessione internet
Serial.println("Device connected to the internet.");
timeClient.begin();
Retime:
InternetStatus = true;
Serial.println("Clock synchronization.");
timeClient.update();
Hours = timeClient.getHours() + HH + IsDst(day(timeClient.getEpochTime()), month(timeClient.getEpochTime()), weekday(timeClient.getEpochTime()));
Minutes = timeClient.getMinutes() + MM;
Seconds = timeClient.getSeconds();
if(timeClient.getEpochTime() > 1000){
RetimeTry=0;
Serial.println("Starting clock mode.");
tasker.setInterval(Clocking, 1000);
tasker.setInterval(Refresh, 300000);
} else {
if(RetimeTry<10){
Serial.print("No time received. Retrying. x");
Serial.println(RetimeTry+1);
RetimeTry++;
goto Retime;
} else {
Serial.println("Can't obtain time packets. Reconnecting.");
goto WaitCon;
}
RetimeTry++;
}
} else {
Serial.println("Connection failed.");
InternetStatus = false;
Serial.println("Slowing down 30s");
delay(30000);
tasker.cancel(Animation);
goto WaitCon;
}
}


Thanks.










share|improve this question







New contributor




Parzival is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.




















  • You could write a scheduler for your microcontroller and switch between the different concurrent tasks.
    – Christian Gibbons
    Nov 5 at 17:01










  • I would highly highly recommend refactoring your code into two finite state machines that can trade off running one state at a time. This will make it easy to add another FSM if you have to and give you good practice with microcontrollers (any bigger project you do will likely be in a FSM). For more on structuring FSM's in C/C++, see here: stackoverflow.com/questions/133214/…
    – scohe001
    Nov 5 at 17:03

















up vote
0
down vote

favorite












i'm trying to write a sketch in C and i need to play an animation on my LED Matrix while initializing function for my program.
The problem is, because i need to play the animation in loop and because during delays function the board does not do anything else, i dont know how to loop it while keep doing my other functions.



Here is the animation:



void Animation(){ 
max7219.clr();
if(InternetStatus){ //This is to draw a circle if internet has connected during the animation
max7219.setColumn(0, B11111111);
for(int i=1; i<7; i++){
max7219.setColumn(i, B10000001);
}
AnUp = B10011101;
AnCenter = B10111001;
AnDown = B11110001;
max7219.setColumn(10, B10000001);
max7219.setColumn(11, B10000001);
max7219.setColumn(15, B10000001);
max7219.setColumn(16, B10000001);
max7219.setColumn(20, B10000001);
max7219.setColumn(21, B10000001);
for(int i=25; i<31; i++){
max7219.setColumn(i, B10000001);
}
max7219.setColumn(31, B11111111);
} else {
AnUp = B00011100;
AnCenter = B00111000;
AnDown = B01110000;
}
max7219.setColumn(7, AnCenter);
max7219.setColumn(8, AnCenter);
max7219.setColumn(9, AnCenter);
max7219.setColumn(12, AnCenter);
max7219.setColumn(13, AnCenter);
max7219.setColumn(14, AnCenter);
max7219.setColumn(17, AnCenter);
max7219.setColumn(18, AnCenter);
max7219.setColumn(19, AnCenter);
max7219.setColumn(22, AnCenter);
max7219.setColumn(23, AnCenter);
max7219.setColumn(24, AnCenter);
max7219.refreshAll();
delay(AnDelay); //delays are set between frames
AnIndex = 0;
max7219.setColumn(7+(AnIndex*5), AnUp);
max7219.setColumn(8+(AnIndex*5), AnUp);
max7219.setColumn(9+(AnIndex*5), AnUp);
max7219.refreshAll();
delay(AnDelay);
max7219.setColumn(7+(AnIndex*5), AnCenter);
max7219.setColumn(8+(AnIndex*5), AnCenter);
max7219.setColumn(9+(AnIndex*5), AnCenter);
AnIndex = 1;
max7219.setColumn(7+(AnIndex*5), AnUp);
max7219.setColumn(8+(AnIndex*5), AnUp);
max7219.setColumn(9+(AnIndex*5), AnUp);
max7219.refreshAll();
delay(AnDelay);
AnIndex=0;
max7219.setColumn(7+(AnIndex*5), AnDown);
max7219.setColumn(8+(AnIndex*5), AnDown);
max7219.setColumn(9+(AnIndex*5), AnDown);
AnIndex=1;
max7219.setColumn(7+(AnIndex*5), AnCenter);
max7219.setColumn(8+(AnIndex*5), AnCenter);
max7219.setColumn(9+(AnIndex*5), AnCenter);
AnIndex=2;
max7219.setColumn(7+(AnIndex*5), AnUp);
max7219.setColumn(8+(AnIndex*5), AnUp);
max7219.setColumn(9+(AnIndex*5), AnUp);
max7219.refreshAll();
delay(AnDelay);
AnIndex=0;
max7219.setColumn(7+(AnIndex*5), AnCenter);
max7219.setColumn(8+(AnIndex*5), AnCenter);
max7219.setColumn(9+(AnIndex*5), AnCenter);
AnIndex=1;
max7219.setColumn(7+(AnIndex*5), AnDown);
max7219.setColumn(8+(AnIndex*5), AnDown);
max7219.setColumn(9+(AnIndex*5), AnDown);
AnIndex=2;
max7219.setColumn(7+(AnIndex*5), AnCenter);
max7219.setColumn(8+(AnIndex*5), AnCenter);
max7219.setColumn(9+(AnIndex*5), AnCenter);
AnIndex=3;
max7219.setColumn(7+(AnIndex*5), AnUp);
max7219.setColumn(8+(AnIndex*5), AnUp);
max7219.setColumn(9+(AnIndex*5), AnUp);
max7219.refreshAll();
delay(AnDelay);
AnIndex=1;
max7219.setColumn(7+(AnIndex*5), AnCenter);
max7219.setColumn(8+(AnIndex*5), AnCenter);
max7219.setColumn(9+(AnIndex*5), AnCenter);
AnIndex=2;
max7219.setColumn(7+(AnIndex*5), AnDown);
max7219.setColumn(8+(AnIndex*5), AnDown);
max7219.setColumn(9+(AnIndex*5), AnDown);
AnIndex=3;
max7219.setColumn(7+(AnIndex*5), AnCenter);
max7219.setColumn(8+(AnIndex*5), AnCenter);
max7219.setColumn(9+(AnIndex*5), AnCenter);
max7219.refreshAll();
delay(AnDelay);
AnIndex=2;
max7219.setColumn(7+(AnIndex*5), AnCenter);
max7219.setColumn(8+(AnIndex*5), AnCenter);
max7219.setColumn(9+(AnIndex*5), AnCenter);
AnIndex=3;
max7219.setColumn(7+(AnIndex*5), AnDown);
max7219.setColumn(8+(AnIndex*5), AnDown);
max7219.setColumn(9+(AnIndex*5), AnDown);
max7219.refreshAll();
delay(AnDelay);
max7219.setColumn(7+(AnIndex*5), AnCenter);
max7219.setColumn(8+(AnIndex*5), AnCenter);
max7219.setColumn(9+(AnIndex*5), AnCenter);
max7219.refreshAll();
delay(AnDelay);
}


And i need to run that animation while executing these functions:



void Wait4Connection(){
Serial.println("Waiting for connection.");
InternetStatus = false;
WaitCon:
max7219.clr();
InternetStatus = false;
RetimeTry = 0;
Serial.println("Trying to connect.");
wifiManager.autoConnect("Clock Configuration");
ret = Ping.ping(ip);
if(ret){ //prova connessione internet
Serial.println("Device connected to the internet.");
timeClient.begin();
Retime:
InternetStatus = true;
Serial.println("Clock synchronization.");
timeClient.update();
Hours = timeClient.getHours() + HH + IsDst(day(timeClient.getEpochTime()), month(timeClient.getEpochTime()), weekday(timeClient.getEpochTime()));
Minutes = timeClient.getMinutes() + MM;
Seconds = timeClient.getSeconds();
if(timeClient.getEpochTime() > 1000){
RetimeTry=0;
Serial.println("Starting clock mode.");
tasker.setInterval(Clocking, 1000);
tasker.setInterval(Refresh, 300000);
} else {
if(RetimeTry<10){
Serial.print("No time received. Retrying. x");
Serial.println(RetimeTry+1);
RetimeTry++;
goto Retime;
} else {
Serial.println("Can't obtain time packets. Reconnecting.");
goto WaitCon;
}
RetimeTry++;
}
} else {
Serial.println("Connection failed.");
InternetStatus = false;
Serial.println("Slowing down 30s");
delay(30000);
tasker.cancel(Animation);
goto WaitCon;
}
}


Thanks.










share|improve this question







New contributor




Parzival is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.




















  • You could write a scheduler for your microcontroller and switch between the different concurrent tasks.
    – Christian Gibbons
    Nov 5 at 17:01










  • I would highly highly recommend refactoring your code into two finite state machines that can trade off running one state at a time. This will make it easy to add another FSM if you have to and give you good practice with microcontrollers (any bigger project you do will likely be in a FSM). For more on structuring FSM's in C/C++, see here: stackoverflow.com/questions/133214/…
    – scohe001
    Nov 5 at 17:03















up vote
0
down vote

favorite









up vote
0
down vote

favorite











i'm trying to write a sketch in C and i need to play an animation on my LED Matrix while initializing function for my program.
The problem is, because i need to play the animation in loop and because during delays function the board does not do anything else, i dont know how to loop it while keep doing my other functions.



Here is the animation:



void Animation(){ 
max7219.clr();
if(InternetStatus){ //This is to draw a circle if internet has connected during the animation
max7219.setColumn(0, B11111111);
for(int i=1; i<7; i++){
max7219.setColumn(i, B10000001);
}
AnUp = B10011101;
AnCenter = B10111001;
AnDown = B11110001;
max7219.setColumn(10, B10000001);
max7219.setColumn(11, B10000001);
max7219.setColumn(15, B10000001);
max7219.setColumn(16, B10000001);
max7219.setColumn(20, B10000001);
max7219.setColumn(21, B10000001);
for(int i=25; i<31; i++){
max7219.setColumn(i, B10000001);
}
max7219.setColumn(31, B11111111);
} else {
AnUp = B00011100;
AnCenter = B00111000;
AnDown = B01110000;
}
max7219.setColumn(7, AnCenter);
max7219.setColumn(8, AnCenter);
max7219.setColumn(9, AnCenter);
max7219.setColumn(12, AnCenter);
max7219.setColumn(13, AnCenter);
max7219.setColumn(14, AnCenter);
max7219.setColumn(17, AnCenter);
max7219.setColumn(18, AnCenter);
max7219.setColumn(19, AnCenter);
max7219.setColumn(22, AnCenter);
max7219.setColumn(23, AnCenter);
max7219.setColumn(24, AnCenter);
max7219.refreshAll();
delay(AnDelay); //delays are set between frames
AnIndex = 0;
max7219.setColumn(7+(AnIndex*5), AnUp);
max7219.setColumn(8+(AnIndex*5), AnUp);
max7219.setColumn(9+(AnIndex*5), AnUp);
max7219.refreshAll();
delay(AnDelay);
max7219.setColumn(7+(AnIndex*5), AnCenter);
max7219.setColumn(8+(AnIndex*5), AnCenter);
max7219.setColumn(9+(AnIndex*5), AnCenter);
AnIndex = 1;
max7219.setColumn(7+(AnIndex*5), AnUp);
max7219.setColumn(8+(AnIndex*5), AnUp);
max7219.setColumn(9+(AnIndex*5), AnUp);
max7219.refreshAll();
delay(AnDelay);
AnIndex=0;
max7219.setColumn(7+(AnIndex*5), AnDown);
max7219.setColumn(8+(AnIndex*5), AnDown);
max7219.setColumn(9+(AnIndex*5), AnDown);
AnIndex=1;
max7219.setColumn(7+(AnIndex*5), AnCenter);
max7219.setColumn(8+(AnIndex*5), AnCenter);
max7219.setColumn(9+(AnIndex*5), AnCenter);
AnIndex=2;
max7219.setColumn(7+(AnIndex*5), AnUp);
max7219.setColumn(8+(AnIndex*5), AnUp);
max7219.setColumn(9+(AnIndex*5), AnUp);
max7219.refreshAll();
delay(AnDelay);
AnIndex=0;
max7219.setColumn(7+(AnIndex*5), AnCenter);
max7219.setColumn(8+(AnIndex*5), AnCenter);
max7219.setColumn(9+(AnIndex*5), AnCenter);
AnIndex=1;
max7219.setColumn(7+(AnIndex*5), AnDown);
max7219.setColumn(8+(AnIndex*5), AnDown);
max7219.setColumn(9+(AnIndex*5), AnDown);
AnIndex=2;
max7219.setColumn(7+(AnIndex*5), AnCenter);
max7219.setColumn(8+(AnIndex*5), AnCenter);
max7219.setColumn(9+(AnIndex*5), AnCenter);
AnIndex=3;
max7219.setColumn(7+(AnIndex*5), AnUp);
max7219.setColumn(8+(AnIndex*5), AnUp);
max7219.setColumn(9+(AnIndex*5), AnUp);
max7219.refreshAll();
delay(AnDelay);
AnIndex=1;
max7219.setColumn(7+(AnIndex*5), AnCenter);
max7219.setColumn(8+(AnIndex*5), AnCenter);
max7219.setColumn(9+(AnIndex*5), AnCenter);
AnIndex=2;
max7219.setColumn(7+(AnIndex*5), AnDown);
max7219.setColumn(8+(AnIndex*5), AnDown);
max7219.setColumn(9+(AnIndex*5), AnDown);
AnIndex=3;
max7219.setColumn(7+(AnIndex*5), AnCenter);
max7219.setColumn(8+(AnIndex*5), AnCenter);
max7219.setColumn(9+(AnIndex*5), AnCenter);
max7219.refreshAll();
delay(AnDelay);
AnIndex=2;
max7219.setColumn(7+(AnIndex*5), AnCenter);
max7219.setColumn(8+(AnIndex*5), AnCenter);
max7219.setColumn(9+(AnIndex*5), AnCenter);
AnIndex=3;
max7219.setColumn(7+(AnIndex*5), AnDown);
max7219.setColumn(8+(AnIndex*5), AnDown);
max7219.setColumn(9+(AnIndex*5), AnDown);
max7219.refreshAll();
delay(AnDelay);
max7219.setColumn(7+(AnIndex*5), AnCenter);
max7219.setColumn(8+(AnIndex*5), AnCenter);
max7219.setColumn(9+(AnIndex*5), AnCenter);
max7219.refreshAll();
delay(AnDelay);
}


And i need to run that animation while executing these functions:



void Wait4Connection(){
Serial.println("Waiting for connection.");
InternetStatus = false;
WaitCon:
max7219.clr();
InternetStatus = false;
RetimeTry = 0;
Serial.println("Trying to connect.");
wifiManager.autoConnect("Clock Configuration");
ret = Ping.ping(ip);
if(ret){ //prova connessione internet
Serial.println("Device connected to the internet.");
timeClient.begin();
Retime:
InternetStatus = true;
Serial.println("Clock synchronization.");
timeClient.update();
Hours = timeClient.getHours() + HH + IsDst(day(timeClient.getEpochTime()), month(timeClient.getEpochTime()), weekday(timeClient.getEpochTime()));
Minutes = timeClient.getMinutes() + MM;
Seconds = timeClient.getSeconds();
if(timeClient.getEpochTime() > 1000){
RetimeTry=0;
Serial.println("Starting clock mode.");
tasker.setInterval(Clocking, 1000);
tasker.setInterval(Refresh, 300000);
} else {
if(RetimeTry<10){
Serial.print("No time received. Retrying. x");
Serial.println(RetimeTry+1);
RetimeTry++;
goto Retime;
} else {
Serial.println("Can't obtain time packets. Reconnecting.");
goto WaitCon;
}
RetimeTry++;
}
} else {
Serial.println("Connection failed.");
InternetStatus = false;
Serial.println("Slowing down 30s");
delay(30000);
tasker.cancel(Animation);
goto WaitCon;
}
}


Thanks.










share|improve this question







New contributor




Parzival is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











i'm trying to write a sketch in C and i need to play an animation on my LED Matrix while initializing function for my program.
The problem is, because i need to play the animation in loop and because during delays function the board does not do anything else, i dont know how to loop it while keep doing my other functions.



Here is the animation:



void Animation(){ 
max7219.clr();
if(InternetStatus){ //This is to draw a circle if internet has connected during the animation
max7219.setColumn(0, B11111111);
for(int i=1; i<7; i++){
max7219.setColumn(i, B10000001);
}
AnUp = B10011101;
AnCenter = B10111001;
AnDown = B11110001;
max7219.setColumn(10, B10000001);
max7219.setColumn(11, B10000001);
max7219.setColumn(15, B10000001);
max7219.setColumn(16, B10000001);
max7219.setColumn(20, B10000001);
max7219.setColumn(21, B10000001);
for(int i=25; i<31; i++){
max7219.setColumn(i, B10000001);
}
max7219.setColumn(31, B11111111);
} else {
AnUp = B00011100;
AnCenter = B00111000;
AnDown = B01110000;
}
max7219.setColumn(7, AnCenter);
max7219.setColumn(8, AnCenter);
max7219.setColumn(9, AnCenter);
max7219.setColumn(12, AnCenter);
max7219.setColumn(13, AnCenter);
max7219.setColumn(14, AnCenter);
max7219.setColumn(17, AnCenter);
max7219.setColumn(18, AnCenter);
max7219.setColumn(19, AnCenter);
max7219.setColumn(22, AnCenter);
max7219.setColumn(23, AnCenter);
max7219.setColumn(24, AnCenter);
max7219.refreshAll();
delay(AnDelay); //delays are set between frames
AnIndex = 0;
max7219.setColumn(7+(AnIndex*5), AnUp);
max7219.setColumn(8+(AnIndex*5), AnUp);
max7219.setColumn(9+(AnIndex*5), AnUp);
max7219.refreshAll();
delay(AnDelay);
max7219.setColumn(7+(AnIndex*5), AnCenter);
max7219.setColumn(8+(AnIndex*5), AnCenter);
max7219.setColumn(9+(AnIndex*5), AnCenter);
AnIndex = 1;
max7219.setColumn(7+(AnIndex*5), AnUp);
max7219.setColumn(8+(AnIndex*5), AnUp);
max7219.setColumn(9+(AnIndex*5), AnUp);
max7219.refreshAll();
delay(AnDelay);
AnIndex=0;
max7219.setColumn(7+(AnIndex*5), AnDown);
max7219.setColumn(8+(AnIndex*5), AnDown);
max7219.setColumn(9+(AnIndex*5), AnDown);
AnIndex=1;
max7219.setColumn(7+(AnIndex*5), AnCenter);
max7219.setColumn(8+(AnIndex*5), AnCenter);
max7219.setColumn(9+(AnIndex*5), AnCenter);
AnIndex=2;
max7219.setColumn(7+(AnIndex*5), AnUp);
max7219.setColumn(8+(AnIndex*5), AnUp);
max7219.setColumn(9+(AnIndex*5), AnUp);
max7219.refreshAll();
delay(AnDelay);
AnIndex=0;
max7219.setColumn(7+(AnIndex*5), AnCenter);
max7219.setColumn(8+(AnIndex*5), AnCenter);
max7219.setColumn(9+(AnIndex*5), AnCenter);
AnIndex=1;
max7219.setColumn(7+(AnIndex*5), AnDown);
max7219.setColumn(8+(AnIndex*5), AnDown);
max7219.setColumn(9+(AnIndex*5), AnDown);
AnIndex=2;
max7219.setColumn(7+(AnIndex*5), AnCenter);
max7219.setColumn(8+(AnIndex*5), AnCenter);
max7219.setColumn(9+(AnIndex*5), AnCenter);
AnIndex=3;
max7219.setColumn(7+(AnIndex*5), AnUp);
max7219.setColumn(8+(AnIndex*5), AnUp);
max7219.setColumn(9+(AnIndex*5), AnUp);
max7219.refreshAll();
delay(AnDelay);
AnIndex=1;
max7219.setColumn(7+(AnIndex*5), AnCenter);
max7219.setColumn(8+(AnIndex*5), AnCenter);
max7219.setColumn(9+(AnIndex*5), AnCenter);
AnIndex=2;
max7219.setColumn(7+(AnIndex*5), AnDown);
max7219.setColumn(8+(AnIndex*5), AnDown);
max7219.setColumn(9+(AnIndex*5), AnDown);
AnIndex=3;
max7219.setColumn(7+(AnIndex*5), AnCenter);
max7219.setColumn(8+(AnIndex*5), AnCenter);
max7219.setColumn(9+(AnIndex*5), AnCenter);
max7219.refreshAll();
delay(AnDelay);
AnIndex=2;
max7219.setColumn(7+(AnIndex*5), AnCenter);
max7219.setColumn(8+(AnIndex*5), AnCenter);
max7219.setColumn(9+(AnIndex*5), AnCenter);
AnIndex=3;
max7219.setColumn(7+(AnIndex*5), AnDown);
max7219.setColumn(8+(AnIndex*5), AnDown);
max7219.setColumn(9+(AnIndex*5), AnDown);
max7219.refreshAll();
delay(AnDelay);
max7219.setColumn(7+(AnIndex*5), AnCenter);
max7219.setColumn(8+(AnIndex*5), AnCenter);
max7219.setColumn(9+(AnIndex*5), AnCenter);
max7219.refreshAll();
delay(AnDelay);
}


And i need to run that animation while executing these functions:



void Wait4Connection(){
Serial.println("Waiting for connection.");
InternetStatus = false;
WaitCon:
max7219.clr();
InternetStatus = false;
RetimeTry = 0;
Serial.println("Trying to connect.");
wifiManager.autoConnect("Clock Configuration");
ret = Ping.ping(ip);
if(ret){ //prova connessione internet
Serial.println("Device connected to the internet.");
timeClient.begin();
Retime:
InternetStatus = true;
Serial.println("Clock synchronization.");
timeClient.update();
Hours = timeClient.getHours() + HH + IsDst(day(timeClient.getEpochTime()), month(timeClient.getEpochTime()), weekday(timeClient.getEpochTime()));
Minutes = timeClient.getMinutes() + MM;
Seconds = timeClient.getSeconds();
if(timeClient.getEpochTime() > 1000){
RetimeTry=0;
Serial.println("Starting clock mode.");
tasker.setInterval(Clocking, 1000);
tasker.setInterval(Refresh, 300000);
} else {
if(RetimeTry<10){
Serial.print("No time received. Retrying. x");
Serial.println(RetimeTry+1);
RetimeTry++;
goto Retime;
} else {
Serial.println("Can't obtain time packets. Reconnecting.");
goto WaitCon;
}
RetimeTry++;
}
} else {
Serial.println("Connection failed.");
InternetStatus = false;
Serial.println("Slowing down 30s");
delay(30000);
tasker.cancel(Animation);
goto WaitCon;
}
}


Thanks.







c++ c arduino






share|improve this question







New contributor




Parzival is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











share|improve this question







New contributor




Parzival is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









share|improve this question




share|improve this question






New contributor




Parzival is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









asked Nov 5 at 16:59









Parzival

12




12




New contributor




Parzival is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





New contributor





Parzival is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.






Parzival is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.












  • You could write a scheduler for your microcontroller and switch between the different concurrent tasks.
    – Christian Gibbons
    Nov 5 at 17:01










  • I would highly highly recommend refactoring your code into two finite state machines that can trade off running one state at a time. This will make it easy to add another FSM if you have to and give you good practice with microcontrollers (any bigger project you do will likely be in a FSM). For more on structuring FSM's in C/C++, see here: stackoverflow.com/questions/133214/…
    – scohe001
    Nov 5 at 17:03




















  • You could write a scheduler for your microcontroller and switch between the different concurrent tasks.
    – Christian Gibbons
    Nov 5 at 17:01










  • I would highly highly recommend refactoring your code into two finite state machines that can trade off running one state at a time. This will make it easy to add another FSM if you have to and give you good practice with microcontrollers (any bigger project you do will likely be in a FSM). For more on structuring FSM's in C/C++, see here: stackoverflow.com/questions/133214/…
    – scohe001
    Nov 5 at 17:03


















You could write a scheduler for your microcontroller and switch between the different concurrent tasks.
– Christian Gibbons
Nov 5 at 17:01




You could write a scheduler for your microcontroller and switch between the different concurrent tasks.
– Christian Gibbons
Nov 5 at 17:01












I would highly highly recommend refactoring your code into two finite state machines that can trade off running one state at a time. This will make it easy to add another FSM if you have to and give you good practice with microcontrollers (any bigger project you do will likely be in a FSM). For more on structuring FSM's in C/C++, see here: stackoverflow.com/questions/133214/…
– scohe001
Nov 5 at 17:03






I would highly highly recommend refactoring your code into two finite state machines that can trade off running one state at a time. This will make it easy to add another FSM if you have to and give you good practice with microcontrollers (any bigger project you do will likely be in a FSM). For more on structuring FSM's in C/C++, see here: stackoverflow.com/questions/133214/…
– scohe001
Nov 5 at 17:03














1 Answer
1






active

oldest

votes

















up vote
0
down vote













Well, at the end i came up with this:



short AnimationControl = 0;

void AnimationMain(){
switch (AnimationControl){
case 0:
Animation1();
break;

case 1:
Animation2();
break;

case 2:
Animation3();
break;

case 3:
Animation4();
break;

case 4:
Animation5();
break;

case 5:
Animation6();
break;

case 6:
Animation7();
break;

case 7:
Animation8();
break;
}
}

void Animation1()
max7219.clr();
if(InternetStatus){
max7219.setColumn(0, B11111111);
for(int i=1; i<7; i++){
max7219.setColumn(i, B10000001);
}
AnUp = B10011101;
AnCenter = B10111001;
AnDown = B11110001;
max7219.setColumn(10, B10000001);
max7219.setColumn(11, B10000001);
max7219.setColumn(15, B10000001);
max7219.setColumn(16, B10000001);
max7219.setColumn(20, B10000001);
max7219.setColumn(21, B10000001);
for(int i=25; i<31; i++){
max7219.setColumn(i, B10000001);
}
max7219.setColumn(31, B11111111);
} else {
AnUp = B00011100;
AnCenter = B00111000;
AnDown = B01110000;
}
max7219.setColumn(7, AnCenter);
max7219.setColumn(8, AnCenter);
max7219.setColumn(9, AnCenter);
max7219.setColumn(12, AnCenter);
max7219.setColumn(13, AnCenter);
max7219.setColumn(14, AnCenter);
max7219.setColumn(17, AnCenter);
max7219.setColumn(18, AnCenter);
max7219.setColumn(19, AnCenter);
max7219.setColumn(22, AnCenter);
max7219.setColumn(23, AnCenter);
max7219.setColumn(24, AnCenter);
max7219.refreshAll();
AnimationControl=1;
}


void Animation2(){
AnIndex = 0;
max7219.setColumn(7+(AnIndex*5), AnUp);
max7219.setColumn(8+(AnIndex*5), AnUp);
max7219.setColumn(9+(AnIndex*5), AnUp);
max7219.refreshAll();
AnimationControl=2;
}

void Animation3(){
max7219.setColumn(7+(AnIndex*5), AnCenter);
max7219.setColumn(8+(AnIndex*5), AnCenter);
max7219.setColumn(9+(AnIndex*5), AnCenter);
AnIndex = 1;
max7219.setColumn(7+(AnIndex*5), AnUp);
max7219.setColumn(8+(AnIndex*5), AnUp);
max7219.setColumn(9+(AnIndex*5), AnUp);
max7219.refreshAll();
AnimationControl=3;
}

void Animation4(){
AnIndex=0;
max7219.setColumn(7+(AnIndex*5), AnDown);
max7219.setColumn(8+(AnIndex*5), AnDown);
max7219.setColumn(9+(AnIndex*5), AnDown);
AnIndex=1;
max7219.setColumn(7+(AnIndex*5), AnCenter);
max7219.setColumn(8+(AnIndex*5), AnCenter);
max7219.setColumn(9+(AnIndex*5), AnCenter);
AnIndex=2;
max7219.setColumn(7+(AnIndex*5), AnUp);
max7219.setColumn(8+(AnIndex*5), AnUp);
max7219.setColumn(9+(AnIndex*5), AnUp);
max7219.refreshAll();
AnimationControl = 4;
}

void Animation5(){
AnIndex=0;
max7219.setColumn(7+(AnIndex*5), AnCenter);
max7219.setColumn(8+(AnIndex*5), AnCenter);
max7219.setColumn(9+(AnIndex*5), AnCenter);
AnIndex=1;
max7219.setColumn(7+(AnIndex*5), AnDown);
max7219.setColumn(8+(AnIndex*5), AnDown);
max7219.setColumn(9+(AnIndex*5), AnDown);
AnIndex=2;
max7219.setColumn(7+(AnIndex*5), AnCenter);
max7219.setColumn(8+(AnIndex*5), AnCenter);
max7219.setColumn(9+(AnIndex*5), AnCenter);
AnIndex=3;
max7219.setColumn(7+(AnIndex*5), AnUp);
max7219.setColumn(8+(AnIndex*5), AnUp);
max7219.setColumn(9+(AnIndex*5), AnUp);
max7219.refreshAll();
AnimationControl = 5;
}

void Animation6(){
AnIndex=1;
max7219.setColumn(7+(AnIndex*5), AnCenter);
max7219.setColumn(8+(AnIndex*5), AnCenter);
max7219.setColumn(9+(AnIndex*5), AnCenter);
AnIndex=2;
max7219.setColumn(7+(AnIndex*5), AnDown);
max7219.setColumn(8+(AnIndex*5), AnDown);
max7219.setColumn(9+(AnIndex*5), AnDown);
AnIndex=3;
max7219.setColumn(7+(AnIndex*5), AnCenter);
max7219.setColumn(8+(AnIndex*5), AnCenter);
max7219.setColumn(9+(AnIndex*5), AnCenter);
max7219.refreshAll();
AnimationControl = 6;
}

void Animation7(){
AnIndex=2;
max7219.setColumn(7+(AnIndex*5), AnCenter);
max7219.setColumn(8+(AnIndex*5), AnCenter);
max7219.setColumn(9+(AnIndex*5), AnCenter);
AnIndex=3;
max7219.setColumn(7+(AnIndex*5), AnDown);
max7219.setColumn(8+(AnIndex*5), AnDown);
max7219.setColumn(9+(AnIndex*5), AnDown);
max7219.refreshAll();
AnimationControl = 7;
}

void Animation8(){
max7219.setColumn(7+(AnIndex*5), AnCenter);
max7219.setColumn(8+(AnIndex*5), AnCenter);
max7219.setColumn(9+(AnIndex*5), AnCenter);
max7219.refreshAll();
AnimationControl = 0;
}


And i called AnimationMain with the Ticker library every setted interval (in my case 125ms).



Hopefully helps someone.






share|improve this answer








New contributor




Parzival is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.


















  • It's a little clunky to make each animation step responsible for modifying the counter, not to mention the switch statement. Right now, if you wanted one step of the animation to be the same as another, you'd need to create a new function for it. Since your animation is simple and cyclical, consider using an array of function pointers instead, and have the main animation function drive the counter. For example: ideone.com/n0Om36
    – paddy
    Nov 5 at 21:46











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});






Parzival is a new contributor. Be nice, and check out our Code of Conduct.










 

draft saved


draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53158896%2fplaying-an-animation-while-doing-other-functions-led-matrix-and-arduino-esp8266%23new-answer', 'question_page');
}
);

Post as a guest
































1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
0
down vote













Well, at the end i came up with this:



short AnimationControl = 0;

void AnimationMain(){
switch (AnimationControl){
case 0:
Animation1();
break;

case 1:
Animation2();
break;

case 2:
Animation3();
break;

case 3:
Animation4();
break;

case 4:
Animation5();
break;

case 5:
Animation6();
break;

case 6:
Animation7();
break;

case 7:
Animation8();
break;
}
}

void Animation1()
max7219.clr();
if(InternetStatus){
max7219.setColumn(0, B11111111);
for(int i=1; i<7; i++){
max7219.setColumn(i, B10000001);
}
AnUp = B10011101;
AnCenter = B10111001;
AnDown = B11110001;
max7219.setColumn(10, B10000001);
max7219.setColumn(11, B10000001);
max7219.setColumn(15, B10000001);
max7219.setColumn(16, B10000001);
max7219.setColumn(20, B10000001);
max7219.setColumn(21, B10000001);
for(int i=25; i<31; i++){
max7219.setColumn(i, B10000001);
}
max7219.setColumn(31, B11111111);
} else {
AnUp = B00011100;
AnCenter = B00111000;
AnDown = B01110000;
}
max7219.setColumn(7, AnCenter);
max7219.setColumn(8, AnCenter);
max7219.setColumn(9, AnCenter);
max7219.setColumn(12, AnCenter);
max7219.setColumn(13, AnCenter);
max7219.setColumn(14, AnCenter);
max7219.setColumn(17, AnCenter);
max7219.setColumn(18, AnCenter);
max7219.setColumn(19, AnCenter);
max7219.setColumn(22, AnCenter);
max7219.setColumn(23, AnCenter);
max7219.setColumn(24, AnCenter);
max7219.refreshAll();
AnimationControl=1;
}


void Animation2(){
AnIndex = 0;
max7219.setColumn(7+(AnIndex*5), AnUp);
max7219.setColumn(8+(AnIndex*5), AnUp);
max7219.setColumn(9+(AnIndex*5), AnUp);
max7219.refreshAll();
AnimationControl=2;
}

void Animation3(){
max7219.setColumn(7+(AnIndex*5), AnCenter);
max7219.setColumn(8+(AnIndex*5), AnCenter);
max7219.setColumn(9+(AnIndex*5), AnCenter);
AnIndex = 1;
max7219.setColumn(7+(AnIndex*5), AnUp);
max7219.setColumn(8+(AnIndex*5), AnUp);
max7219.setColumn(9+(AnIndex*5), AnUp);
max7219.refreshAll();
AnimationControl=3;
}

void Animation4(){
AnIndex=0;
max7219.setColumn(7+(AnIndex*5), AnDown);
max7219.setColumn(8+(AnIndex*5), AnDown);
max7219.setColumn(9+(AnIndex*5), AnDown);
AnIndex=1;
max7219.setColumn(7+(AnIndex*5), AnCenter);
max7219.setColumn(8+(AnIndex*5), AnCenter);
max7219.setColumn(9+(AnIndex*5), AnCenter);
AnIndex=2;
max7219.setColumn(7+(AnIndex*5), AnUp);
max7219.setColumn(8+(AnIndex*5), AnUp);
max7219.setColumn(9+(AnIndex*5), AnUp);
max7219.refreshAll();
AnimationControl = 4;
}

void Animation5(){
AnIndex=0;
max7219.setColumn(7+(AnIndex*5), AnCenter);
max7219.setColumn(8+(AnIndex*5), AnCenter);
max7219.setColumn(9+(AnIndex*5), AnCenter);
AnIndex=1;
max7219.setColumn(7+(AnIndex*5), AnDown);
max7219.setColumn(8+(AnIndex*5), AnDown);
max7219.setColumn(9+(AnIndex*5), AnDown);
AnIndex=2;
max7219.setColumn(7+(AnIndex*5), AnCenter);
max7219.setColumn(8+(AnIndex*5), AnCenter);
max7219.setColumn(9+(AnIndex*5), AnCenter);
AnIndex=3;
max7219.setColumn(7+(AnIndex*5), AnUp);
max7219.setColumn(8+(AnIndex*5), AnUp);
max7219.setColumn(9+(AnIndex*5), AnUp);
max7219.refreshAll();
AnimationControl = 5;
}

void Animation6(){
AnIndex=1;
max7219.setColumn(7+(AnIndex*5), AnCenter);
max7219.setColumn(8+(AnIndex*5), AnCenter);
max7219.setColumn(9+(AnIndex*5), AnCenter);
AnIndex=2;
max7219.setColumn(7+(AnIndex*5), AnDown);
max7219.setColumn(8+(AnIndex*5), AnDown);
max7219.setColumn(9+(AnIndex*5), AnDown);
AnIndex=3;
max7219.setColumn(7+(AnIndex*5), AnCenter);
max7219.setColumn(8+(AnIndex*5), AnCenter);
max7219.setColumn(9+(AnIndex*5), AnCenter);
max7219.refreshAll();
AnimationControl = 6;
}

void Animation7(){
AnIndex=2;
max7219.setColumn(7+(AnIndex*5), AnCenter);
max7219.setColumn(8+(AnIndex*5), AnCenter);
max7219.setColumn(9+(AnIndex*5), AnCenter);
AnIndex=3;
max7219.setColumn(7+(AnIndex*5), AnDown);
max7219.setColumn(8+(AnIndex*5), AnDown);
max7219.setColumn(9+(AnIndex*5), AnDown);
max7219.refreshAll();
AnimationControl = 7;
}

void Animation8(){
max7219.setColumn(7+(AnIndex*5), AnCenter);
max7219.setColumn(8+(AnIndex*5), AnCenter);
max7219.setColumn(9+(AnIndex*5), AnCenter);
max7219.refreshAll();
AnimationControl = 0;
}


And i called AnimationMain with the Ticker library every setted interval (in my case 125ms).



Hopefully helps someone.






share|improve this answer








New contributor




Parzival is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.


















  • It's a little clunky to make each animation step responsible for modifying the counter, not to mention the switch statement. Right now, if you wanted one step of the animation to be the same as another, you'd need to create a new function for it. Since your animation is simple and cyclical, consider using an array of function pointers instead, and have the main animation function drive the counter. For example: ideone.com/n0Om36
    – paddy
    Nov 5 at 21:46















up vote
0
down vote













Well, at the end i came up with this:



short AnimationControl = 0;

void AnimationMain(){
switch (AnimationControl){
case 0:
Animation1();
break;

case 1:
Animation2();
break;

case 2:
Animation3();
break;

case 3:
Animation4();
break;

case 4:
Animation5();
break;

case 5:
Animation6();
break;

case 6:
Animation7();
break;

case 7:
Animation8();
break;
}
}

void Animation1()
max7219.clr();
if(InternetStatus){
max7219.setColumn(0, B11111111);
for(int i=1; i<7; i++){
max7219.setColumn(i, B10000001);
}
AnUp = B10011101;
AnCenter = B10111001;
AnDown = B11110001;
max7219.setColumn(10, B10000001);
max7219.setColumn(11, B10000001);
max7219.setColumn(15, B10000001);
max7219.setColumn(16, B10000001);
max7219.setColumn(20, B10000001);
max7219.setColumn(21, B10000001);
for(int i=25; i<31; i++){
max7219.setColumn(i, B10000001);
}
max7219.setColumn(31, B11111111);
} else {
AnUp = B00011100;
AnCenter = B00111000;
AnDown = B01110000;
}
max7219.setColumn(7, AnCenter);
max7219.setColumn(8, AnCenter);
max7219.setColumn(9, AnCenter);
max7219.setColumn(12, AnCenter);
max7219.setColumn(13, AnCenter);
max7219.setColumn(14, AnCenter);
max7219.setColumn(17, AnCenter);
max7219.setColumn(18, AnCenter);
max7219.setColumn(19, AnCenter);
max7219.setColumn(22, AnCenter);
max7219.setColumn(23, AnCenter);
max7219.setColumn(24, AnCenter);
max7219.refreshAll();
AnimationControl=1;
}


void Animation2(){
AnIndex = 0;
max7219.setColumn(7+(AnIndex*5), AnUp);
max7219.setColumn(8+(AnIndex*5), AnUp);
max7219.setColumn(9+(AnIndex*5), AnUp);
max7219.refreshAll();
AnimationControl=2;
}

void Animation3(){
max7219.setColumn(7+(AnIndex*5), AnCenter);
max7219.setColumn(8+(AnIndex*5), AnCenter);
max7219.setColumn(9+(AnIndex*5), AnCenter);
AnIndex = 1;
max7219.setColumn(7+(AnIndex*5), AnUp);
max7219.setColumn(8+(AnIndex*5), AnUp);
max7219.setColumn(9+(AnIndex*5), AnUp);
max7219.refreshAll();
AnimationControl=3;
}

void Animation4(){
AnIndex=0;
max7219.setColumn(7+(AnIndex*5), AnDown);
max7219.setColumn(8+(AnIndex*5), AnDown);
max7219.setColumn(9+(AnIndex*5), AnDown);
AnIndex=1;
max7219.setColumn(7+(AnIndex*5), AnCenter);
max7219.setColumn(8+(AnIndex*5), AnCenter);
max7219.setColumn(9+(AnIndex*5), AnCenter);
AnIndex=2;
max7219.setColumn(7+(AnIndex*5), AnUp);
max7219.setColumn(8+(AnIndex*5), AnUp);
max7219.setColumn(9+(AnIndex*5), AnUp);
max7219.refreshAll();
AnimationControl = 4;
}

void Animation5(){
AnIndex=0;
max7219.setColumn(7+(AnIndex*5), AnCenter);
max7219.setColumn(8+(AnIndex*5), AnCenter);
max7219.setColumn(9+(AnIndex*5), AnCenter);
AnIndex=1;
max7219.setColumn(7+(AnIndex*5), AnDown);
max7219.setColumn(8+(AnIndex*5), AnDown);
max7219.setColumn(9+(AnIndex*5), AnDown);
AnIndex=2;
max7219.setColumn(7+(AnIndex*5), AnCenter);
max7219.setColumn(8+(AnIndex*5), AnCenter);
max7219.setColumn(9+(AnIndex*5), AnCenter);
AnIndex=3;
max7219.setColumn(7+(AnIndex*5), AnUp);
max7219.setColumn(8+(AnIndex*5), AnUp);
max7219.setColumn(9+(AnIndex*5), AnUp);
max7219.refreshAll();
AnimationControl = 5;
}

void Animation6(){
AnIndex=1;
max7219.setColumn(7+(AnIndex*5), AnCenter);
max7219.setColumn(8+(AnIndex*5), AnCenter);
max7219.setColumn(9+(AnIndex*5), AnCenter);
AnIndex=2;
max7219.setColumn(7+(AnIndex*5), AnDown);
max7219.setColumn(8+(AnIndex*5), AnDown);
max7219.setColumn(9+(AnIndex*5), AnDown);
AnIndex=3;
max7219.setColumn(7+(AnIndex*5), AnCenter);
max7219.setColumn(8+(AnIndex*5), AnCenter);
max7219.setColumn(9+(AnIndex*5), AnCenter);
max7219.refreshAll();
AnimationControl = 6;
}

void Animation7(){
AnIndex=2;
max7219.setColumn(7+(AnIndex*5), AnCenter);
max7219.setColumn(8+(AnIndex*5), AnCenter);
max7219.setColumn(9+(AnIndex*5), AnCenter);
AnIndex=3;
max7219.setColumn(7+(AnIndex*5), AnDown);
max7219.setColumn(8+(AnIndex*5), AnDown);
max7219.setColumn(9+(AnIndex*5), AnDown);
max7219.refreshAll();
AnimationControl = 7;
}

void Animation8(){
max7219.setColumn(7+(AnIndex*5), AnCenter);
max7219.setColumn(8+(AnIndex*5), AnCenter);
max7219.setColumn(9+(AnIndex*5), AnCenter);
max7219.refreshAll();
AnimationControl = 0;
}


And i called AnimationMain with the Ticker library every setted interval (in my case 125ms).



Hopefully helps someone.






share|improve this answer








New contributor




Parzival is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.


















  • It's a little clunky to make each animation step responsible for modifying the counter, not to mention the switch statement. Right now, if you wanted one step of the animation to be the same as another, you'd need to create a new function for it. Since your animation is simple and cyclical, consider using an array of function pointers instead, and have the main animation function drive the counter. For example: ideone.com/n0Om36
    – paddy
    Nov 5 at 21:46













up vote
0
down vote










up vote
0
down vote









Well, at the end i came up with this:



short AnimationControl = 0;

void AnimationMain(){
switch (AnimationControl){
case 0:
Animation1();
break;

case 1:
Animation2();
break;

case 2:
Animation3();
break;

case 3:
Animation4();
break;

case 4:
Animation5();
break;

case 5:
Animation6();
break;

case 6:
Animation7();
break;

case 7:
Animation8();
break;
}
}

void Animation1()
max7219.clr();
if(InternetStatus){
max7219.setColumn(0, B11111111);
for(int i=1; i<7; i++){
max7219.setColumn(i, B10000001);
}
AnUp = B10011101;
AnCenter = B10111001;
AnDown = B11110001;
max7219.setColumn(10, B10000001);
max7219.setColumn(11, B10000001);
max7219.setColumn(15, B10000001);
max7219.setColumn(16, B10000001);
max7219.setColumn(20, B10000001);
max7219.setColumn(21, B10000001);
for(int i=25; i<31; i++){
max7219.setColumn(i, B10000001);
}
max7219.setColumn(31, B11111111);
} else {
AnUp = B00011100;
AnCenter = B00111000;
AnDown = B01110000;
}
max7219.setColumn(7, AnCenter);
max7219.setColumn(8, AnCenter);
max7219.setColumn(9, AnCenter);
max7219.setColumn(12, AnCenter);
max7219.setColumn(13, AnCenter);
max7219.setColumn(14, AnCenter);
max7219.setColumn(17, AnCenter);
max7219.setColumn(18, AnCenter);
max7219.setColumn(19, AnCenter);
max7219.setColumn(22, AnCenter);
max7219.setColumn(23, AnCenter);
max7219.setColumn(24, AnCenter);
max7219.refreshAll();
AnimationControl=1;
}


void Animation2(){
AnIndex = 0;
max7219.setColumn(7+(AnIndex*5), AnUp);
max7219.setColumn(8+(AnIndex*5), AnUp);
max7219.setColumn(9+(AnIndex*5), AnUp);
max7219.refreshAll();
AnimationControl=2;
}

void Animation3(){
max7219.setColumn(7+(AnIndex*5), AnCenter);
max7219.setColumn(8+(AnIndex*5), AnCenter);
max7219.setColumn(9+(AnIndex*5), AnCenter);
AnIndex = 1;
max7219.setColumn(7+(AnIndex*5), AnUp);
max7219.setColumn(8+(AnIndex*5), AnUp);
max7219.setColumn(9+(AnIndex*5), AnUp);
max7219.refreshAll();
AnimationControl=3;
}

void Animation4(){
AnIndex=0;
max7219.setColumn(7+(AnIndex*5), AnDown);
max7219.setColumn(8+(AnIndex*5), AnDown);
max7219.setColumn(9+(AnIndex*5), AnDown);
AnIndex=1;
max7219.setColumn(7+(AnIndex*5), AnCenter);
max7219.setColumn(8+(AnIndex*5), AnCenter);
max7219.setColumn(9+(AnIndex*5), AnCenter);
AnIndex=2;
max7219.setColumn(7+(AnIndex*5), AnUp);
max7219.setColumn(8+(AnIndex*5), AnUp);
max7219.setColumn(9+(AnIndex*5), AnUp);
max7219.refreshAll();
AnimationControl = 4;
}

void Animation5(){
AnIndex=0;
max7219.setColumn(7+(AnIndex*5), AnCenter);
max7219.setColumn(8+(AnIndex*5), AnCenter);
max7219.setColumn(9+(AnIndex*5), AnCenter);
AnIndex=1;
max7219.setColumn(7+(AnIndex*5), AnDown);
max7219.setColumn(8+(AnIndex*5), AnDown);
max7219.setColumn(9+(AnIndex*5), AnDown);
AnIndex=2;
max7219.setColumn(7+(AnIndex*5), AnCenter);
max7219.setColumn(8+(AnIndex*5), AnCenter);
max7219.setColumn(9+(AnIndex*5), AnCenter);
AnIndex=3;
max7219.setColumn(7+(AnIndex*5), AnUp);
max7219.setColumn(8+(AnIndex*5), AnUp);
max7219.setColumn(9+(AnIndex*5), AnUp);
max7219.refreshAll();
AnimationControl = 5;
}

void Animation6(){
AnIndex=1;
max7219.setColumn(7+(AnIndex*5), AnCenter);
max7219.setColumn(8+(AnIndex*5), AnCenter);
max7219.setColumn(9+(AnIndex*5), AnCenter);
AnIndex=2;
max7219.setColumn(7+(AnIndex*5), AnDown);
max7219.setColumn(8+(AnIndex*5), AnDown);
max7219.setColumn(9+(AnIndex*5), AnDown);
AnIndex=3;
max7219.setColumn(7+(AnIndex*5), AnCenter);
max7219.setColumn(8+(AnIndex*5), AnCenter);
max7219.setColumn(9+(AnIndex*5), AnCenter);
max7219.refreshAll();
AnimationControl = 6;
}

void Animation7(){
AnIndex=2;
max7219.setColumn(7+(AnIndex*5), AnCenter);
max7219.setColumn(8+(AnIndex*5), AnCenter);
max7219.setColumn(9+(AnIndex*5), AnCenter);
AnIndex=3;
max7219.setColumn(7+(AnIndex*5), AnDown);
max7219.setColumn(8+(AnIndex*5), AnDown);
max7219.setColumn(9+(AnIndex*5), AnDown);
max7219.refreshAll();
AnimationControl = 7;
}

void Animation8(){
max7219.setColumn(7+(AnIndex*5), AnCenter);
max7219.setColumn(8+(AnIndex*5), AnCenter);
max7219.setColumn(9+(AnIndex*5), AnCenter);
max7219.refreshAll();
AnimationControl = 0;
}


And i called AnimationMain with the Ticker library every setted interval (in my case 125ms).



Hopefully helps someone.






share|improve this answer








New contributor




Parzival is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









Well, at the end i came up with this:



short AnimationControl = 0;

void AnimationMain(){
switch (AnimationControl){
case 0:
Animation1();
break;

case 1:
Animation2();
break;

case 2:
Animation3();
break;

case 3:
Animation4();
break;

case 4:
Animation5();
break;

case 5:
Animation6();
break;

case 6:
Animation7();
break;

case 7:
Animation8();
break;
}
}

void Animation1()
max7219.clr();
if(InternetStatus){
max7219.setColumn(0, B11111111);
for(int i=1; i<7; i++){
max7219.setColumn(i, B10000001);
}
AnUp = B10011101;
AnCenter = B10111001;
AnDown = B11110001;
max7219.setColumn(10, B10000001);
max7219.setColumn(11, B10000001);
max7219.setColumn(15, B10000001);
max7219.setColumn(16, B10000001);
max7219.setColumn(20, B10000001);
max7219.setColumn(21, B10000001);
for(int i=25; i<31; i++){
max7219.setColumn(i, B10000001);
}
max7219.setColumn(31, B11111111);
} else {
AnUp = B00011100;
AnCenter = B00111000;
AnDown = B01110000;
}
max7219.setColumn(7, AnCenter);
max7219.setColumn(8, AnCenter);
max7219.setColumn(9, AnCenter);
max7219.setColumn(12, AnCenter);
max7219.setColumn(13, AnCenter);
max7219.setColumn(14, AnCenter);
max7219.setColumn(17, AnCenter);
max7219.setColumn(18, AnCenter);
max7219.setColumn(19, AnCenter);
max7219.setColumn(22, AnCenter);
max7219.setColumn(23, AnCenter);
max7219.setColumn(24, AnCenter);
max7219.refreshAll();
AnimationControl=1;
}


void Animation2(){
AnIndex = 0;
max7219.setColumn(7+(AnIndex*5), AnUp);
max7219.setColumn(8+(AnIndex*5), AnUp);
max7219.setColumn(9+(AnIndex*5), AnUp);
max7219.refreshAll();
AnimationControl=2;
}

void Animation3(){
max7219.setColumn(7+(AnIndex*5), AnCenter);
max7219.setColumn(8+(AnIndex*5), AnCenter);
max7219.setColumn(9+(AnIndex*5), AnCenter);
AnIndex = 1;
max7219.setColumn(7+(AnIndex*5), AnUp);
max7219.setColumn(8+(AnIndex*5), AnUp);
max7219.setColumn(9+(AnIndex*5), AnUp);
max7219.refreshAll();
AnimationControl=3;
}

void Animation4(){
AnIndex=0;
max7219.setColumn(7+(AnIndex*5), AnDown);
max7219.setColumn(8+(AnIndex*5), AnDown);
max7219.setColumn(9+(AnIndex*5), AnDown);
AnIndex=1;
max7219.setColumn(7+(AnIndex*5), AnCenter);
max7219.setColumn(8+(AnIndex*5), AnCenter);
max7219.setColumn(9+(AnIndex*5), AnCenter);
AnIndex=2;
max7219.setColumn(7+(AnIndex*5), AnUp);
max7219.setColumn(8+(AnIndex*5), AnUp);
max7219.setColumn(9+(AnIndex*5), AnUp);
max7219.refreshAll();
AnimationControl = 4;
}

void Animation5(){
AnIndex=0;
max7219.setColumn(7+(AnIndex*5), AnCenter);
max7219.setColumn(8+(AnIndex*5), AnCenter);
max7219.setColumn(9+(AnIndex*5), AnCenter);
AnIndex=1;
max7219.setColumn(7+(AnIndex*5), AnDown);
max7219.setColumn(8+(AnIndex*5), AnDown);
max7219.setColumn(9+(AnIndex*5), AnDown);
AnIndex=2;
max7219.setColumn(7+(AnIndex*5), AnCenter);
max7219.setColumn(8+(AnIndex*5), AnCenter);
max7219.setColumn(9+(AnIndex*5), AnCenter);
AnIndex=3;
max7219.setColumn(7+(AnIndex*5), AnUp);
max7219.setColumn(8+(AnIndex*5), AnUp);
max7219.setColumn(9+(AnIndex*5), AnUp);
max7219.refreshAll();
AnimationControl = 5;
}

void Animation6(){
AnIndex=1;
max7219.setColumn(7+(AnIndex*5), AnCenter);
max7219.setColumn(8+(AnIndex*5), AnCenter);
max7219.setColumn(9+(AnIndex*5), AnCenter);
AnIndex=2;
max7219.setColumn(7+(AnIndex*5), AnDown);
max7219.setColumn(8+(AnIndex*5), AnDown);
max7219.setColumn(9+(AnIndex*5), AnDown);
AnIndex=3;
max7219.setColumn(7+(AnIndex*5), AnCenter);
max7219.setColumn(8+(AnIndex*5), AnCenter);
max7219.setColumn(9+(AnIndex*5), AnCenter);
max7219.refreshAll();
AnimationControl = 6;
}

void Animation7(){
AnIndex=2;
max7219.setColumn(7+(AnIndex*5), AnCenter);
max7219.setColumn(8+(AnIndex*5), AnCenter);
max7219.setColumn(9+(AnIndex*5), AnCenter);
AnIndex=3;
max7219.setColumn(7+(AnIndex*5), AnDown);
max7219.setColumn(8+(AnIndex*5), AnDown);
max7219.setColumn(9+(AnIndex*5), AnDown);
max7219.refreshAll();
AnimationControl = 7;
}

void Animation8(){
max7219.setColumn(7+(AnIndex*5), AnCenter);
max7219.setColumn(8+(AnIndex*5), AnCenter);
max7219.setColumn(9+(AnIndex*5), AnCenter);
max7219.refreshAll();
AnimationControl = 0;
}


And i called AnimationMain with the Ticker library every setted interval (in my case 125ms).



Hopefully helps someone.







share|improve this answer








New contributor




Parzival is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









share|improve this answer



share|improve this answer






New contributor




Parzival is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









answered Nov 5 at 19:24









Parzival

12




12




New contributor




Parzival is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





New contributor





Parzival is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.






Parzival is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.












  • It's a little clunky to make each animation step responsible for modifying the counter, not to mention the switch statement. Right now, if you wanted one step of the animation to be the same as another, you'd need to create a new function for it. Since your animation is simple and cyclical, consider using an array of function pointers instead, and have the main animation function drive the counter. For example: ideone.com/n0Om36
    – paddy
    Nov 5 at 21:46


















  • It's a little clunky to make each animation step responsible for modifying the counter, not to mention the switch statement. Right now, if you wanted one step of the animation to be the same as another, you'd need to create a new function for it. Since your animation is simple and cyclical, consider using an array of function pointers instead, and have the main animation function drive the counter. For example: ideone.com/n0Om36
    – paddy
    Nov 5 at 21:46
















It's a little clunky to make each animation step responsible for modifying the counter, not to mention the switch statement. Right now, if you wanted one step of the animation to be the same as another, you'd need to create a new function for it. Since your animation is simple and cyclical, consider using an array of function pointers instead, and have the main animation function drive the counter. For example: ideone.com/n0Om36
– paddy
Nov 5 at 21:46




It's a little clunky to make each animation step responsible for modifying the counter, not to mention the switch statement. Right now, if you wanted one step of the animation to be the same as another, you'd need to create a new function for it. Since your animation is simple and cyclical, consider using an array of function pointers instead, and have the main animation function drive the counter. For example: ideone.com/n0Om36
– paddy
Nov 5 at 21:46










Parzival is a new contributor. Be nice, and check out our Code of Conduct.










 

draft saved


draft discarded


















Parzival is a new contributor. Be nice, and check out our Code of Conduct.













Parzival is a new contributor. Be nice, and check out our Code of Conduct.












Parzival is a new contributor. Be nice, and check out our Code of Conduct.















 


draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53158896%2fplaying-an-animation-while-doing-other-functions-led-matrix-and-arduino-esp8266%23new-answer', 'question_page');
}
);

Post as a guest




















































































這個網誌中的熱門文章

Tangent Lines Diagram Along Smooth Curve

Yusuf al-Mu'taman ibn Hud

Zucchini