Start a new topic

Button Background Color

Newbie. I just started playing around with this programming thing and on my first adventure failed. However, for the life of me I can not figure out why.


I made a very simple background picture for the display and added four buttons which when pressed take the user to the four pages. Each button is set to a default bco color, green  and a pressed color bco2 of red. When pressed, none of the buttons change color. I read somewhere where ref 0 needed to be used so I added that still no change. So I loaded the example CompButton and debugged, it said it was out of date and recompiled it. Debugged and the button works as advertised. My button has the same attributes as the demo except color is different. So any ideas on what gives? 


Thanks for any help and I am sure that before I finish this project there will be plenty more questions.

HMI

Refer to doevents in Nextion Instruction Set

  - partial insights.


Code in an event will start running as soon as triggered

 - visual refresh without "doevents" occurs when user event code completes.


Now since you issued a page change in the button's touch Press Event as the first command is to change the page this will take on the expected behaviour of changing pages.

  • Run the Preinitialization Event of the new loading page
  • Dump the old currently loaded page
  • Load the new loading page from the HMI as designed
  • Run the Postinitialization Event of the newly load page
  • Wait for an event (touch, gpio, timer, incoming serial)

So when you have Pressed your button, it has already changed pages with the new page's button (which is in almost the same location) in it's unpressed state - you see a green button of the new page and think the other old now unloaded button has never been pressed.  Visually too quick to track.


Such incompleted Press/Release (component Press without matching component Release) will eventually lead to a stack overflow issue.  Press Event pushed onto the stack, but never popped from the stack as there is no matching component release once component's Page is gone.


Page change page command in the component Touch Release event would not only allow you to visually see the button press, but wouldn't change pages until the component is released and would have matched Press/Release events avoiding your eventual stack overflow issue.


Ref when reading the Nextion Instruction Set, is generally not needed since v0.39

Ref 0 refreshes the entire page, bringing you back to a state of page freshly reloaded (less Pre/Post Init)

( refer to date posts were made (and who posted) when considering their current validity )

PS: 

Your buttons did not completely have the same attributes as CompButton.

The state of the two SendComponentID checkboxes and presence/lack of user code must also be taken into account

Login or Signup to post a comment