// Created 1/4/99 12:05:10 PM int rotate //rotation sensor variable int testvar //a test variable int leftmax //hold the number positive turn int rightmax //hold the number neg turn int radar //one equal radar on int ping //tell me the lught sensor value int pingone //hold ping value int pingtwo //hold ping value int pingthree //hold ping value int pingfour //hold ping value int proximity //senstivity int countdown // should I stop int urstuck //if this reaches 100 change direction setsensortype 2 5 //sensor two is a rotation sensor setsensortype 3 4 //sensor three is a light sensor beginsub tada playtone 262 20 playtone 440 20 playtone 392 20 playtone 523 40 playtone 440 20 playtone 523 80 endsub beginsub reverse readsensor rotate 2 motortoggle a wait 50 motortoggle a endsub beginsub center readsensor rotate 2 while rotate ! 0 readsensor rotate 2 if rotate < 0 motorreverse c motoron c wait 5 motoroff c else motorforward c motoron c wait 5 motoroff c endif endwhile motoroff c endsub beginsub rightforward //also leftbackward readsensor rotate 2 while rotate < rightmax motorreverse c motoron c readsensor rotate 2 endwhile motoroff c endsub beginsub leftforward //also rightbackward readsensor rotate 2 while rotate > leftmax motorforward c motoron c readsensor rotate 2 endwhile motoroff c endsub beginsub pinger set countdown 0 set pingone 0 set pingtwo 0 set pingthree 0 set pingfour 0 sendmessage 255 readsensor ping 3 set pingone ping sendmessage 255 readsensor ping 3 set pingtwo ping sendmessage 255 readsensor ping 3 set pingthree ping sendmessage 255 readsensor ping 3 set pingfour ping //build the average set ping 0 inc ping pingone inc ping pingtwo inc ping pingthree inc ping pingfour div ping 4 inc ping proximity endsub begintask 3 while radar = 1 inc urstuck 1 gosub pinger if pingone > ping inc countdown 1 endif if pingtwo > ping inc countdown 1 endif if pingthree > ping inc countdown 1 endif if pingfour > ping inc countdown 1 endif if countdown = 1 set urstuck 0 playtone 220 20 motorforward a gosub leftforward wait 50 gosub center motorreverse a endif wait 20 if urstuck > 100 playtone 420 20 motorforward a gosub rightforward wait 50 gosub center motorreverse a set urstuck 0 endif endwhile endtask BeginTask 2 starttask 3 motorsetpower abc 8 motorreverse a motoron a EndTask BeginTask 1 set radar 1 set rightmax 35 set leftmax 0 dec leftmax 35 set proximity 0 inc proximity 10 set countdown 0 StartTask 2 EndTask