Start a new topic

Timers activating timers

I want to cretae a screen in which 2 arrows are changing their colors from bright to dark (only 2 colors, yellow and grey). I have two images, one contains the first arrow in yellow and the second in grey and the second one, the contrary configuration.


I created 2 timers. The first one, activated after 400ms, change the image to the second one, and enable the second timer 


The second timer, fires after 400ms, change the image to the first one and enable the first timer again.


In simuator mode, it seems to work fine. You can see the change in images continously, but in real device you just see the change to the second timer. But this second timer never gets launch neither the image change again.


How do you guys do a loading screen?


I am not sure I followed.

Two timers toggle each other at the same interval

 - I might have used only one and a variable to track 

   and used an if then else.

 - But one timer must deactivate itself .en=0 before 

   triggering the other .en=1


A loading screen? (loading is near instant?)

 - but perhaps you mean a different page?

If you are referring to a page while TFT loads

 - there is no hiding this.


Sorry, I will explain a bit my project.


I have my nextion display connected to an arduino. When I click on a button on the screen, I want to show the current configuration of my arduino.


For this, I created a page with all variables my arduino can store. The problem is that if I change to the page where the values are shown (lets call it page5), nextion display change the page and then, my arduino starts sending the values so I see on the screen how they are being updated.


For this, I want nextion display to go to another "loagind page" and my arduino start updating the values (in page5 all variables are global, so I can update them in any screen). As soon as my variables are updates, arduino will change nextion display page.


I wanted that this loading page wasn't give the impression the display is stuck. So I created both images and wanted to change from one another.


First timer tm0:

tim = 400ms

en=1

Second timer tm1:

tim = 400ms

en=0


In tm0:

p0.pic=79

tm1.en=1


In tm1:

p0.pic=78

tm0.en=1


Timers are executed just once? and then enable goes disabled? I am not sure how timers work in nextion displays.


I think, tm0 is enabled, fires at 400ms, executes code and then it goes disabled. Then at 400ms tm1 fires, executes code (enabling tm0) and goes disabled.


Debug in simulator works this way. Not the real device. Which never fires the second timer.

@Biribu


As Patrick stated, a simple if else in one timer should suffice.


example.. 

if(t0.txt=="Hello")
{
  t0.txt="World"
}else
{
  t0.txt="Hello"
}

 

Make a timeline

 

 

0.0
0.4    TM1 fires enabling TM2
0.8    TM1 fires, TM2 fires
1.2    TM1 fires, TM2 fires
1.6    TM1 fires, TM2 fires
2.0    TM1 fires, TM2 fires

 


I think it is doing exactly as instructed to do

I think you are not quick enough to see the change in ms

Timer is triggered after interval counter expires, code, reset, count again


But does Arduino really take 800ms or more to update variables?

At 115200 baud, that is 11,520 char max, ~ 10,350 byte effective.

Timers are triggered each 400ms. They repeats until something stops them. Understood!


I got it working now. Actually arduino takes a couple of seconds because I do some operations depending on values and I had to include a couple of delays.


I want to improve that, but for the moment, this is what I have.

Login or Signup to post a comment