Shop OBEX P1 Docs P2 Docs Learn Events
How to have Pause as a Random Amount of Time and have OutPut also Random — Parallax Forums

How to have Pause as a Random Amount of Time and have OutPut also Random

sam_sam_samsam_sam_sam Posts: 2,286
edited 2006-11-01 21:30 in General Discussion
Hi, EveryOne
I would like to have some· idea.gif·on how to do this

I am at it again

I·want to learn how to have·PAUSE VALUE·for a·RANDOM amount of·TIME

Is there an easy way to this

I did look in the BS2 files and found an example of using random command but that will not work for what i want to
I also look in Stamp's online help and examples do not help me·any

I don't think it will


I also look in· Fourm Search and did not find an example that i could use

This is what i have in mind

Pause Values are as follows this is only an example here

·The more Random the Better I would also like to not repeat the same routine over and over

I would also like to make the outputs to be·random· as well if this can be done

DO
toggle 8
Pause 100 ' This lowest value
toggle 9
Pause 500
toggle 10
Pause 1000
toggle 11
Pause 200
toggle 12
Pause·120
toggle 13
Pause·1500
toggle 14
Pause· 65535 The max value
toggle 15
Loop

Toggle 15,9,12,8,11,14,9,13 and so on

I know that i could write it·this way·but it would keep repeating in the same order·and that is not what i am looking for

I hope that some out on the Forum can give an example how do this
Thanks to any one that can help in this matter

Sam

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2006-11-01 02:39
    The RANDOM statement is what you want to use.· It uses a word variable and changes the value of the variable in a pseudo-random fashion each time it's executed.· You can use the word variable as the amount for the PAUSE statement to wait.· To take care of the case where the value is less than 100, you can just repeat the RANDOM like:

    [noparse][[/noparse]code]

    z···· VAR·· WORD

    100 RANDOM z

    ····· IF z < 100 THEN 100

    ····· PAUSE z

    ····· ' Anything else you want after the pause

    [noparse][[/noparse]/code]
  • sam_sam_samsam_sam_sam Posts: 2,286
    edited 2006-11-01 05:24
    Mike Green

    Thank You for your Post This helps alot

    This is what i came up with i am not able to·test this·tonight but i will test it soon

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

    Z··· VAR··· Word
    Y··· VAR··· Byte
    x··· VAR··· Word
    s··· VAR··· Byte

    RANDOM Z : RANDOM Y : RANDOM X : RANDOM S

    DO

    TOGGLE 8
    PAUSE Z
    TOGGLE 9
    PAUSE Y
    TOGGLE 8
    PAUSE X
    TOGGLE 9
    PAUSE S

    IF Z· OR· X· < 100 THEN
    x = 500
    z = 800
    ENDIF

    IF y· OR· s· < 50 THEN
    y = 100
    s = 150
    ENDIF

    LOOP

    I tried to write it the way you had wrote the routine but it would not complie it·so worte this

    Can you tell if this writen the right way

    ·Sam
  • Mike GreenMike Green Posts: 23,101
    edited 2006-11-01 05:44
    I don't think your code will do what you want. First of all, the four RANDOM statements will
    produce the same results because they're "pseudo-random". They produce a sequence that's
    reproducible, but behaves statistically as if it were random (by using a linear feedback shift
    register). Since you're starting all four with zero, the two word variables will be the same and
    the two byte variables will be the same.
    Sorry for the coding error. I was thinking of standard Basic, not PBasic.
    Z    VAR    Word
     
    DO
      DO
        RANDOM Z
      LOOP WHILE Z < 100  ' This makes sure Z is 100+
      TOGGLE 8 : PAUSE Z
      DO
        RANDOM Z
      LOOP WHILE Z < 100  ' This gets us a 2nd random number 100+
      TOGGLE 9 : PAUSE Z
    LOOP
    
    
  • sam_sam_samsam_sam_sam Posts: 2,286
    edited 2006-11-01 21:30
    Mike Green

    Thanks for your post.
    That help me alot to understand how to use the RANDOM command.
    I will try this over the weeken .

    I bought these Christmas Candy Cane from Kmart
    They just have plain lights in them

    I thought that it would be cool to have them blink ON and OFF randomly all eight of them at different times

    Yes i know your going to tell that i have to much time on my hands

    This is what my wife tell me but i say that am going to learn something
    by doing this project


    Sam
Sign In or Register to comment.