;; Jerry Day 5

;; this is all programming by Julie and Katie, last modified 1/23/01

global [roomlight time carpet]

to jerry



end

to initiate
print "initiate
setroomlight (right-eye + left-eye + rightlight + leftlight + taillight) / 5
setcarpet linesense
end

to pikasong
print "pikasong
note 72 3 note 84 3 note 79 3
end


to scream
print "scream
note 96 1 note 90 1 note 96 1 note 90 1
note 96 1 note 90 1 note 96 1 note 90 1
note 96 1 note 90 1 note 96 1 note 90 1
note 82 .5 note 81 .5 note 80 .5
end

to runfromlight1
print "runfromlight1
loop [if (sensor 0) < 20 [a, on scream] a, off]
end

to run
print "run
left-wheel on thisway
right-wheel on thisway
end

to stopmotion
print "stopmotion
left-wheel off 
right-wheel off
end

to backup
print "backup
left-wheel on thatway
right-wheel on thatway
end

to makefastleft
print "makefastleft
left-wheel on thatway
right-wheel on thisway
end

to makeshortfastleft
print "makeshortfastleft
left-wheel onfor 5 thatway
right-wheel onfor 5 thisway
end

to makefastright
print "makefastright
right-wheel on thatway
left-wheel on thisway
end

to makeshortfastright
print "makeshortfastright
right-wheel onfor 5 thatway
left-wheel onfor 5 thisway
end

to slowright
print "slowright
left-wheel on thisway
right-wheel off
end

to slowleft
print "slowleft
right-wheel on thisway
left-wheel off
end

to smallslowright
print "smallslowright
left-wheel onfor 10 thisway
right-wheel off
end

to smallslowleft
print "smallslowleft
right-wheel onfor 10 thisway
left-wheel off
end

to tailwag
print "tailwag 
loop[c, onfor 5 thisway
c, onfor 5 thatway]
end

to shorttailwag
print "shorttailwag
repeat 4 [c, onfor 5 thisway
c, onfor 5 thatway]
end



to left-wheel
a,
end

to right-wheel
b,
end

to follow-light
print "follow-light
initiate ;; GET RID OF THIS IN FINAL
forever [frontbumper?] ;; DITTO
loop [if ((roomlight - left-eye) > 30) [slowleft]
if ((roomlight - left-eye) < 30) [left-wheel off]
if ((roomlight - right-eye) > 30) [right-wheel on]
if ((roomlight - right-eye) < 30) [right-wheel off]]
end

to leftlight?
initiate
print "leftlight?
forever [frontbumper?]
loop [top print roomlight bottom print leftlight
if (roomlight - leftlight) > 30
[slowleft waituntil [(roomlight - left-eye) > 30] 
follow-light]
]
end

to rightlight?
print "rightlight?
initiate
loop [top print roomlight bottom print leftlight wait 1
if (roomlight - leftlight) > 30 
[slowright waituntil [(roomlight - right-eye) > 30]
follow-light]]
end

to taillight?
print "taillight?
loop [if (roomlight - taillight) > 30 [slowleft
waituntil [(roomlight - leftlight) >30] 
leftlight?]]
end

to linesense? ; should work well, but battery dead 11-; 23-01
print "linesense?
initiate
run
forever [frontbumper?]
loop [
if (carpet - linesense) > 30 [backup wait 10 makefastright wait random 10 run]]
end

to frontbumper? ; works well
print "frontbumper?
loop [if (frontbumper = 1) [backup scream makefastright wait 10 run]]
end







;; sensors

to left-eye ; light sensor
output sensor 6
end

to right-eye ; light sensor
output sensor 5
end

to rightlight ; light sensor
output sensor 4
end

to leftlight ; light sensor
output sensor 3
end

to taillight ; light sensor
output sensor 2
end

to linesense ; reflectance sensor
output sensor 1
end

to nose ; reflectance sensor 
output sensor 0 
end

to frontbumper ; touch sensor
output switch 10
end

to burp
note 40 6
note 42 1
note 43 1
note 47 1
note 50 1
note 55 1
note 60 1
note 70 1
end


to bedrunk
forever [if (frontbumper = 1)
[backup
waituntil [frontbumper = 0]
makeshortfastleft]
]

loop [smallslowright
smallslowleft
burp 
shorttailwag]

end

;;

control buttons =
leftlight?
follow-light
frontbumper?
follow-light
bedrunk
shorttailwag