Shop OBEX P1 Docs P2 Docs Learn Events
Nee help with a code? — Parallax Forums

Nee help with a code?

randyleekrandyleek Posts: 4
edited 2010-01-15 01:41 in Learn with BlocklyProp
I am new here and a beginer. I'm trying to write a code that Random choses a output between two pins for 2 seconds, then returns back Low.·I think i have part figured out, just not the random part.
·Thanks for any help confused.gif

············ motor:· ·' my Sub

·············· Random· ?????????????·· 'I want pin 6 or 7 to high for 2 seconds and return low

························ Pause 2000
·························· low 6
·························· low 7

···················· Return

Comments

  • kf4ixmkf4ixm Posts: 529
    edited 2010-01-14 16:09
    try this, an excerpt from the help with the random statement·in basic stamp editor...
    result  VAR     WordMain:  result = 3                       ' set initial "seed" value   RANDOM result                         ' generate random number   DEBUG DEC ? result                    ' show the result on screen  GOTO Main
    




    then just assign a pin to go low if the number matches the result.

    Post Edited (kf4ixm) : 1/14/2010 4:14:22 PM GMT
  • randyleekrandyleek Posts: 4
    edited 2010-01-14 23:53
    maybe i was not quite clear.

    i have pins 6 & 7 at LOW.

    i want to make a call (gosub motor) and have the call RANDOM chose pin 6 or 7 and go HIGH 5v output for 2 seconds and return back LOW, and return from my call.
  • kf4ixmkf4ixm Posts: 529
    edited 2010-01-14 23:58
    randyleek said...

    maybe i was not quite clear.

    i have pins 6 & 7 at LOW.

    i want to make a call (gosub motor) and have the call RANDOM chose pin 6 or 7 and go HIGH 5v output for 2 seconds and return back LOW, and return from my call.

    OK, then just change the code above to high instead of low, then insert·it into your own code (gosub or whatever)·to do what you want it to, the random statement is well documented in the basic stamp editor help section. if you look at the code, the 'result' will be a number from 0-3, you can adjust this to how many states you want, then assign a pin name of a number in your declarations.

    Post Edited (kf4ixm) : 1/15/2010 12:06:33 AM GMT
  • randyleekrandyleek Posts: 4
    edited 2010-01-15 00:15
    so is this what u are saying?



    ···· motor:· ·' my Sub


    ·············· Random··· 'I want pin 6 or 7 to high for 2 seconds and return low
    ··················
    ···························High 6
    ···························High 7
    ······························· pause 2000

    ································ LOW 6
    ································ LOW 7
    ···················· Return
  • kf4ixmkf4ixm Posts: 529
    edited 2010-01-15 00:31
    ' {$STAMP BS2}
    ' -----[noparse][[/noparse] I/O Definitions ]-------------------------------------------------
    1 PIN 6   'assigns the name of 1 to pin 6
    2 PIN 7   'assigns the name of 2 to pin 7
    result VAR word
    main:
    result = 2
    RANDOM result
    HIGH result
    PAUSE 2000
    LOW result
    GOTO main
    
    

    this should get you close.

    Post Edited (kf4ixm) : 1/15/2010 1:41:18 AM GMT
  • randyleekrandyleek Posts: 4
    edited 2010-01-15 01:11
    Thanks
    I'm new to the basic stamp and pbasic. I love tinkering with electronics and am planning to get more serious. i've taking C++ for a while and enjoyed it.
    Again THANKS
  • kf4ixmkf4ixm Posts: 529
    edited 2010-01-15 01:41
    Anytime! be sure to check out the help in the basic stapm editor, it's very good at explaining commands and gives great examples.
Sign In or Register to comment.