Shop OBEX P1 Docs P2 Docs Learn Events
BS1 Firefly effect question — Parallax Forums

BS1 Firefly effect question

haunteddansionhaunteddansion Posts: 68
edited 2007-09-03 22:47 in BASIC Stamp
Hi I am using this code to make an effect and cannot for the life of me figure out how to make it work when I trigger pin 7, and only cycle for seconds then wait again until it it triggered. I have spent much time trying to make this work with no success. What would the code look like? The code I am usin is just below this paragraph. Thanks soo much!





'
[noparse][[/noparse] Variables ]

SYMBOL lottery = W1 ' random value
SYMBOL timer = W2
SYMBOL oldFlies = B6 ' flies that have lit
SYMBOL flyNum = B7
SYMBOL mask = B8
SYMBOL test = B9
SYMBOL idx = B10
SYMBOL lastFly = B11


'
[noparse][[/noparse] EEPROM Data ]

BitMask:
EEPROM (%000001, %000010, %000100, %001000, %010000, %100000)


'
[noparse][[/noparse] Initialization ]

Reset:
DIRS = %00111111 ' make P0-P5 outputs
lottery = 1031 ' seed random value


'
[noparse][[/noparse] Program Code ]

Main:
FOR idx = 1 TO 3 ' tumble random generator
RANDOM lottery
NEXT
flyNum = lottery // 6 ' select "fly" (0 to 5)
IF flyNum = lastFly THEN Main ' no repeats
lastFly = flyNum ' save current fly
READ flyNum, mask ' get its bit position
test = mask & oldFlies ' check in "oldFlies"
IF test > 0 THEN Main ' if not 0, already lit

GOSUB Fade_On ' activate fly
timer = lottery // 251 + 250 ' 250 - 500 ms delay
PAUSE timer
GOSUB Fade_Off ' deactivate

timer = lottery / 32 ' delay between flies
PAUSE timer

oldFlies = oldFlies | mask ' mark this fly
IF oldFlies <> %111111 THEN Main ' still more?
oldFlies = %000000 ' no, reset
GOTO Main


'
[noparse][[/noparse] Subroutines ]

Fade_On:
timer = lottery / 16 // 5 + 1 ' randomize brighten time
FOR idx = 0 TO 255 STEP 15 ' sweep from off to on
PWM flyNum, idx, timer ' brighten the output
NEXT
HIGH flyNum ' leave the output on
RETURN


Fade_Off:
timer = lottery / 32 // 5 + 1 ' randomize fade time
FOR idx = 255 TO 0 STEP -15
PWM flyNum, idx, timer ' dim the output
NEXT
LOW flyNum ' leave the output off
RETURN

Comments

  • TechnoRobboTechnoRobbo Posts: 323
    edited 2007-09-02 02:06
    Is this what you mean?

    new variable:

    Symbol Countdown = B0
    ...
    ...
    ....
    PreMain:

    if PIN7=0 then PreMain
    Countdown=30

    Main:
    .............................
    .............................
    ..............rest of your·Main Code goes here
    .............................
    .............................

    Countdown=Countdown-1
    if Countdown=0 then PreMain

    GOTO Main
    ...
    ... your subroutines go here
    ....

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Have Fun


    TR
  • Vern GranerVern Graner Posts: 337
    edited 2007-09-03 22:47
    haunteddansion said...
    Hi I am using this code to make an effect and cannot for the life of me figure out how to make it work

    There are examples on how to do a firefly simulation over onthe EFX-TEK forums here:

    http://www.efx-tek.com/php/smf/index.php?topic=80.0

    and here:

    http://www.efx-tek.com/php/smf/index.php?topic=220.0

    Source code for the BS1, schematics and even pictures are there. [noparse]:)[/noparse]

    Vern

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Vern Graner CNE/CNA/SSE    | "If the network is down, then you're
    Senior Systems Engineer    | obviously incompetent so why are we
    Texas Information Services | paying you? Of course,if the network
    http://www.txis.com        | is up, then we obviously don't need
    Austin Office 512 328-8947 | you, so why are we paying you?" ©VLG
    
    
Sign In or Register to comment.