Counter, LED light up and Random numbers, and Servo motor codes
shakerlax1
Posts: 2
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
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
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
'{$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
.