'>KasTomToeP08m2 'setfreq m8 '@8MHz serrxd,sertxd @9600, PAUSE is 0.5ms 'setfreq m16 '@16MHz serrxd,sertxd @19200, PAUSE is 0.25ms setfreq m32 '@32MHz serrxd,sertxd @38400, PAUSE is 0.125ms SERTXD("KasTomToeP08m2.bas",CR) 'report program 'Joe,Kas,Tom are all the same except Joe has PAUSE 1 ** and Tom,Kas PAUSE 2 #PicAxe 08m2 'Memory used = 154 bytes out of 2048 #no_data #rem _ _ +V| V |0v Ground_lat I,Si,C.5| |C.0,O,So LED Tr Ground_med TAOI,C.4| |C.1,IOAT Whisker In 100k pullup Bump wire I,C.3|___|C.2,IOATpt SERIN/SEROUT Whisker - LED - Kingbright L-7113SEC-H 5mm Red/Orange LED 10000mcd Whisker - standard IR phototransistor Bump 4k7 pullup, Whisker 100k pullup, Ser to BS2 200R in series Key - Analog, In, Out, Touch, pwm, tune #endrem PIN_MAPPING: 'C.0 serin SYMBOL OLED_Tr =C.0 SYMBOL Awhisker =C.1 SYMBOL SerFromBS2 =C.2 SYMBOL BS2Rdy =C.2 SYMBOL BS2Rdypin =pin2 SYMBOL SerToBS2 =C.2 SYMBOL Ibump_ =pin3 SYMBOL Iground_med =C.4 SYMBOL Iground_lat =C.5 Rationale: 'Wait for "T" or "B" '================================================================= VARIABLES_and_CONSTANTS: SYMBOL tempW0 =W0 SYMBOL temp0 =B0 SYMBOL tempLo =B0 SYMBOL temp1 =B1 SYMBOL f_flags =B2 SYMBOL Ttoe =B3 '================================================================= INITIALISE: SERTXD("INITIALISE",CR) HIGH C.0 'blink 3 times so we know Toes are alive PAUSE 80 LOW C.0 PAUSE 800 HIGH C.0 PAUSE 80 LOW C.0 PAUSE 800 HIGH C.0 PAUSE 80 LOW C.0 PAUSE 800 START: 'goto test SERIN SerFromBS2,N9600_32,temp1 'wait for ready IF temp1="B" THEN BumpToes IF temp1="T" THEN TwinkleToes GOTO START BumpToes: 'temp1="B" LOW OLED_Tr 'in case it was high from obstacle LOW SerToBS2 'idle level PAUSE 16 '2ms for BS2 to turn round Ser Ttoe =0 'initialise no Twinkletoe return IF Ibump_=0 THEN :Ttoe =1 ENDIF SEROUT SerToBS2,N9600_32,(Ttoe) 'sertxd(temp1,#Ttoe) 'IF Ttoe=0 THEN START 'test 'HIGH OLED_Tr 'test 'indicated an obstacle GOTO START TwinkleToes: 'temp1="T" LOW OLED_Tr 'in case it was high from obstacle LOW SerToBS2 'idle level PAUSE 16 '2ms for BS2 to turn round Ser 'sertxd(" ",temp1) Ttoe =0 'initialise no Twinkletoe return readadc C.1,b4 'sertxd("b4=",#b4,",") HIGH OLED_Tr pause 2 'Joe 1 ** readadc C.1,b5 LOW OLED_Tr 'sertxd("b5=",#b5,",") IF b4>b5 THEN Ttoe =b4 -b5 ENDIF Ttoe =Ttoe *8 /b4 'sertxd("T=",#Ttoe,13) SEROUT SerToBS2,N9600_32,(Ttoe) IF Ttoe=0 THEN START HIGH OLED_Tr 'indicated an obstacle GOTO START test: SEROUT SerToBS2,N9600_32,("T") HIGH OLED_Tr readadc C.1,b5 LOW OLED_Tr pause 1000 goto test