Monday, December 21, 2009

Switch-Operated Elevator

Two of my 9th grade students created this elevator. It raises up at the press of a switch, then waits for another press before descending. The motors also gear down for increased torque.

Saturday, December 12, 2009

Ways to Program a Loop

If you need a switch to work repeatedly when you run its program, you need to loop it. Here are some ways depending on exactly how you want them to work:
;this strategy repeats indefinitely
to main
loop
[commands to loop]
end

;this strategy makes the program run itself indefinitely
to main
commands to loop
main
end

;this strategy repeats the commands many times
to main
repeat 100
[commands to loop]
end

Many Ways to Program Switches

;simplest way, one switch
to go
waituntil [switcha = 1]
motor commands
waituntil [switcha = 1]
more motor commands
end

;another way, one switch
to go
if switcha = 1
[motor commands]
if switcha = 0
[more motor commands]
end

;another way, one switch
to go
ifelse switcha = 1
[motor commands]
[more motor commands]
end

;two switches!
to go
if switcha = 1
[motor commands]
if switchb = 1
[more motor commands]
end