Code

global [color]

 

to difference

output (color - (sensor 6))

end

 

to print-loop

setcolor (sensor 6)

loop [print difference]

end

 

to setthreshold

setcolor (sensor 6)

bottom type color top

beep

end

 

to sort

setthreshold

forever [test-candy]

forever [print difference wait 1]

end

 

to test-candy

waituntil [difference > 3]

wait 20 ; wait for reading to stabilize

kisses

reeses

snickers

end

 

to kisses

if (and (difference > 3) (difference < 20))

[dump

setthreshold]

end

 

to reeses

if (and (difference > 20) (difference < 90))

[goright

dump

returnright

setthreshold]

end

 

to snickers

if (not (difference < 90))

[goleft

dump

returnleft

setthreshold]

end

 

to goright

b, thisway onfor 22

end

 

to returnright

b, thatway onfor 22

end

 

to goleft

b, thatway onfor 22

end

 

to returnleft

b, thisway onfor 22

end

 

to dump

a, on thatway

waituntil [switch 7]

waituntil [not (switch 7)]

a, off

end

Back to Home