Asymmetric LED Flashing with TASKs
![JonnyMac](https://forums.parallax.com/uploads/userpics/922/n74EUX0AORWZS.jpg)
Credit where it's due: Peter Verkaik suggested this trick in the beta forum.
A task gets called on a regular schedule but what if we want asymmetric output/behavior from the task? -- we can do it with TASKS SUSPEND:
If this task is called every 10ms then the LED on-time will be 200ms and the off-time 800ms. It takes one task tick to process the LED so the suspension value is decremented by one (I have verified this on a 'scope).
A task gets called on a regular schedule but what if we want asymmetric output/behavior from the task? -- we can do it with TASKS SUSPEND:
TASK FLASH_LED Led1 = ~Led1 ' toggle LED IF Led1 = IsOn THEN TASKS SUSPEND, 0, 19 ' on time is 20 ticks ELSE TASKS SUSPEND, 0, 79 ' off time is 80 ticks ENDIF ENDTASK
If this task is called every 10ms then the LED on-time will be 200ms and the off-time 800ms. It takes one task tick to process the LED so the suspension value is decremented by one (I have verified this on a 'scope).
Comments
Cool
More to add to My library.
I really like the Basic code in SXB and the intro to ASM. To Me this is an Ideal transition and merger to Mixed code.
__________________$WMc%_____
Did I mention that the Parallax Oscope is on sale for $90.99.__Thats 35% off the reg. price.____serach for part#28014 on the Parallax home page
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
The Truth is out there············································ BoogerWoods, FL. USA