pls help.......hbridge control with respect to binary inputs.

Please help.

The forward loop in the code is not working.
If i can correct forward loop,i can use the same method for the other three cases.

The code is for taking binary inputs 0001,0010,0011 & 0100 and to run a remote controlled car.

// Use this code to test your motor with the Arduino board:

// if you need PWM, just use the PWM outputs on the Arduino
// and instead of digitalWrite, you should use the analogWrite command

// —————————————————————————  Motors
int motor_left[] = {2, 3};
int motor_right[] = {7, 8};
int ledPin =  13;    // LED connected to digital pin 13

// ————————————————————————— Setup
void setup() {
Serial.begin(9600);

// Setup motors
int i;
for(i = 0; i < 2; i++){
pinMode(motor_left[i], OUTPUT);
pinMode(motor_right[i], OUTPUT);
pinMode(ledPin, OUTPUT);
}

}

// ————————————————————————— Loop
void loop() {
 int a=analogRead(12);
 int b=analogRead(11);
 int c=analogRead(10);
 int d=analogRead(9);
int input[]={d,c,b,a};
int forward[]={0,0,0,1};

if (input==forward)
{
drive_forward();
delay(1000);
motor_stop();
Serial.println("1");
}
drive_backward();
delay(1000);
motor_stop();
Serial.println("2");


turn_left();
delay(1000);
motor_stop();
Serial.println("3");

turn_right();
delay(1000);
motor_stop();
Serial.println("4");

motor_stop();
delay(1000);
motor_stop();
Serial.println("5");

digitalWrite(ledPin, HIGH);   // set the LED on
  delay(1000);                  // wait for a second
  digitalWrite(ledPin, LOW);    // set the LED off
  delay(1000);                  // wait for a second

}

// ————————————————————————— Drive

void motor_stop(){
digitalWrite(motor_left[0], LOW);
digitalWrite(motor_left[1], LOW);

digitalWrite(motor_right[0], LOW);
digitalWrite(motor_right[1], LOW);
delay(25);
}

void drive_forward(){
digitalWrite(motor_left[0], HIGH);
digitalWrite(motor_left[1], LOW);

digitalWrite(motor_right[0], HIGH);
digitalWrite(motor_right[1], LOW);
}

void drive_backward(){
digitalWrite(motor_left[0], LOW);
digitalWrite(motor_left[1], HIGH);

digitalWrite(motor_right[0], LOW);
digitalWrite(motor_right[1], HIGH);
}

void turn_left(){
digitalWrite(motor_left[0], LOW);
digitalWrite(motor_left[1], HIGH);

digitalWrite(motor_right[0], HIGH);
digitalWrite(motor_right[1], LOW);
}

void turn_right(){
digitalWrite(motor_left[0], HIGH);
digitalWrite(motor_left[1], LOW);

digitalWrite(motor_right[0], LOW);
digitalWrite(motor_right[1], HIGH);
}

Moderator edit: Replaced [ color ] with [ code ] to remove italics.

void loop() {
 int a=analogRead(12);
 int b=analogRead(11);
 int c=analogRead(10);
 int d=analogRead(9);
int input[]={d,c,b,a};
int forward[]={0,0,0,1};

if (input==forward)

Whoa. Slow down here. You are not comparing the contents of input and forward, you are comparing the addresses of the arrays, which will always be different.

I'm not sure I like this approach, because analogRead returns a number between 0 and 1023, so the likelihood of getting exactly 0 or 1 is quite low.

http://arduino.cc/en/Reference/AnalogRead

And even if that was OK, you need to compare the values you got, not the array addresses.

I think you actually want digitalRead, given that you’re using pins 9, 10, 11, 12 and comparing against ‘1’.

And, as Nick says, you have to compare each element of ‘forward’ against each element of input.

Alternately, you could compress it into one value:

int input = (digitalRead(10) << 2) | (digitalRead(11) << 1) | digitalRead(12);
const int forward = 1;