hi , i have problem my project is robot follow people (tracking) by using pair of pololu IR becon ,but after download code on arduino , a robot does not move forward and back ,only Tire is move left and right ,anyone can help me please ,tick tock.
sorry i forgotten attaching code ,
this is my code i hope get help:
#include "ArduinoMotorShieldR3.h"
ArduinoMotorShieldR3 md;
#define NORTH A38
#define SOUTH A36
#define EAST A34
#define WEST A32
int NORTH =0;
int SOUTH =0;
int EAST =0;
int WEST =0;
void setup() {
Serial.begin(9600);
pinMode(NORTH,INPUT);
pinMode(SOUTH,INPUT);
pinMode(EAST,INPUT);
pinMode(WEST,INPUT);
md.init();
}
void loop() {
SCANDIRECTION();
WHICHDIRECTION();
delay(1000);
Serial.println(analogRead(A38));
Serial.println(analogRead(A36));
Serial.println(analogRead(A34));
Serial.println(analogRead(A32));
delay(2000);}
void WHICHDIRECTION( ){
if (NORTH < 900 && SOUTH > 500 && EAST > 500 && WEST > 500)
{ md.setSpeeds(200,200); }
else if (NORTH > 500 && SOUTH < 900 && EAST > 500 && WEST > 500)
{ md.setSpeeds(-200,-200);}
else if (NORTH > 500 && SOUTH > 500 && EAST < 900 && WEST > 500)
{ md.setSpeeds(200,0); }
else if (NORTH > 500 && SOUTH > 500 && EAST > 500 && WEST < 900)
{ md.setSpeeds(0,200); }
}
void SCANDIRECTION(){
NORTH = analogRead(A38);
SOUTH = analogRead(A36);
EAST = analogRead(A34);
WEST = analogRead(A32);}
You have posted code without using code tags. The code tags make the code look
like this
when posting source code files. It makes it easier to read, and can be copied with a single mouse click. Also, if you don't do it, some of the character sequences in the code can be misinterpred by the forum code as italics or funny emoticons.
If you have already posted without using code tags, open your message and select "modify" from the pull down menu labelled, "More", at the lower left corner of the message. Highlight your code by selecting it (it turns blue), and then click on the "</>" icon at the upper left hand corner. Click on the "Save" button. Code tags can also be inserted manually in the forum text using the code and /code metatags.
There are many other things that programmers do to make their code understandable. Please do them, as a courtesy to the members who volunteer their time to help you here. One is to use a standard indentation to clearly show the code blocks. Never put more than one statement per line. Place any brackets by themselves on a separate line. Before posting the code, use Ctrl-T in the IDE to reformat the code in a standard format, which makes it easier for us to read.
Another is to give things descriptive names. You can name numerical constants, pin numbers, variables and many other things in this way. For example, you can refer to a pin and an output level by number, like digitalWrite(3,0)
. But such a statement doesn't reveal anything about the purpose. digitalWrite(hornRelayPin, LOW)
does. You can do that by declaring const byte hornRelayPin = 3;
before setup() in your program.
What is NORTH? Is it a pin number or a reading from a pin?
#define NORTH A38
Does a text substitution so that when you say
int NORTH =0;
it means
int A38 =0;
All subsequent uses of the symbol NORTH refer to the int variable. Thus when you say
pinMode(NORTH,INPUT);
you are saying
pinMode(0,INPUT);
GypsumFantastic:
What is NORTH? Is it a pin number or a reading from a pin?
That is the problem. The program attempts to use it for both.