WiFly+arduino motor controll

Hi all i trying to control my robot motors using wifly shield of corse wifly library 1 alpha release. so far all going good just all my setup freezez for too long after i press button say Forward it takes few minutes to start spin motor(sometimes id dosint at all :slight_smile: ) i am just begining in programing or electronicks but its nice time spend so far :slight_smile:

My skech is

/*
 * Web Server
 *
 * (Based on Ethernet's WebServer Example)
 *
 * A simple web server that shows the value of the analog input pins.
 */

#include "WiFly.h"
#include "Credentials.h"
#include <WString.h>
String readString = String(100);



Server server(80);
 
//const int ledPin = 4;

// set the output pins
int baseMotorEnablePin = 2;
int baseMotorPin1 = 3;                             
int baseMotorPin2 = 4;                           
int shoulderMotorEnablePin = 14;
int shoulderMotorPin1 = 15;                             
int shoulderMotorPin2 = 16;        
///////////////////////////////

void setup() {
  WiFly.begin();
  if (!WiFly.join(ssid, passphrase)) {
    while (1) {
      // Hang on failure.
    }
  }
  // set the SN754410 pins as outputs:
  pinMode(baseMotorPin1, OUTPUT);
  pinMode(baseMotorPin2, OUTPUT);
  pinMode(baseMotorEnablePin, OUTPUT);
  digitalWrite(baseMotorEnablePin, HIGH);
  pinMode(shoulderMotorPin1, OUTPUT);
  pinMode(shoulderMotorPin2, OUTPUT);
  pinMode(shoulderMotorEnablePin, OUTPUT);
  digitalWrite(shoulderMotorEnablePin, HIGH);
  //++++++++++++++++++++++++++++++++++++++++++++++
 //pinMode(ledPin, OUTPUT);
  Serial.begin(9600);
  Serial.print("IP: ");
  Serial.println(WiFly.ip());
  
  server.begin();
}

void loop() {
  Client client = server.available();
  if (client) {
    // an http request ends with a blank line
    boolean current_line_is_blank = true;
    while (client.connected()) {
      if (client.available()) {
        char c = client.read();
             Serial.print(c);
       if(readString.length() < 100)
       {
         readString.append(c);
      //   Serial.println(readString);
       }
        // if we've gotten to the end of the line (received a newline
        // character) and the line is blank, the http request has ended,
        // so we can send a reply
        if (c == '\n' && current_line_is_blank) {
          // send a standard http response header
          client.println("HTTP/1.1 200 OK");
          client.println("Content-Type: text/html");
          client.println();
          client.println("<title>Motor Control</title><h2><center>TEST</center></h2>
<hr>





");
          
         /* // output the value of each analog input pin
          for (int i = 0; i < 6; i++) {
            client.print("analog input ");
            client.print(i);
            client.print(" is ");
            client.print(analogRead(i));
            client.println("
");
          }*/
         client.println("<table  width=50   cellpadding=-2 cellspacing=5  align=right>");
         client.println("<tr><td></td><td><form method=get name=L><input type=submit name=L value=Forw></form></td><td></td></tr>");
         client.println("<tr><td><form method=get name=L><input type=submit name=L value=Left></form></td><td><form method=get name=L><input type=submit name=L value=Stop></form></td><td><form method=get name=LED><input type=submit name=LED value=Right></form></td></tr>");
         client.println("<tr><td></td><td><form method=get name=L><input type=submit name=L value=Down></form></td><td></td></tr>");
         client.println("</table>");
             if(readString.contains("L=Forw"))
         {
      digitalWrite(baseMotorPin1, LOW);   
      digitalWrite(baseMotorPin2, HIGH);  
      digitalWrite(shoulderMotorPin1, LOW);   
      digitalWrite(shoulderMotorPin2, HIGH); 
         }
         if(readString.contains("L=Down"))
         {
      digitalWrite(baseMotorPin1, HIGH);   
      digitalWrite(baseMotorPin2, LOW);
      digitalWrite(shoulderMotorPin1, HIGH);   
      digitalWrite(shoulderMotorPin2, LOW); 
         }
                  if(readString.contains("L=Stop"))
         {
      digitalWrite(baseMotorPin1, LOW);   
      digitalWrite(baseMotorPin2, LOW);
      digitalWrite(shoulderMotorPin1, LOW);   
      digitalWrite(shoulderMotorPin2, LOW); 
         }
         readString = 0;
          break;
        }
        if (c == '\n') {
          // we're starting a new line
          current_line_is_blank = true;
        } else if (c != '\r') {
          // we've gotten a character on the current line
          current_line_is_blank = false;
        }
      }
    }
    // give the web browser time to receive the data
    delay(1000);
    client.stop();

  }
}

Maybe someone have any sugestion how to improve it all is welcome .

Used similar setup for turning Led on and off works good but still too much lag sometimes

I am using Arduino Duemilanove 328 and wifly shield with 14Mhz crystal

If you havenโ€™t made progress with this, you might get a better response for this on the main Arduino.cc site forums as I suspect part of the issue might be a more general programming issue. (I could be wrong however. :slight_smile: )

To start with, I would suggest separating the code that checks what action to take from the code that actually causes that action to happen.

โ€“Philip;