'{$STAMP BS2} '------------------------------------------ 'testsm.bs2 ' 'This program tests the sound module hardware pause 500 serout 7,188+$8000,["!SM0I"] pause 500 serout 7,188+$8000,["!SM0N"] end pause 1000 serout 7,188+$8000,["!SM0P",0] end lightl var word 'Light level light0 var word 'Temp storage for getdl lightd var byte 'Light direction start: gosub getdl 'Get light direction debug lightd, cr 'Display result pause 1000 'Wait 1 second goto start 'Loop forever '------------------------------------------ 'getdl 'Reads the light level from 4 sensors and returns 'the direction as a letter stored in lightd. 'F=Front, B=Back, L=Left, R=Right getdl: lightd = "F" 'Initialize. 'Read Front sensor high 2 'Discharge cap pause 1 'Short delay rctime 2,1,lightl 'Capture light level 'Read Back sensor high 3 'Discharge cap pause 1 'Short delay rctime 3,1,light0 'Capture light level if light0 > lightl then getdl1 lightd = "B" lightl = light0 'Read Left sensor getdl1: high 4 'Discharge cap pause 1 'Short delay rctime 4,1,light0 'Capture light level if light0 > lightl then getdl2 lightd = "L" lightl = light0 'Read Right sensor getdl2: high 5 'Discharge cap pause 1 'Short delay rctime 5,1,light0 'Capture light level if light0 > lightl then getdl3 lightd = "R" lightl = light0 getdl3: return 'Done