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.
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.
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 )
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