Shop OBEX P1 Docs P2 Docs Learn Events
Blinking LEDs - Subloops? — Parallax Forums

Blinking LEDs - Subloops?

JackMacJackMac Posts: 3
edited 2008-07-09 00:25 in BASIC Stamp
Hi Forum - I'm doing my first project with a BS2 on a BOE board with PBasis2.5.

I'm controlling several LEDs (basically easy), but then I need to make a selected one blink at a fast rate (like 5/sec), while other LEDs stay lit. I'd like to somehow generate a 5/sec clock signal ("Blink") that continues outside (independent of) the main loop. Then I can just set RedLED (a PIN variable) = Blink to make it flash. So, in essence, I need to have TWO loops running; one to control the blink rate, plus the main loop.

If I just define a bit variable called "Blink" like this,

' Generate Blink squarewave 200ms (5/second)
BlinkCtr = BlinkCtr + 1
SELECT BlinkCtr 'BlinkClk counts to 200, then resets
CASE 100 'Assuming main loop time ~1ms
Blink = 1
CASE 200
Blink = 0
BlinkCtr = 0
ENDSELECT

then this Blink timing is screwed up if the main loop goes off and does something else for a few seconds.

Any ideas on how to make Blink remain a fixed squarewave (or some other approach to making the LED blink fast)?

Thx,
Jack

Comments

  • sam_sam_samsam_sam_sam Posts: 2,286
    edited 2008-07-07 19:01
    ·Look at this

    This may help you understand what you want to do ·····

    http://www.parallax.com/Portals/0/Downloads/docs/books/edu/Wamv2_2.pdf

    What’s a Microcontroller?· Chapter #2: Lights On – Lights Off · Page 37

    This is where it start read all of Chapter 2

    JackMac

    So, in essence, I need to have TWO loops running; one to control the blink rate, plus the main loop.

    You can ONLY do one thing at a time with a BASIC STAMP

    Now you can·run thing one at time and make it look like you are doing two thing at one time but you are not

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ··Thanks for any·idea.gif·that you may have and all of your time finding them

    ·
    ·
    ·
    ·
    Sam

    Post Edited (sam_sam_sam) : 7/7/2008 7:08:54 PM GMT
  • JackMacJackMac Posts: 3
    edited 2008-07-07 20:15
    Sorry Sam, the examples shown in the manual do NOT really address my issue. They simple reaffirm that the BS2 can only do one thing at a time. I'm not sure my problem can be solved.

    When I jump out of my main loop with a gosub to set the LED states, I set some LEDs high or low and others to my variable "Blink" before returning to the main loop. But even though Blink is a 200ms squarewave, the LED is told to go to the value of Blink at the instant it's sampled, not the alternating value over time.

    Seems like I may have to assign the blinking LED state value within a subloop inside the main loop, thus increasing the duration of the main loop (which I don't want to do).

    Suggestions?
    Thx,
    Jack
  • JackMacJackMac Posts: 3
    edited 2008-07-09 00:25
    Just to let you know; I solved the issue myself. The Blink code block must be within the main Do Loop to keep the LEDs blinking. Then when outside the loop doing other things (requiring the LEDs to continue blinking), I simply jump back into the main loop at the beginning of the Blink code and then jump back out at the end of the Blink code to finish what I was doing. So I'm using a "piece" of the main loop code while I'm outside the loop. Works great.

    Jack
Sign In or Register to comment.