Shop OBEX P1 Docs P2 Docs Learn Events
My First Project - Basic Faux Candles With The BS2 — Parallax Forums

My First Project - Basic Faux Candles With The BS2

T3h_R@v3nT3h_R@v3n Posts: 12
edited 2005-11-01 18:17 in Robotics
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
'========================================================================================

Comments

  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2005-09-05 04:56
    Interesting way to pass time waiting for your Prop-1!· Couldn't wait to get your hands wet, huh?· =)· One of our Techs must have gotten bored too and made the same conversion in this thread:· http://forums.parallax.com/showthread.php?p=542365


    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
    csavage@parallax.com
  • T3h_R@v3nT3h_R@v3n Posts: 12
    edited 2005-09-05 05:21
    Lol.

    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 SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2005-09-05 05:24
    Whoops!· I hadn't realized he never posted it.· I saw his message saying he would.· We'll have to have him add his version to this post then.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
    csavage@parallax.com
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2005-09-05 11:53
    Cool. Let me suggest that PBASIC programs are easy to port between the BS1 and BS2 (and back) when you use named pins verus pin numbers. Using named pins lets you shuffle things around as might be required on a bigger (or smaller) project.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
  • T3h_R@v3nT3h_R@v3n Posts: 12
    edited 2005-09-05 14:28
    Jon Williams (Parallax) said...
    Cool. Let me suggest that PBASIC programs are easy to port between the BS1 and BS2 (and back) when you use named pins verus pin numbers. Using named pins lets you shuffle things around as might be required on a bigger (or smaller) project.

    Great idea Jon.· I also put all the values of the potentiometer into an array to condense the program greatly. I will post the new program code in a bit.
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2005-09-05 17:25
    I'm the most anal-retentive code formatter I know, so that kind of stuff tends to be important to me.· We have guidelines that we use a Parallax that I think are very useful, and have just reiterated them in the StampWorks (being edited now) update.

    The·Elements of PBASIC Style: http://www.parallax.com/dl/docs/prod/stamps/pbasicstyle.pdf

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
  • Ryan ClarkeRyan Clarke Posts: 738
    edited 2005-09-06 21:08
    I don't think that some people realize that there is a reason for striving for consistency and good coding style...it can help with debugging, and facilitate quick and easy code modification down the road...

    Ryan

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Ryan Clarke

    Parallax Tech Support
    rclarke@parallax.com

    Post Edited (Ryan Clarke (Parallax)) : 9/6/2005 10:40:15 PM GMT
  • MacGeek117MacGeek117 Posts: 747
    edited 2005-11-01 18:17
    I have also come up with a fairly good program for the Faux Candle, see attachment below.
    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
Sign In or Register to comment.