Shop OBEX P1 Docs P2 Docs Learn Events
Another Newbie question — Parallax Forums

Another Newbie question

NWCCTVNWCCTV Posts: 3,629
edited 2010-03-05 09:30 in BASIC Stamp
Is it possible to have a BS2SX chip leave 2 LED's on while running other processes, or would I be better off using the Peopeller to accomplish this?

Comments

  • W9GFOW9GFO Posts: 4,010
    edited 2010-03-05 05:49
    Sure. The Basic Stamps can only do one thing at a time. It can turn on the two LEDs, then go on to other tasks, the LEDs will stay on until told otherwise.

    Rich H

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    The Simple Servo Tester, a kit from Gadget Gangster.
  • NWCCTVNWCCTV Posts: 3,629
    edited 2010-03-05 05:56
    Oh, I thought they would shut off. Thanks for that. Would I have to use a loop, or just have the pin go High?
  • RoboticsProfessorRoboticsProfessor Posts: 54
    edited 2010-03-05 06:01
    From page 50 of the Parallax "Robotics with the Boe-Bot" text:

    DO

    · HIGH 13

    · PAUSE 500

    · LOW 13

    · PAUSE 500

    LOOP

    So this will alternately on/off an LED every half second. So if you don't turn the LED off (by sending a low to pin 13) it will stay on as long as you like.

    Just put the on/off code anywhere you want in your code, like...

    'Main Loop

    DO

    · GOSUB Turn_Them_On

    · GOSUB Do_Stuff

    · GOSUB Do_Other_Stuff

    · GOSUB Turn_Them_Off

    LOOP



    Turn_Them_On:

    · HIGH 12

    · HIGH 13

    RETURN



    Turn_Them_Off:

    · LOW 12

    · LOW 13

    RETURN



    Output ports when put to HIGH or LOW remain in that state until changed by the program, so you can "go somewhere else" and do just about anything. If your LEDs are turned on or off at specific times, just place the appropriate subroutine call in your code where it needs to be.

    I used subroutines above to illustrate that the program can continue once the LEDs are lit or extinguished, but you could just as easily put:

    HIGH 12

    HIGH13

    ...or...

    LOW 12

    LOW 13

    ...anywhere you need to in your code.


    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Richard Vannoy

    Programming and Electronics Instructor
    www.RichardVannoy.info
    ·
  • W9GFOW9GFO Posts: 4,010
    edited 2010-03-05 08:09
    NWCCTV said...
    Oh, I thought they would shut off. Thanks for that. Would I have to use a loop, or just have the pin go High?
    Microcontrollers have to be told everything. If you tell it to turn on the LEDs then they will stay on until you command them to go off (or the power runs out). You don't need a loop to keep telling them to turn on.

    Rich H

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    The Simple Servo Tester, a kit from Gadget Gangster.
  • sylvie369sylvie369 Posts: 1,622
    edited 2010-03-05 09:30
    I gather that you´re thinking that LEDs work like servos, in that the micro needs to give them constant attention. They don´t, because you turn an LED on simply by putting the corresponding pin HIGH, while with servos you have to constantly send pulses of a certain type (which DOES require the micro´s attention).

    If you move a servo and then stop paying attention to it, weird things will happen, but if you turn an LED on and then stop paying attention to it, it´ll just stay on. No problem.
Sign In or Register to comment.