error in programing??

hi…
i got a program from net for interfacing dualshock controller with the arduino uno board…well…i edited the program such that i can use it drive the small 4 wheeled vehicle…i programed such that the arduino gives following outputs for my instruction(via controller)…ther are 4 o/p…r1 r2 l1 l2…these are connected to the l293d motor drivers for driving the mini-motors…
i/p r1 r2 l1 l2 function
X 1 0 1 0 forward
triangle 0 1 0 1 backward
X(or)triangle +left 0 1 1 0 left
X(or)triangle+right 1 0 0 1 right
read the 2 sticks

now the problem is just for simulation purpose i connected these pins with leds…i checked it with led i found all functions except the forward function works very well…but in forward function the led dims…and i get a max voltage of 1.2v…the same led is provided with 3.3v by the board when other functions are performed…
…i cant find any mistakes in programming or circuits…i have uploaded the program here…

there is also another problem such that the pin 2 gives high always…i tried to make it low using the edited BLINK program…well that is not working…its always high…

#include <PS2X_lib.h>
PS2X ps2x;
/* restart your Arduino after you conect the controller or call config_gamepad(pins) again after connecting the controller./
/

pins functions
13 clock
12 data
11 command
10 attension(enable)
7 r1
6 r2
5 l1
4 l2
*/
int error = 0;
byte type = 0;
byte vibrate = 0;
int led=9,r1=7,r2=6,l1=5,l2=4;
void setup()
{
Serial.begin(57600);
pinMode(r1,OUTPUT);
pinMode(r2,OUTPUT);
pinMode(l1,OUTPUT);
pinMode(l2,OUTPUT);
error = ps2x.config_gamepad(13,11,10,12, true, true);
if(error == 0)
{
Serial.println(“Found Controller, configured successful”);
Serial.println(“Try out all the buttons, X will vibrate the controller, faster as you press harder;”);
Serial.println(“holding L1 or R1 will print out the analog stick values.”);
}
else if(error == 1)
Serial.println(“No controller found, check wiring”);
else if(error == 2)
Serial.println(“Controller found but not accepting commands.”);
else if(error == 3)
Serial.println("Controller refusing to enter Pressures mode, may not support it. ");
//Serial.print(ps2x.Analog(1), HEX);
type = ps2x.readType();
switch(type)
{
case 0:
Serial.println(“Unknown Controller type”);
break;
case 1:
{
Serial.println(“DualShock Controller Found”);
pinMode(led, OUTPUT);
digitalWrite(led,HIGH);
break;
}
}
}
int b=0,g=0;
char d=‘s’;
void loop()
{
if(error == 1) //skip loop if no controller found
return;
if(error!=2)//DualShock Controller
{
ps2x.read_gamepad(false, vibrate);
if(b==1 || g==1)
{ //read controller and set large motor to spin at ‘vibrate’ speed
if(ps2x.Button(PSB_PAD_RIGHT))
{
Serial.print("Right held this hard: ");
Serial.println(ps2x.Analog(PSAB_PAD_RIGHT), DEC);
d=‘r’;
}
if(ps2x.Button(PSB_PAD_LEFT))
{
Serial.print("LEFT held this hard: ");
Serial.println(ps2x.Analog(PSAB_PAD_LEFT), DEC);
d=‘l’;
}
if(ps2x.Analog(PSAB_PAD_RIGHT)==0 && ps2x.Analog(PSAB_PAD_LEFT)==0)
{
Serial.println(“Both r off”);
d=‘s’;
}
}
vibrate = ps2x.Analog(PSAB_BLUE); //this will set the large motor vibrate speed based on,how hard you press the blue (X) button
if (ps2x.NewButtonState()) //will be TRUE if any button changes state (on to off, or off to on)
{
if(ps2x.Button(PSB_GREEN))
{
Serial.println(“Triangle pressed”);
g=1;
}
if(ps2x.Button(PSB_BLUE))
{
Serial.println(“x pressed”);
b=1;
}
}
if(ps2x.ButtonReleased(PSB_GREEN))
{
Serial.println(“tri just released”);
g=0;
d=‘s’;
}
if(ps2x.ButtonReleased(PSB_BLUE)) //will be TRUE if button was JUST released
{
Serial.println(“x just released”);
b=0;
d=‘s’;
}
if(d==‘s’)
{
if(b==1)
{
Serial.println(“forward”);
digitalWrite(r1,HIGH);
digitalWrite(r2,LOW);
digitalWrite(l1,HIGH);
digitalWrite(l2,LOW);
}
if(g==1)
{
Serial.println(“backward”);
digitalWrite(r1,LOW);
digitalWrite(r2,HIGH);
digitalWrite(l1,LOW);
digitalWrite(l2,HIGH);
}
else
{
Serial.println(“stop”);
digitalWrite(r1,LOW);
digitalWrite(r2,LOW);
digitalWrite(l1,LOW);
digitalWrite(l2,LOW);
}
}
if(d==‘r’)
{
Serial.println(“right”);
digitalWrite(r1,HIGH);
digitalWrite(r2,LOW);
digitalWrite(l1,LOW);
digitalWrite(l2,HIGH);
}
if(d==‘l’)
{
Serial.println(“left”);
digitalWrite(r1,LOW);
digitalWrite(r2,HIGH);
digitalWrite(l1,HIGH);
digitalWrite(l2,LOW);
}

if(ps2x.Button(PSB_L1) || ps2x.Button(PSB_R1)) // print stick values if either is TRUE
{
Serial.print(“Stick Values:”);
Serial.print(ps2x.Analog(PSS_LY), DEC); //Left stick, Y axis. Other options: LX, RY, RX
Serial.print(",");
Serial.print(ps2x.Analog(PSS_LX), DEC);
Serial.print(",");
Serial.print(ps2x.Analog(PSS_RY), DEC);
Serial.print(",");
Serial.println(ps2x.Analog(PSS_RX), DEC);
}
}
delay(50);
}

Hi Late at night here and have not looked at code, but I would guess something is in contention, it could be hardware as in something holding a voltage down or the same in software, two ports, one on and one off.

I know, not the best help, but sometimes just looking in a different direction helps

Is this correct?

  if(b==1)
        {
            Serial.println("forward");
            digitalWrite(r1,HIGH);
            digitalWrite(r2,LOW);
            digitalWrite(l1,HIGH);
            digitalWrite(l2,LOW);
        }
        if(g==1)
        {
          Serial.println("backward");
          digitalWrite(r1,LOW);
          digitalWrite(r2,HIGH);
          digitalWrite(l1,LOW);
          digitalWrite(l2,HIGH);
        }
        else
        {
          Serial.println("stop"); 
          digitalWrite(r1,LOW);
          digitalWrite(r2,LOW);
          digitalWrite(l1,LOW);
          digitalWrite(l2,LOW);
        }

If b is 1, the forward code is invoked and pins set for forward. But then it immediately checks for g, and depending on g, it immediately either goes into reverse or stops… so if the forward code was invoked, it immediately gets counter-manded.

@ JimboZA: so what do you suggest??how will change the programm??

@ JimboZA:well thanx...i edited the "else" with "if(b==0 && g==0)"...the problem is solved...:):)

Great....