I have been using the arduino for a while now, and figured I would try the picaxe. It seemed that the picaxe would be like the arduino coding except in basic, but I guess I'm just not getting it. I have a simple robot with two motors and an ir detector. I know all of the above works because I double checked them on an arduino, so the problem lie in my coding.
Its not so much my coding isn't working, as it isn't doing what I want. I have an h-bridge connected to the picaxe controlling two motors. These are the pins for the current setup:
Picaxe 20x2 (Based on page 27 of manual #1)
Pin 18 - IR Detector
Pin 17 - Motor 1 Forwards
Pin 16 - Motor 1 Backwards
Pin 15 - Motor 2 Forwards
Pin 14 - Motor 2 Backwards
I then wrote this program for this bot:
When this did not work (motors were working, but not when they were supposed to) I tried smaller programs just to see what pin was which. I tried the following:
With several different numbers of course. I then tried to use 17 to 14 but the programmer says that these pins do not exist on a 20x2. I've done reading in all three manuals but I have yet to figure out why this is not working. I know it has to be the way I am using my pins, but I do not know in what way.
The more I read I guess I am supposed to use portb 1 to portb 4? When I was looking at the 28x2 information it says all of it's ports are fixed as output only, so I guess if that is true for the 20x2 as well, then I'm going to have to move the IR input to another pin...or all of my stuff to port c?
So just to sum this post up my two questions are:
How do I use the pins in my code?
Do I have to move everything?
Its not so much my coding isn't working, as it isn't doing what I want. I have an h-bridge connected to the picaxe controlling two motors. These are the pins for the current setup:
Picaxe 20x2 (Based on page 27 of manual #1)
Pin 18 - IR Detector
Pin 17 - Motor 1 Forwards
Pin 16 - Motor 1 Backwards
Pin 15 - Motor 2 Forwards
Pin 14 - Motor 2 Backwards
I then wrote this program for this bot:
Code:
main:
readadc 1,b0
if b0>200 then
gosub m_forward
pause 100
else
gosub m_stop
pause 10
gosub m_reverse
pause 100
gosub m_stop
pause 10
gosub m_right
pause 100
gosub m_stop
pause 10
if b0>200 then
goto main
else
gosub m_left
pause 200
gosub m_stop
pause 10
if b0>200 then
goto main
else
gosub m_left
pause 100
gosub m_stop
pause 10
goto main
endif
endif
endif
goto main
m_stop:
low 1
low 2
low 3
low 4
return
m_forward:
high 1
low 2
high 3
low 4
return
m_reverse:
low 1
high 2
low 3
high 4
return
m_right:
low 1
high 2
high 3
low 4
return
m_left:
high 1
low 2
low 3
high 4
return
Code:
main:
high b.1
pause 10000
low b.1
goto main
Code:
main:
high b1
pause 10000
low b1
goto main
The more I read I guess I am supposed to use portb 1 to portb 4? When I was looking at the 28x2 information it says all of it's ports are fixed as output only, so I guess if that is true for the 20x2 as well, then I'm going to have to move the IR input to another pin...or all of my stuff to port c?
So just to sum this post up my two questions are:
How do I use the pins in my code?
Do I have to move everything?