Looking for Spin example to timeout a LCD backlight in background
Don M
Posts: 1,652
in Propeller 1
I'm looking for a way to turn off the backlight on the display when there is no activity from the rotary encoder i.e. knob hasn't been turned.
I tried launching this code into its own cog and calling it but my main program hangs until it times out. Is there a way to have it run in the background without it affecting the main program?
I'm using the Parallax 4x20 LCD. You send a $11 to turn it on and a $12 to turn it off. I'm using Full Duplex Serial to talk to it.
I launch the WatchDog cog like this
The stack variable is a long[100]
Thanks.
I tried launching this code into its own cog and calling it but my main program hangs until it times out. Is there a way to have it run in the background without it affecting the main program?
I'm using the Parallax 4x20 LCD. You send a $11 to turn it on and a $12 to turn it off. I'm using Full Duplex Serial to talk to it.
I launch the WatchDog cog like this
cognew(WatchDog, @stack)
The stack variable is a long[100]
PUB WatchDog | t LCD.tx($11) t := cnt - 1776 ' sync with system counter repeat 5000 ' Set delay for 5 seconds waitcnt(t += MS_001) LCD.tx($12)
Thanks.
Comments
(I have the same problem in Tachyon so I have the background timer cog (which constantly maintains runtime and general-purpose countdown timers) set a flag or something for the main program to act on).
I tried adding that watchdog routine in the full duplex serial object since fsd launches in it's own cog but that didn't work either. It just stalled for the 5 seconds and then continued on.
You can do a surprising amount of work in 1ms. In your case I would have the foreground set millis (which is global, hence available to both cogs) to -5000 whenever there is activity. During your foreground loop you can look to see if millis is => 0; if it is, send the backlight off command.
If you don't have anything else to do in the background you can do the same thing with my time object (which uses differential measurements of the cnt register). In that case you would reset the backlight timer with. ...and check it with: Note: The time object isn't running in a cog so it must be accessed periodically (before cnt roll-over).
Your stack doesn't need to be that big. I would use 16 or 32.
I often have to read them for a few days to get it.
But this one seems to go directly to the OPs request...
See if it helps?