Touch event during postinitialize code not working

Hello!

I have below code that I found in this forum in preinitialize on page1. It’s for getting a fading bootup screen:

for(dim=0;dim<100;dim++) {
  delay=100
}
delay=3000
dp=2

At the same time i have a button on page1 with touchevent activated but it doesn’t seem to work when having this code in postinitialize. My plan was to use it as a bootup screen and if you pressed the button you would enter a configuration page kind of. Is it possible to trigger buttons during postinitialize code? If so, what more do I have to do to get the touch events happening?

Thanks!

  1. Insert a “doevents” command insyde the cycle.
  2. Don’t use the “delay” command but try this code:
    for(sys0=0;sys0<100;sys0++) {
    delay=30
    doevents
    }
2 Likes

Hi and welcome @lillaeriika!

As @lemax said you need to include doevents within the loops because that tells the processor to check for touch inputs etc. It‘s explained in the official instruction set under 3.26 and 3.27, too.
doevents is automatically called after each touch press/release event so most of the time you don‘t need to worry about it.

Kind regards,
Max

1 Like

Thank you for the quick answer. It got me all excited but unfortunately I can’t get it to work.
I have this code now:

for(dim=0;dim<100;dim++)
{
delay=30
doevents
}
dp=2

The screen dims up slowly, when dim=100 it changes to page2 but during the loop no touch events are registered. Iv’e ticked in Send Component ID (touch press event) on button, picture and the whole page1 but no events at all. I can add that I’m using ESPHome and get touch events on all other pages where I don’t have a loop like this configured.

Thank you!

As you can see I answered his post and I can’t get it to work. I’ve tried reading the documentation. In the foor loop example doevents is the only thing within the block{}

I’ve tried doing that as well but then the dimming goes really fast and I don’t see any touch events then either.

Try this

for(sys0=0;sys<1000;sys++)
{
dim=sys0/10
doevents
}
dp=2

Nope, added some zeroes to get a longer time to try and press.
Does not work. :frowning:

for(sys0=0;sys0<100000;sys0++)
{
dim=sys0/1000
doevents
}
dp=2

Why would you expect it to work before the page has been initialized? Try putting it in the post initialization.

Yes that’s were I’ve put the code. :slight_smile:

Thinking about this some more I think you should use a Timer component and put the dimming code in there. Something like

dim++
if(dim>=100)
{
  timer.en=0
  page 2
}

Using timers shouldn‘t mess with touch responses etc.

Kind regards,
Max