Shop OBEX P1 Docs P2 Docs Learn Events
Asymmetric LED Flashing with TASKs — Parallax Forums

Asymmetric LED Flashing with TASKs

JonnyMacJonnyMac Posts: 9,214
edited 2009-01-31 05:00 in General Discussion
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:

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

  • $WMc%$WMc% Posts: 1,884
    edited 2009-01-31 05:00
    Mr Williams

    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
Sign In or Register to comment.