The Programming

 

menu 1 [captain_planet] ;general prgm
menu 2 [black+10] ; calibration to tape on table
menu 3 [black-10]
;menu 4 [cp] ; tests sensor settings
menu 5 [dump] ; tests gate
;menu 6 [plastictest]

global [black amb-light dot]

; sensor 0 = photo sensor
; sensor 1 = IR reflectance sensor
; sensor 2 = LED
; motor b = gate
; motor c = wheels

to captain_planet
loop [
setdot 1 ; resets dot to 1 to correct for double-counting at end
waituntil [switch 7] ; prevents confusion from shadows
if plastic? [ plastic-dump ]
if glass? [ glass-dump ]
if metal? [ metal-dump ]
]
end

to plastic?
output (and ((sensor 0) > 13) ((sensor 0) < 40))
;value between the metal and glass.
end

to glass?
output (and ((sensor 0) > 9) ((sensor 0) < 12))
end

to metal?
output (sensor 0) > 50
end

to plastic-dump
wait 10
; so it doesn't start moving when you're still putting it in
go-right
; 'when' provides enough concurrency so 'forever' is unnec.
add-dot

waituntil [dot = 2]
stoprules
stop-motor
dump
go-home
end

to glass-dump
wait 10
go-right
add-dot
waituntil [dot = 3]
stoprules
stop-motor
dump
go-home
end

to metal-dump
wait 10
go-right
add-dot
waituntil [dot = 4]
stoprules
stop-motor
dump
go-home
end

to sees-black-tape?
output ((sensor 1) > black)
end

to add-dot
when [sees-black-tape?][setdot (dot + 1)] ; edge-triggering to prevent multiple readings of one piece of tape
print (dot)
end

to subtract-dot
when [sees-black-tape?][setdot (dot - 1)] ; ditto
print (dot)
end

to open-gate
setpower 10
b, onfor 5 thatway
end

to close-gate
setpower 10
b, onfor 20 thisway ; makes sure that gate closes all the way
end

to dump
open-gate
wait 5 ; makes it possible for object to fall
close-gate
end

to go-right
c, on thisway
end

to go-left
c, on thatway
end

to go-home
go-left ; need concurrency so it will move & count simul
subtract-dot
waituntil [dot = 0] ; setting to 0 corrects double-counting problem
stoprules
stop-motor
end

to stop-motor
c, off
end

to black+10
setblack black + 10
printblack
end

to black-10
setblack black - 10
printblack
end

to printblack
type [black=] print black
end

 

HOME | THE IDEA | THE MECHANICS| THE PROGRAMMING | IN ACTION | THE PLANETEERS | RDS HOMEPAGE


Created by: Linda Fung and Catherine Lee
January 2007
Background image from: www.lancashire.gov.uk/
Background music from: Captain Planet