The Program. '********************************************** ' b0 = variable for right servo pin = 0 ' b1 = variable for left servo pin = 1 ' Piezo speaker pin = 2 ' ' b6 = variable for right eye pin = 6 ' b7 = variable for left eye pin = 7 ' '********************************************** Symbol counter = b4 ‘ Counter Symbol Reye = b6 ‘ Right Eye Symbol Leye = b7 ‘ Left Eye Symbol LwSig = b3 ‘ Low Signal of light. '********************************************** Init: pins = 0 ‘ Initialize. dirs = %00001111 LwSig = 255 gosub Start ‘ PART 1 ****** Find Bright Spot ************* ‘ ******* Then Point there ************ FindHigh: gosub spin ‘ Normal fwd speed gosub ReadE ‘ Read eyes counter = counter + 1 ‘ Inc. counter if counter > 90 then Find ‘ Complete 1 spin? if Reye = LwSig then MoreLt ‘ At bright spot? goto ContFnd MoreLt: LwSig = Reye ‘ Save location of high goto Continue Find: if Reye = LwSig then Follow ‘ At Bright Spot? goto Continue ContFnd: gosub Pulse goto FindHigh ‘PART 2 ********* Follow Light ****************** Follow: gosub ReadE ‘ Read eyes gosub Forward ‘ Normal fwd speed if Reye > Leye then TrnRt if Leye > Reye then TrnLt goto Continue ‘ If eyes are equal TrnRt: gosub Right ‘ Cut right servo speed goto Continue TrnLt: gosub Left ‘ Cut left servo speed goto Continue Continue: gosub Pulse goto Follow '********* SUBROUTINES ************** ReadE: pot 6,255,b6 ‘ Read right CDS cell pot 7,200,b7 ‘ Read left CDS cell b6 = b6 / 16 ‘ Make it smaller bb7 = b7 / 16 return Pulse: b0 = 125+b0 ‘ Adjust for + = forward. b1 = 128-b1 ‘ Adjust for + = forward pulsout 0,b0 ‘ right servo pulsout 1,b1 ‘ left servo return Forward: b0 = 50 ‘ Normal forward speed b1 = 50 ‘ Normal forward speed return Spin: b0 = 10 ‘ Spin the bot b1 = -10 ‘ Spin the bot return Right: b0 = 2 ‘ Slow to turn right return Left: b1 = 2 ‘ Slow to turn left return Sing: sound 2,(60,15,75,15,90,15,60,30) return ‘ Make a sound Start: gosub sing ‘ Sing a song gosub sing gosub sing pause 1000 return As you can see this code is broken into two parts. The first part of the program spins the robot 180 degrees , takeing a sensor reading each step. The program remebers the location of the brightest spot. After the first full spin, the robot, the robot continues to spin until it reaches the location of the brightest spot. The second part of the code allows the robot to follow the sensor with the brightest light on it. If the two sensors are equal, then the robot just goes forward. It may surprise you that this code compiles down to about 100 bytes of code space in the BASIC Stamp.