Thursday, June 3, 2010

Using a Variable to Count

Until now you've had to write each new number you want the LED to display as it counts to 10. If you wanted it to count higher this would start to get tedious. To avoid the tedium you can use a variable. It is similar to a variable in algebra in that you use a name that stands for a value that can be changed.

Here is how:

global [number] ;this creates a variable and names it

to count

setnumber 1 ;this sets the value of the variable
repeat 10 [
display number ;this displays the current value of the variable
wait 5
setnumber number + 1 ;this sets the value again, adding one to the current value

No comments: