program lightscan { /* Things 2 note 1. having a small gear drive a bigger gear removes power but increases speed so much so the tank went no where 2. Stopping one track and just using the other to steer does not work to much drag. 3. need more power, full stop fixed turning be trotating both track in opisite directions */ sensor SCAN on 3 SCAN is light as percent // the scanning light sensor GREY on 2 // the light switch GREY is switch as boolean // grey are we looking 4 lite or dark? output LEFTMOTOR on 1 // port A output RIGHTMOTOR on 3 // port C // global var for holding current greymode var GREYMODE = 0 // 0 = light, 1 = dark seeking // global var 4 holding current light reading var LASTSCAN = 50 // set at 50% macro MOVEFORWARD { // crank up the motors forward [LEFTMOTOR RIGHTMOTOR] on [LEFTMOTOR RIGHTMOTOR] for 250 } macro TURNLEFT ( TIMEON ) { forward [RIGHTMOTOR] backward [LEFTMOTOR] on [LEFTMOTOR RIGHTMOTOR] for ( TIMEON * 10 ) } macro TURNRIGHT ( TIMEON ) { forward [LEFTMOTOR ] backward [RIGHTMOTOR] on [LEFTMOTOR RIGHTMOTOR] for ( TIMEON * 10 ) } macro LIGHTSWITCH { if GREYMODE = 0 { GREYMODE = 1 } else { GREYMODE = 0 } tone 8000 for 20 wait 25 tone 7000 for 20 wait 25 tone 6000 for 20 wait 25 tone 5000 for 20 wait 25 tone 4000 for 20 wait 25 tone 5000 for 20 wait 25 tone 6000 for 20 wait 25 display GREYMODE //stop tasks } macro COMPLETE { tone 1000 for 20 wait 25 tone 2000 for 20 wait 25 tone 3000 for 20 wait 25 tone 4000 for 20 wait 25 tone 5000 for 20 wait 25 tone 4000 for 20 wait 25 stop tasks } // setup an event for when the button is pressed to change modes event BUTTONHIT when GREY.released main { // initialise motors without turning them on forward [LEFTMOTOR RIGHTMOTOR] power [LEFTMOTOR RIGHTMOTOR] 5 // nice and slow start BUTTONCHECK forever { wait 30 display SCAN if GREYMODE = 0 { if SCAN > 90 { COMPLETE } if LASTSCAN < SCAN { MOVEFORWARD TURNRIGHT(5) } else { TURNLEFT(10) } } else { if SCAN < 35 { COMPLETE } if LASTSCAN > SCAN { MOVEFORWARD TURNRIGHT(5) } else { TURNLEFT(10) } } LASTSCAN = SCAN } } // end of main watcher BUTTONCHECK monitor BUTTONHIT { LIGHTSWITCH } } // end of program