Hello All,
I built a robot using the 08M2 chip. I have a write up on it on this website: [URL="http://letsmakerobots.com/node/8408"/URL]
It ran ok with the original code but I wanted to update it. Here is the updated code:
'****************************
If you look at the IR: code there are 3 storage locations. I am looking at b0 & b2 to compare readings. I would like to look at b0, b1, b2 to select the best path to take. I am having trouble writing anything that will work. Anyone have any suggestions how to accomplish this?
Thanks for any help!
-Gary
I built a robot using the 08M2 chip. I have a write up on it on this website: [URL="http://letsmakerobots.com/node/8408"/URL]
It ran ok with the original code but I wanted to update it. Here is the updated code:
'****************************
Code:
'Robot#2_R1.bas
'Picaxe 08M2 MicroProcessor
'I/O Pins
'Servo = Output 0
'IR Sensor = ADC Input 1
'Motor Control = Output 2,4
'Motor Forward = high 2: low 4
'Motor Reverse = high 4: low 2
'Motor Stop = low 2: low 4
'Servo 80 = Rotate Left
'Servo 175 = Center
'Servo 250 = Rotate Right
'*****************************
'** Directives
#picaxe 08m2 '08m2 Chip
#com 3 'Com Port
init:
servo 0,175 'Center Servo
pause 100
main:
low 2: low 4 'Motor Stop
pause 150
gosub ir
high 2: low 4 'Motor Forward
do
readadc 1, b3
pause 50
high 2: low 4 'Motor Forward
pause 200
if b3 > 90 then
exit
endif
loop
goto main
'-----------------------------------------------
ir:
servopos 0,80 'Look Left -60 deg
pause 250
readadc 1, b0 'Read IR store at b0
pause 50
servopos 0,175 'Look Straight Ahead 0 deg
pause 250
readadc 1, b1 'Read IR store at b1
pause 50
servopos 0,250 'Look Right +60 deg
pause 250
readadc 1, b2 'Read IR store at b2
pause 50
servopos 0,175 'Servo = Center
pause 250
if b0 => b2 then
goto LTurn
else
goto RTurn
endif
return
LTurn:
servopos 0,250
pause 250
high 4: low 2 'Motor Reverse
pause 750
servopos 0,175 'Servo = Center
pause 250
high 2: low 4 'Motor Forward
pause 500
return
NoTurn:
servopos 0,175 'Servo = Center
pause 250
high 2: low 4 'Motor Forward
pause 500
return
RTurn:
servopos 0,80
pause 250
high 4: low 2 'Motor Reverse
pause 750
servopos 0,175 'Servo = Center
pause 250
high 2: low 4 'Motor Forward
pause 500
return
Thanks for any help!
-Gary
Last edited: