code not functioning well on the arduino

hi guys , im working on RC car controlled with 2 motors , one for controlling backward and forward and the second one for right and left , by " arduino diamondback wifi " i did upload this code onces and its working great with no errors ,

#include <WiServer.h>

#define WIRELESS_MODE_INFRA    1 
#define WIRELESS_MODE_ADHOC    2

// Wireless configuration parameters —————————————- 
unsigned char local_ip[]    = {192,168,0,100};   // IP address of WiShield
unsigned char gateway_ip[]  = {192,168,0,1};   // router or gateway IP address
unsigned char subnet_mask[] = {255,255,255,0}; // subnet mask for the local network
char ssid[]                 = {"ahmed"};   // max 32 bytes
unsigned char security_type = 0;               // 0 - open; 1 - WEP; 2 - WPA; 3 - WPA2

// WPA/WPA2 passphrase
const prog_char security_passphrase[] PROGMEM = {"12345678"};	// max 64 characters

// WEP 128-bit keys
prog_uchar wep_keys[] PROGMEM = { 
	0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d,	// Key 0
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,	// Key 1
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,	// Key 2
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00	// Key 3
};

// setup the wireless mode 
// infrastructure – connect to AP 
// adhoc – connect to another WiFi device 
unsigned char wireless_mode = WIRELESS_MODE_INFRA;

unsigned char ssid_len; 
unsigned char security_passphrase_len; 
// End of wireless configuration parameters —————————————-

int redState = 0; 
int whiteState = 0; 
int greenState = 0;

int redPin = 5; 
int whitePin = 6; 
int greenPin = 7;

// This is our page serving function that generates web pages 
boolean sendMyPage(char* URL) { 
    if (strcmp(URL, "/red") == 0) redState = !redState; 
    if (strcmp(URL, "/white") == 0) whiteState = !whiteState; 
    if (strcmp(URL, "/green") == 0) greenState = !greenState; 
    digitalWrite(redPin, redState); 
    digitalWrite(whitePin, whiteState); 
    digitalWrite(greenPin, greenState); 
    // Check if the requested URL matches "/" 
   // if (strcmp(URL, "/") == 0) { 
        // Use WiServer’s print and println functions to write out the page content 
        WiServer.print("<html>"); 
        WiServer.print("Light Control

"); 
        printLightStatus("red", redState); 
        printLightStatus("white", whiteState); 
        printLightStatus("green", greenState); 
        WiServer.print("The page you requested was: "); 
        WiServer.print(URL); 
        WiServer.print("
The arduino has been running for: "); 
        WiServer.print(millis()); 
        WiServer.print(" milliseconds
"); 
        WiServer.print("</html>"); 
        // URL was recognized 
        return true; 
    //} 
    // URL not found 
    return false; 
}

void printLightStatus( String lightName, int lightState) { 
  WiServer.print(lightName); 
  WiServer.print(" Light is "); 
        if(lightState ==0) { 
            WiServer.print(" <b>off</b> <a href=/"); 
            WiServer.print(lightName); 
            WiServer.print(">Turn On</a>
"); 
        } else { 
          WiServer.print(" <b>on</b> <a href=/"); 
            WiServer.print(lightName); 
            WiServer.print(">Turn off</a>
"); 
        } 
}

void setup() { 
  // Initialize WiServer and have it use the sendMyPage function to serve pages 
  WiServer.init(sendMyPage); 
  // Enable Serial output and ask WiServer to generate log messages (optional) 
  Serial.begin(57600); 
  WiServer.enableVerboseMode(true); 
  pinMode(redPin, OUTPUT); 
  pinMode(whitePin, OUTPUT); 
  pinMode(greenPin, OUTPUT); 
}

void loop(){

  // Run WiServer 
  WiServer.server_task(); 
  delay(10); 
}

but in my project i need to control 4 pins and this one control just 3 , i tried to add one more pin and change the name to , backward , forward and this what i end with

/* 
* A simple sketch that uses WiServer to serve a web page 
*/

#include <WiServer.h>

#define WIRELESS_MODE_INFRA    1 
#define WIRELESS_MODE_ADHOC    2

// Wireless configuration parameters —————————————- 
unsigned char local_ip[]    = {192,168,0,100};   // IP address of WiShield
unsigned char gateway_ip[]  = {192,168,0,1};   // router or gateway IP address
unsigned char subnet_mask[] = {255,255,255,0}; // subnet mask for the local network
char ssid[]                 = {"ahmed"};   // max 32 bytes
unsigned char security_type = 0;               // 0 - open; 1 - WEP; 2 - WPA; 3 - WPA2

// WPA/WPA2 passphrase
const prog_char security_passphrase[] PROGMEM = {"12345678"};	// max 64 characters

// WEP 128-bit keys
prog_uchar wep_keys[] PROGMEM = { 
	0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d,	// Key 0
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,	// Key 1
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,	// Key 2
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00	// Key 3
};

// setup the wireless mode 
// infrastructure – connect to AP 
// adhoc – connect to another WiFi device 
unsigned char wireless_mode = WIRELESS_MODE_INFRA;

unsigned char ssid_len; 
unsigned char security_passphrase_len; 
// End of wireless configuration parameters —————————————-

int fowrwardState = 0; 
int backwardState = 0; 
int rightState = 0;
int leftState = 0;

int  fowrwardPin = 4; 
int  backwardPin = 5; 
int rightPin = 6;
int leftPin = 7;
// This is our page serving function that generates web pages 
boolean sendMyPage(char* URL) { 
    if (strcmp(URL, "/fowrward") == 0) fowrwardState = !fowrwardState; 
    if (strcmp(URL, "/backward") == 0) backwardState = !backwardState; 
    if (strcmp(URL, "/right") == 0) rightState = !rightState; 
        if (strcmp(URL, "/left") == 0) leftState = !leftState; 
    digitalWrite(fowrwardPin, fowrwardState); 
    digitalWrite(backwardPin, backwardState); 
    digitalWrite(rightPin, rightState); 
     digitalWrite(leftPin, leftState); 
    // Check if the requested URL matches "/" 
   // if (strcmp(URL, "/") == 0) { 
        // Use WiServer’s print and println functions to write out the page content 
        WiServer.print("<html>"); 
        WiServer.print("WiFi RC 

"); 
        printcarStatus("fowrward", fowrwardState); 
                WiServer.print("------"); 
        printcarStatus("backward", backwardState); 
                        WiServer.print("------"); 
        printcarStatus("right", rightState); 
                        WiServer.print("------"); 
          printcarStatus("left", leftState); 
                          WiServer.print("------"); 
        WiServer.print("The page you requested was: "); 
        WiServer.print(URL); 
                WiServer.print("
Done by :Ahmed Alghasra "); 
        WiServer.print("
The arduino has been running for: "); 
        WiServer.print(millis()); 
        WiServer.print(" milliseconds
"); 
        WiServer.print("</html>"); 
        // URL was recognized 
        return true; 
    //} 
    // URL not found 
    return false; 
}

void printcarStatus( String carName, int carState) { 
  WiServer.print(carName); 
  WiServer.print(" car is "); 
        if(carState ==0) { 
            WiServer.print(" <b>off</b> <a href=/"); 
            WiServer.print(carName); 
            WiServer.print(">Turn On</a>
"); 
        } else { 
          WiServer.print(" <b>on</b> <a href=/"); 
            WiServer.print(carName); 
            WiServer.print(">Turn off</a>
"); 
        } 
}

void setup() { 
  // Initialize WiServer and have it use the sendMyPage function to serve pages 
  WiServer.init(sendMyPage); 
  // Enable Serial output and ask WiServer to generate log messages (optional) 
  Serial.begin(57600); 
  WiServer.enableVerboseMode(true); 
  pinMode(fowrwardPin, OUTPUT); 
  pinMode(backwardPin, OUTPUT); 
  pinMode(rightPin, OUTPUT); 
    pinMode(leftPin, OUTPUT); 
}

void loop(){

  // Run WiServer 
  WiServer.server_task(); 
  delay(10); 
}

on this code i face errors , when i click on any function , backward /forward/right /left nothing work , just less than sec the motor work then stop ! , but on the upper code its functioning very well ,
thanks for your time ,

Have a link to your Wi-Fi shield?
Are you sure that pin 4 is not in use by shield?

Does the first version work as expected on the RC car with its motors? Do you have separate supplies for the motors and the Arduino? Its a common mistake to run the Arduino from the same supply as a motor (which creates all manner of noise and drop-outs on the supply rails).

Magician:
Have a link to your Wi-Fi shield?
Are you sure that pin 4 is not in use by shield?

How can i check ?

MarkT:
Does the first version work as expected on the RC car with its motors? Do you have separate supplies for the motors and the Arduino? Its a common mistake to run the Arduino from the same supply as a motor (which creates all manner of noise and drop-outs on the supply rails).

The first code working well 100% ,about thr power supply no im using 12 v for the motors and 5V for the arduino

ahmed665:

Magician:
Have a link to your Wi-Fi shield?
Are you sure that pin 4 is not in use by shield?

How can i check ?

Look at the traces on the shield - if it doesn't use pin4 then there won't be any traces leading from it.

I've compared the code line by line, no obvious issue there, I think it must be hardware issues with supply and or decoupling. Are the grounds commoned properly?

MarkT:

ahmed665:

Magician:
Have a link to your Wi-Fi shield?
Are you sure that pin 4 is not in use by shield?

How can i check ?

Look at the traces on the shield - if it doesn't use pin4 then there won't be any traces leading from it.

I've compared the code line by line, no obvious issue there, I think it must be hardware issues with supply and or decoupling. Are the grounds commoned properly?

i checked this too , no pin is connected , and i changed pin4 to pin8 same problem too