Scrolling Text as a state

  • 323 Views
  • Last Post 11 November 2015
will_brett posted this 25 October 2015

I've been playing around with the examples for a bit and now feel i understand how it works enough to start writing my own scripts and combining the examples into larger programs. 

I've come accross an issue however. So far I have made a counter so that when you click the right button it ads 1 to an int and if you press the left button it takes 1 off that same int. This int is then linked to a switch so that the petduino has different states. I've got this working with simple things like making sounds and displaying images etc but when I tried to do it with the scrolling text the buttons no longer function. They dont even register a click in the serial monitor anymore. 

Does anyone know how I can make it so that I can get the buttons to function when the scrolling text state is active? 

I hope thats enough info. If not let me know and I will cut down my script to show the valid stuff. 

 

Thanks :D

3 Comments
Order By: Standard | Newest | Votes
Circuitbeard posted this 26 October 2015

Hey Will,

Glad to hear you are rocking along nicely with your Petduino.

The reason the scrolling text demo prevents the buttons from working (and I think by the title of your post you may also know why) is because the scrolling is using delay to do this rather than the Petduino's state manager. Delay is a blocking action, so while the system is being delayed, everything but interupts will stop during that time, where as the state manager built into the Petduino library is non blocking. The state manager internally tracks timestamps of actions, and as part of the pet.update() call determins whether a state has expired and so should change.

To allow the buttons to work, you'd need to change the scrolling text demo to use states to update the display, rather than delay.

In all honesty, the code for the scrolling text demo was copied from some place else and has been on my list to update to be a bit nicer, I just never got around to it. Hopefully this gives you a starting point though.

Circuitbeard posted this 26 October 2015

Ok, I've gone ahead and created a state based scrolling text demo so hopefully this will be of use to you. I've pushed it to the Petduino github repo here:

https://github.com/circuitbeard/petduino/blob/master/examples/ScrollingTextState/ScrollingTextState.ino

will_brett posted this 11 November 2015

Oh superb thank you very much.