' this programm reads photoresistor at pin 5,6 and 7 ' it also reads four collision switches at pin 4 ' separated by 1K resistors ' and emitts a motor signal at pin 0, 1, 2 and 3 ' pin0 = left motor fwd, pin1 = left motor back ' pin2 = right motor fwd, pin3 = right motor back ' (c)nab98 dirs=%00001111 'define ins and outs. 0=input 1=output pins=%00000000 'clear everything symbol p4=B8 'define some variables used for sampling symbol p5=B9 symbol p6=B10 symbol p7=B11 main: 'main loop ********* pot 7,36,p7 pot 6,36,p6 pot 5,36,p5 pot 4,255,p4 p5=255-p5: p6=255-p6: p7=255-p7 'invert pot photoresistor results 'evaluate collision switches 'method taken from application notes if p4<100 and p4>85 then driveback 'both front if p4<145 and p4>130 then uturnright 'left front if p4<50 and p4>35 then uturnleft 'right front if p4=0 then turnoff 'back (programmers convinence) if p5>p7 and p7>p6 then turnleft 'check for backlight if p5>p6 and p6>p7 then turnright if p6=p7 then drive 'evaluate frontlights if p6>p7 then kickleft if p7>p6 then kickright goto main 'driving functions kickleft: pin0=0: pin1=0: pin2=1: pin3=0: goto main kickright: pin0=1: pin1=0: pin2=0: pin3=0: goto main turnleft: pin0=0: pin1=1: pin2=1: pin3=0: nap 1: goto main turnright: pin0=1: pin1=0: pin2=0: pin3=1: nap 1: goto main drive: pin0=1: pin1=0: pin2=1: pin3=0: nap 2: goto main driveback: pin0=0: pin1=1: pin2=0: pin3=1: nap 7 'drive back and turn uturnleft: pin0=0: pin1=1: pin2=1: pin3=0: nap 7: goto main uturnright: pin0=1: pin1=0: pin2=0: pin3=1: nap 7: goto main turnoff: pin0=0: pin1=0: pin2=0: pin3=0: goto main