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.
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:
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.
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.
Comments
Rich H
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
The Simple Servo Tester, a kit from Gadget Gangster.
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
·
Rich H
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
The Simple Servo Tester, a kit from Gadget Gangster.
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.