move a stepper by pressing button html


hello i'm having problems  i'm trying move stepper html portal try wont seem work 1 have suggestion?

code: [select]

#include <spi.h>
#include <ethernet.h>
#include <accelstepper.h>

byte mac[] = { 0xde, 0xad, 0xbe, 0xef, 0xfe, 0xed }; //physical mac address
ipaddress ip(192,168,163,253);
ipaddress gateway(192,168,163, 99);
ipaddress subnet(255, 255, 255, 0);
ethernetserver server(80);                                      //server port
string readstring;

#define fullstep 4
#define halfstep 8

//declare variables motor pins
int motorpin1 = 10; // blue   - 28byj48 pin 1
int motorpin2 = 11; // pink   - 28byj48 pin 2
int motorpin3 = 12; // yellow - 28byj48 pin 30
int motorpin4 = 13; // orange - 28byj48 pin 4
                       // red    - 28byj48 pin 5 (vcc)

// sequence 1-3-2-4 required proper sequencing of 28byj48
accelstepper stepper2(fullstep, motorpin1, motorpin3, motorpin2, motorpin4);

void setup() {
// open serial communications , wait port open:
 serial.begin(9600);
  while (!serial) {
   ; // wait serial port connect. needed leonardo only
 }


 // start ethernet connection , server:
 ethernet.begin(mac, ip);
 server.begin();
 serial.print("server @ ");
 serial.println(ethernet.localip());
 //setup stepper motor
 stepper2.setmaxspeed(1000.0);
 stepper2.setacceleration(50.0);
 stepper2.setspeed(200);
 stepper2.moveto(2048);
}


void loop() {
 // create client connection
 ethernetclient client = server.available();
 if (client) {
   while (client.connected()) {  
     if (client.available()) {
       char c = client.read();
   
       //read char char http request
       if (readstring.length() < 100) {
         //store characters string
         readstring += c;
         //serial.print(c);
        }

        //if http request has ended
        if (c == '\n') {          
          serial.println(readstring); //print serial monitor debuging
   
          client.println("http/1.1 200 ok"); //send new page
          client.println("content-type: text/html");
          client.println();    
          client.println("<html>");
          client.println("<head>");
          client.println("</head>");
          client.println("<body>");
          client.println("<h1>control center</h1>");
          client.println("<br />");  
          client.println("<a href=\"/?button1\"\">move stepper clockwise</a>");
          client.println("<br />");
          client.println("<a href=\"/?button2\"\">move stepper</a><br />");
          client.println("<br />");
          client.println("</body>");
          client.println("</html>");
         
          delay(1);
          //stopping client
          client.stop();
          //controls arduino if press buttons
          if (readstring.indexof("?button1") >0){
             stepper2.moveto(2048);
             stepper2.run();
               {
                 delay(15);                       // waits 15ms
               }
          }
          if (readstring.indexof("?button2") >0){
if (stepper2.distancetogo() == 0)
     stepper2.moveto(-stepper2.currentposition());
   stepper2.run();
          }
           //clearing string next read
           readstring="";  
         
        }
      }
   }
}
}

can stepper move correctly sending characters arduino serial monitor (i.e. without using ethernet stuff)?

can arduino correctly receive characters via ethernet connection (i.e. without bothering stepper motor stuff)?

...r


Arduino Forum > Using Arduino > Programming Questions > move a stepper by pressing button html


arduino

Comments

Popular posts from this blog

opencv3, tbb and rasp pi 2 - Raspberry Pi Forums

small ethernet problem - Raspberry Pi Forums

Multithumb configuration params not working? - Joomla! Forum - community, help and support