Shop OBEX P1 Docs P2 Docs Learn Events
Code not working — Parallax Forums

Code not working

Lithium_fun!Lithium_fun! Posts: 18
edited 2007-09-15 14:16 in BASIC Stamp
I don't understand why this code won't work. It's for LED candles.

'---[noparse][[/noparse]Pins]
candle1 PIN 0
candle2 PIN 1
candle3 PIN 2
'---[noparse][[/noparse]Variables]
cc1 VAR Bit
cc2 VAR Bit
cc3 VAR Bit
zc1 VAR Word
zc2 VAR Word
zc3 VAR Word
'---[noparse][[/noparse]Main Program]

DO
· RANDOM cc1
· RANDOM cc2
· RANDOM cc3

·' IF (cc1 = 0) THEN
·'·· zc1 = zc1 + 1
·' ELSEIF (cc2 = 0) THEN
·'·· zc2 = zc2 + 1
·' ELSEIF (cc3 = 0) THEN
·'·· zc3 = zc3 + 1
·' ENDIF

· IF (cc1 = 0) THEN
··· LOW candle1
· ELSE
··· HIGH candle1
· ENDIF

· IF (cc2 = 0) THEN
··· LOW candle2
· ELSE
··· HIGH candle2
· ENDIF

· IF (cc3 = 0) THEN
··· LOW candle3
· ELSE
··· HIGH candle3
· ENDIF
LOOP

Comments

  • kelvin jameskelvin james Posts: 531
    edited 2007-09-15 06:02
    I think you may have your variables set wrong, it seems that a word is required for a random variable, and you may have to specify a seed value to begin with, according to the examples in the help section.
  • Bruce BatesBruce Bates Posts: 3,045
    edited 2007-09-15 07:56
    Lithium_fun -

    You will need to add two lines to the beginning of your program similar to these:

    ' {$STAMP BS2}
    ' {$PBASIC 2.5}

    If the first compiler directive above does not describe the PBASIC Stamp that you are using, then change it accordingly (BS2SX, BS2PE, etc). Complete information on the $STAMP compiler directive can be found in the PBASIC Manual, or the PBASIC Help File.

    Regards,

    Bruce Bates

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
  • D FaustD Faust Posts: 608
    edited 2007-09-15 13:30
    The random command scrambles the digits of the value already in the variable, so as a default it is %0. You might have to create a larger variable (nib maybe) and start it out with whatever ratio of 1s and 0s you want. You could use the random command on the variable and just use the first binary digit. I hope this helps. Check out the PBASIC help file for more about the RANDOM command.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    LOOKDOWN ThisThread, [noparse][[/noparse]Your_?, My_?, Cool_Thing], looknum
    LOOKUP looknum, [noparse][[/noparse]1, 2, 3], subnum
    ON subnum GOTO Hope_this_helps, Thanks!, WOW!!
    END 
    
  • Lithium_fun!Lithium_fun! Posts: 18
    edited 2007-09-15 14:16
    Thanks everybody, I got it working. Apparently I had to declare the variables like this:

    m1 VAR Word
    cc1 VAR m1.BIT0
Sign In or Register to comment.