My First Project - Basic Faux Candles With The BS2
I saw on Parallel EFX that they had designed a simple way to make some LEDs flicker like candles then extinguish themselves like the wind had blown them out using a Basic Stamp 1 and the PBASIC 1.0 language.· I found the effect kind of neat being that I run a simple Halloween haunt every year in my garage, only problem is that I don't get my Prop-1 Controller for about another week.· So I had to do something in·my spare time and I developed this for the Basic Stamp 2 and the PBASIC 2.5 language.
This is my first project and I am pretty much a newbie so please bear with me.· At the time I do not have a picture of the set up (my digital camera software isn't installed since I just recently reformatted)·or a schematic. However,·I do have the BS2 file and code for the project.· All the parts can be found in the "What's a Microcontroller?" kit by Parallax.· The circuitry uses a simple digital potentiometer and LED with a pushbutton used as the trigger to create the "wind effect."· I am sure everyone can hook-up this simple circuit. [noparse];)[/noparse]
Anyway, I will attach the BS2 file to this post and simply paste the code in here.· I am looking for ideas to make the program run quicker, but with the same effect. Any help would be appreciated.
Have fun with this newbie project. [noparse];)[/noparse]
'========================================================================================
'·· File....... FauxCandles.BS2
'·· Purpose.... Simulate a candle with an LED; with wind/trigger input
'·· Author..... David Gross
'·· E-mail..... alleyrat18@gmail.com
'·· Started.... 4 SEP 2005
'·· Updated.... 4 SEP 2005
'
'·· {$STAMP BS2}
'·· {$PBASIC 2.5}
'========================================================================================
'========================================================================================
'
[noparse][[/noparse] Program Description ]
' Simulates candle flicker by executing a routine through a digital potentiometer. Once
' a trigger is pressed, the candle slowly dims out, as if being blown away by the wind.
'========================================================================================
'========================================================================================
'
[noparse][[/noparse] Variable Declarations ]
counter········· VAR········· Byte
'========================================================================================
'========================================================================================
'
[noparse][[/noparse] Program Code ]
DO
· HIGH 5
· FOR counter = 0 TO 127
· PULSOUT 6, 1
· PAUSE 1
· IF (IN3 = 1) THEN GOSUB Dim_Candles
· NEXT
· LOW 5
· FOR counter = 0 TO 110
· PULSOUT 6, 1
· PAUSE 1
· IF (IN3 = 1) THEN GOSUB Dim_Candles
· NEXT
· HIGH 5
· FOR counter = 0 TO 100
· PULSOUT 6, 1
· PAUSE 1
· IF (IN3 = 1) THEN GOSUB Dim_Candles
· NEXT
· LOW 5
· FOR counter = 0 TO 115
· PULSOUT 6, 1
· PAUSE 1
· IF (IN3 = 1) THEN GOSUB Dim_Candles
· NEXT
· HIGH 5
· FOR counter = 0 TO 105
· PULSOUT 6, 1
· PAUSE 1
· IF (IN3 = 1) THEN GOSUB Dim_Candles
· NEXT
· LOW 5
· FOR counter = 0 TO 90
· PULSOUT 6, 1
· PAUSE 1
· IF (IN3 = 1) THEN GOSUB Dim_Candles
· NEXT
· HIGH 5
· FOR counter = 0 TO 100
· PULSOUT 6, 1
· PAUSE 1
· IF (IN3 = 1) THEN GOSUB Dim_Candles
· NEXT
· LOW 5
· FOR counter = 0 TO 80
· PULSOUT 6, 1
· PAUSE 1
· IF (IN3 = 1) THEN GOSUB Dim_Candles
· NEXT
· HIGH 5
· FOR counter = 0 TO 95
· PULSOUT 6, 1
· PAUSE 1
· IF (IN3 = 1) THEN GOSUB Dim_Candles
· NEXT
· LOW 5
· FOR counter = 0 TO 75
· PULSOUT 6, 1
· PAUSE 1
· IF (IN3 = 1) THEN GOSUB Dim_Candles
· NEXT
· HIGH 5
· FOR counter = 0 TO 80
· PULSOUT 6, 1
· PAUSE 1
· IF (IN3 = 1) THEN GOSUB Dim_Candles
· NEXT
· LOW 5
· FOR counter = 0 TO 90
· PULSOUT 6, 1
· PAUSE 1
· IF (IN3 = 1) THEN GOSUB Dim_Candles
· NEXT
· HIGH 5
· FOR counter = 0 TO 85
· PULSOUT 6, 1
· PAUSE 1
· IF (IN3 = 1) THEN GOSUB Dim_Candles
· NEXT
· LOW 5
· FOR counter = 0 TO 100
· PULSOUT 6, 1
· PAUSE 1
· IF (IN3 = 1) THEN GOSUB Dim_Candles
· NEXT
· HIGH 5
· FOR counter = 0 TO 90
· PULSOUT 6, 1
· PAUSE 1
· IF (IN3 = 1) THEN GOSUB Dim_Candles
· NEXT
· LOW 5
· FOR counter = 0 TO 105
· PULSOUT 6, 1
· PAUSE 1
· IF (IN3 = 1) THEN GOSUB Dim_Candles
· NEXT
· HIGH 5
· FOR counter = 0 TO 95
· PULSOUT 6, 1
· PAUSE 1
· IF (IN3 = 1) THEN GOSUB Dim_Candles
· NEXT
· LOW 5
· FOR counter = 0 TO 110
· PULSOUT 6, 1
· PAUSE 1
· IF (IN3 = 1) THEN GOSUB Dim_Candles
· NEXT
LOOP
'========================================================================================
'========================================================================================
'
[noparse][[/noparse] Subroutine - Dim_Candles]
Dim_Candles:
· HIGH 5
· FOR counter = 0 TO 90
· PULSOUT 6, 1
· PAUSE 1
· NEXT
· LOW 5
· FOR counter = 0 TO 127
· PULSOUT 6, 1
· PAUSE 10
· NEXT
END
'========================================================================================
This is my first project and I am pretty much a newbie so please bear with me.· At the time I do not have a picture of the set up (my digital camera software isn't installed since I just recently reformatted)·or a schematic. However,·I do have the BS2 file and code for the project.· All the parts can be found in the "What's a Microcontroller?" kit by Parallax.· The circuitry uses a simple digital potentiometer and LED with a pushbutton used as the trigger to create the "wind effect."· I am sure everyone can hook-up this simple circuit. [noparse];)[/noparse]
Anyway, I will attach the BS2 file to this post and simply paste the code in here.· I am looking for ideas to make the program run quicker, but with the same effect. Any help would be appreciated.
Have fun with this newbie project. [noparse];)[/noparse]
'========================================================================================
'·· File....... FauxCandles.BS2
'·· Purpose.... Simulate a candle with an LED; with wind/trigger input
'·· Author..... David Gross
'·· E-mail..... alleyrat18@gmail.com
'·· Started.... 4 SEP 2005
'·· Updated.... 4 SEP 2005
'
'·· {$STAMP BS2}
'·· {$PBASIC 2.5}
'========================================================================================
'========================================================================================
'
[noparse][[/noparse] Program Description ]
' Simulates candle flicker by executing a routine through a digital potentiometer. Once
' a trigger is pressed, the candle slowly dims out, as if being blown away by the wind.
'========================================================================================
'========================================================================================
'
[noparse][[/noparse] Variable Declarations ]
counter········· VAR········· Byte
'========================================================================================
'========================================================================================
'
[noparse][[/noparse] Program Code ]
DO
· HIGH 5
· FOR counter = 0 TO 127
· PULSOUT 6, 1
· PAUSE 1
· IF (IN3 = 1) THEN GOSUB Dim_Candles
· NEXT
· LOW 5
· FOR counter = 0 TO 110
· PULSOUT 6, 1
· PAUSE 1
· IF (IN3 = 1) THEN GOSUB Dim_Candles
· NEXT
· HIGH 5
· FOR counter = 0 TO 100
· PULSOUT 6, 1
· PAUSE 1
· IF (IN3 = 1) THEN GOSUB Dim_Candles
· NEXT
· LOW 5
· FOR counter = 0 TO 115
· PULSOUT 6, 1
· PAUSE 1
· IF (IN3 = 1) THEN GOSUB Dim_Candles
· NEXT
· HIGH 5
· FOR counter = 0 TO 105
· PULSOUT 6, 1
· PAUSE 1
· IF (IN3 = 1) THEN GOSUB Dim_Candles
· NEXT
· LOW 5
· FOR counter = 0 TO 90
· PULSOUT 6, 1
· PAUSE 1
· IF (IN3 = 1) THEN GOSUB Dim_Candles
· NEXT
· HIGH 5
· FOR counter = 0 TO 100
· PULSOUT 6, 1
· PAUSE 1
· IF (IN3 = 1) THEN GOSUB Dim_Candles
· NEXT
· LOW 5
· FOR counter = 0 TO 80
· PULSOUT 6, 1
· PAUSE 1
· IF (IN3 = 1) THEN GOSUB Dim_Candles
· NEXT
· HIGH 5
· FOR counter = 0 TO 95
· PULSOUT 6, 1
· PAUSE 1
· IF (IN3 = 1) THEN GOSUB Dim_Candles
· NEXT
· LOW 5
· FOR counter = 0 TO 75
· PULSOUT 6, 1
· PAUSE 1
· IF (IN3 = 1) THEN GOSUB Dim_Candles
· NEXT
· HIGH 5
· FOR counter = 0 TO 80
· PULSOUT 6, 1
· PAUSE 1
· IF (IN3 = 1) THEN GOSUB Dim_Candles
· NEXT
· LOW 5
· FOR counter = 0 TO 90
· PULSOUT 6, 1
· PAUSE 1
· IF (IN3 = 1) THEN GOSUB Dim_Candles
· NEXT
· HIGH 5
· FOR counter = 0 TO 85
· PULSOUT 6, 1
· PAUSE 1
· IF (IN3 = 1) THEN GOSUB Dim_Candles
· NEXT
· LOW 5
· FOR counter = 0 TO 100
· PULSOUT 6, 1
· PAUSE 1
· IF (IN3 = 1) THEN GOSUB Dim_Candles
· NEXT
· HIGH 5
· FOR counter = 0 TO 90
· PULSOUT 6, 1
· PAUSE 1
· IF (IN3 = 1) THEN GOSUB Dim_Candles
· NEXT
· LOW 5
· FOR counter = 0 TO 105
· PULSOUT 6, 1
· PAUSE 1
· IF (IN3 = 1) THEN GOSUB Dim_Candles
· NEXT
· HIGH 5
· FOR counter = 0 TO 95
· PULSOUT 6, 1
· PAUSE 1
· IF (IN3 = 1) THEN GOSUB Dim_Candles
· NEXT
· LOW 5
· FOR counter = 0 TO 110
· PULSOUT 6, 1
· PAUSE 1
· IF (IN3 = 1) THEN GOSUB Dim_Candles
· NEXT
LOOP
'========================================================================================
'========================================================================================
'
[noparse][[/noparse] Subroutine - Dim_Candles]
Dim_Candles:
· HIGH 5
· FOR counter = 0 TO 90
· PULSOUT 6, 1
· PAUSE 1
· NEXT
· LOW 5
· FOR counter = 0 TO 127
· PULSOUT 6, 1
· PAUSE 10
· NEXT
END
'========================================================================================
Comments
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
csavage@parallax.com
It will be interesting to see how his code compares to mine when he posts his being that his will probably be much better with the RANDOM command amongst other things that I don't quite understand yet. [noparse];)[/noparse]
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
csavage@parallax.com
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax
The·Elements of PBASIC Style: http://www.parallax.com/dl/docs/prod/stamps/pbasicstyle.pdf
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax
Ryan
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Ryan Clarke
Parallax Tech Support
rclarke@parallax.com
Post Edited (Ryan Clarke (Parallax)) : 9/6/2005 10:40:15 PM GMT
15=CLK, 14=U/D
RoboGeek
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
There are 10 kinds of people in the world,
those that know binary and those that don't.
Formerly bugg.
www.parallax.com
www.goldmine-elec.com
www.expresspcb.com
www.startrek.com