Shop OBEX P1 Docs P2 Docs Learn Events
Counter, LED light up and Random numbers, and Servo motor codes — Parallax Forums

Counter, LED light up and Random numbers, and Servo motor codes

shakerlax1shakerlax1 Posts: 2
edited 2014-10-09 22:39 in BASIC Stamp
Hi all,

Here are a couple of programs i need to write and am having trouble with.

-Counter starts from 1 and when it gets to 10 display this number with debug. Then when the counter reaches 20 display 20 random numbers between 1 and 20. When the program reaches 30 stop the program.

-3 dice are rolled, if the number six appears one led will light up. If two six's appear two leds will be lit up. If three sixes appear then three leds will be lit up. Using the RANDOM command to generate the dice output. Also declare the pins in which each led is connected to (red led, green led, blue led).

-Program that turns a servo motor to 10degrees, 25, 40, 70, 90, 115, 135, 150, and 180

Comments

  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2014-10-09 16:59
    Can you post what you have so far?
  • GenetixGenetix Posts: 1,749
    edited 2014-10-09 17:13
    shakerlax1 wrote: »
    Hi all,

    Here are a couple of programs i need to write and am having trouble with.

    -Counter starts from 1 and when it gets to 10 display this number with debug. Then when the counter reaches 20 display 20 random numbers between 1 and 20. When the program reaches 30 stop the program.

    -3 dice are rolled, if the number six appears one led will light up. If two six's appear two leds will be lit up. If three sixes appear then three leds will be lit up. Using the RANDOM command to generate the dice output. Also declare the pins in which each led is connected to (red led, green led, blue led).

    -Program that turns a servo motor to 10degrees, 25, 40, 70, 90, 115, 135, 150, and 180

    For the 1st and 3rd refer to here:
    http://www.parallax.com/sites/default/files/downloads/28123-Whats-a-Micro-v3.0.pdf
    Chapter 4 is on Servo motion

    There is something similar to the 2nd here:
    http://www.parallax.com/downloads/stampworks-experiment-kit-manual

    Reference this for any commands that you don't understand.
    http://www.parallax.com/downloads/basic-stamp-manual
  • shakerlax1shakerlax1 Posts: 2
    edited 2014-10-09 17:53
    So here is what i have on the first one but i want to have 20 random numbers and am only getting one. Everything else is working fine

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


    counter VAR BYTE
    numbers VAR WORD
    randomnumbers VAR BYTE


    FOR counter = 1 TO 30


    IF (counter = 10) THEN
    DEBUG ? counter


    elseIF (counter = 20) THEN
    RANDOM numbers
    randomnumbers = (numbers // 21) +1
    DEBUG ? randomnumbers


    elseif (counter = 30) THEN
    ENDif


    NEXT


    endprogram:


    END
  • GenetixGenetix Posts: 1,749
    edited 2014-10-09 22:39
    The RANDOM command only gives a number when it's called so if you want 20 numbers then you need to call it 20 times. You can do this by placing a FOR...NEXT loop in your 2nd IF...THEN statement. Just be sure to use a different counter variable.
    [FONT=arial]elseIF (counter = 20) [B]THEN ' When Counter reaches 20[/B][/FONT]
    [FONT=arial][B]  FOR temp = 1 to 20 ' Generate 20 random numbers
        RANDOM[/B] numbers[/FONT]
    [FONT=arial][B]    DEBUG[/B] ? randomnumbers ' Display each in the DEBUG Window
      [B]NEXT[/B][/FONT]
    

    .
Sign In or Register to comment.