Hi,
I wish to use the W5100 shield.
I can control 2 LED's.
When I wish to use the program to control a stepper motor, I get only one step.
Where is the problem?
//for use with W5100 based ethernet shields
#include <SPI.h>
#include <Ethernet.h>
#include <CustomStepper.h>
// was in the basiccode
#include <Servo.h>
Servo myservo; // create servo object to control a servo
CustomStepper stepper(5, 6, 7, 8, (byte[]){8, B1000, B1100, B0100, B0110, B0010, B0011, B0001, B1001}, 8, 4096, CW);
boolean rotate1 = false;
boolean rotatedeg = false;
boolean crotate = false;
int Wup = 0;
int Wdown = 0;
int Wstp = 0;
// pushbutton up on 9
#define up 9
// pushbutton down on 11
#define down 11
// pushbutton stp on 12
#define stp 12
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; //physical mac address
byte ip[] = { 192, 168, 10, 177 }; // ip in lan
byte gateway[] = { 192, 168, 10, 1 }; // internet access via router
byte subnet[] = { 255, 255, 255, 0 }; //subnet mask
EthernetServer server(80); //server port
int cntl = 0 ;
int white = 2 ;
int red = 3 ;
String readString;
//////////////////////
void setup(){
pinMode(up, INPUT);
pinMode(down, INPUT);
pinMode(stp, INPUT);
stepper.setRPM(16);
//sets the Steps Per Rotation, in this case it is 64 * the 283712/4455 annoying ger ratio
//for my motor (it works with float to be able to deal with these non-integer gear ratios)
stepper.setSPR(4096);
pinMode(white, OUTPUT); //pin selected to control LED white
pinMode(red, OUTPUT); //pin selected to control LED red
//start Ethernet
Ethernet.begin(mac, ip, gateway, subnet);
server.begin();
//the pin for the servo co
//enable serial data print
Serial.begin(9600);
Serial.println("server LED test 1.0"); // so I can keep track of what is loaded
}
void loop(){
// Create a client connection
Serial.println ("cntl=");
Serial.println (cntl);
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("<meta name='apple-mobile-web-app-capable' content='yes' />");
client.println("<meta name='apple-mobile-web-app-status-bar-style' content='black-translucent' />");
client.println("<link rel='stylesheet' type='text/css' href='http://homeautocss.net84.net/a.css' />");
client.println("<TITLE>Home Automation</TITLE>");
client.println("</HEAD>");
client.println("<BODY>");
client.println("<H1>Home Automation</H1>");
client.println("<hr />");
client.println("
");
client.println("<a href=\"/?lightwon\"\">White light on</a>");
client.println("<a href=\"/?lightwoff\"\">White light off</a>
");
client.println("
");
client.println("<a href=\"/?lightron\"\">Red light on</a>");
client.println("<a href=\"/?lightroff\"\">Red light off</a>
");
client.println("</BODY>");
client.println("</HTML>");
delay(1);
//stopping client
client.stop();
///////////////////// control arduino pin
if(readString.indexOf("?lightwon") >0)//checks for on
{
digitalWrite(white, HIGH); // set pin 6 high
Serial.println("Led White On");
cntl = 1 ;
Serial.println("here I pass ....");
stepper.setDirection (CW) ;
stepper.rotate(2);
}
else{
if(readString.indexOf("?lightwoff") >0)//checks for off
{
digitalWrite(white, LOW); // set pin 6 low
Serial.println("Led White Off");
cntl = 0 ;
}
}
if(readString.indexOf("?lightron") >0)//checks for on
{
digitalWrite(red, HIGH); // set pin 7 high
Serial.println("Led Red On");
cntl = 2 ;
}
else{
if(readString.indexOf("?lightroff") >0)//checks for off
{
digitalWrite(red, LOW); // set pin 7 low
Serial.println("Led Red Off");
cntl = 0 ;
}
}
//clearing string for next read
readString="";
}
// if (cntl == 1 ) {
// Serial.println("here I pass");
// stepper.setDirection (CW) ;
// stepper.rotate();
// delay(500);
// }
}
}
}
stepper.run();
}