Hello i'm having some problems i'm trying to move my stepper with an html portal but what i try to do it wont seem to work does any one have a suggestion?
#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 for the 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)
// The sequence 1-3-2-4 required for proper sequencing of 28BYJ48
AccelStepper stepper2(FULLSTEP, motorPin1, motorPin3, motorPin2, motorPin4);
void setup() {
// Open serial communications and wait for port to open:
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for Leonardo only
}
// start the Ethernet connection and the server:
Ethernet.begin(mac, ip);
server.begin();
Serial.print("server is at ");
Serial.println(Ethernet.localIP());
//setup for stepper motor
stepper2.setMaxSpeed(1000.0);
stepper2.setAcceleration(50.0);
stepper2.setSpeed(200);
stepper2.moveTo(2048);
}
void loop() {
// Create a client connection
EthernetClient client = server.available();
if (client) {
while (client.connected()) {
if (client.available()) {
char c = client.read();
//read char by char HTTP request
if (readString.length() < 100) {
//store characters to string
readString += c;
//Serial.print(c);
}
//if HTTP request has ended
if (c == '\n') {
Serial.println(readString); //print to serial monitor for 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("
");
client.println("<a href=\"/?button1\"\">Move Stepper Clockwise</a>");
client.println("
");
client.println("<a href=\"/?button2\"\">Move Stepper</a>
");
client.println("
");
client.println("</BODY>");
client.println("</HTML>");
delay(1);
//stopping client
client.stop();
//controls the Arduino if you press the 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 for next read
readString="";
}
}
}
}
}