I have been working on a pan tilt web controller with the ethernet shield. Ive been searching the web and came across something that Dennis Schissler had wrote for the Xport not the WIZnet 1500. I've made some change to work with the wiznet but haven't had much luck getting it to work. I was wondering if some can take a look at the code?
Thanks
Jed
#include <Client.h>
#include <Ethernet.h>
#include <Server.h>
#include <WString.h>
#include <string.h>
#include <avr/pgmspace.h>
#include <Servo.h>
char linebuffer[128]; // a large buffer to store our data
// keep track of how many connections we've got
int requestNumber = 0;
Servo servo1;
Servo servo2;
int value = 5; // user input value
int xposcenter = 50; // x center position of webcam
int yposcenter = 100; // y center position of webcam
int xpos; // current x position of webcam (x is left/right)
int ypos; // current y position of webcam (y is up/down)
int xpos_upperlimit = 95; // upper limit for x direction (left)
int xpos_lowerlimit = 5; // upper limit for x direction (right)
int ypos_upperlimit = 135; // upper limit for y direction (down) - note: inversed
int ypos_lowerlimit = 55; // upper limit for y direction (up) - note: inversed
//////////////////////////////////////////////////////
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
byte ip[] = { 192, 168, 1, 142 };
Server server(80);
void setup() {
Ethernet.begin(mac, ip);
server.begin();
servo2.attach(10);
servo1.attach(9);
xpos = xposcenter;
ypos = yposcenter;
servo1.write(xposcenter);
servo2.write(yposcenter);
Serial.begin(38400);
Serial.println("serial port ready");
}
String readString = String(30); //string for fetching data from address
void loop()
{
// Create a client connection
Client client = server.available();
if (client) {
while (client.connected()) {
if (client.available()) {
char c = client.read();
//read char by char HTTP request
if (readString.length() < 30) {
//store characters to string
readString.append(c); }
//output chars to serial port
Serial.print(c);
//if HTTP request has ended
client.println ("Jed
<font size="5">Jed's<font size="5"> Webcam Positioning System
<form method="get"
<button name="servo" value="8">Move Up
");
client.println ("<button name="servo" value="4">Move Left <button name="servo" value="5">Center <button name="servo" value="6">Move Right
");<button name="servo" value="2">Move Down
if (c == '\n')
Serial.println(linebuffer)
char *found=0;
// Look for a ? style GET command
found = strstr(linebuffer, "?servo="); // "?inputfield=" GET request
if (found) {
// announce that we received a proper command
Serial.println("moving servo");
found += 7; // skip forward in the string to the data part
// print the data
value = int(found[0]);
Serial.println(value);
}
}
switch (value) {
case 52:
// User pressed '4', rotate left 10 degrees
if (xpos+10 < xpos_upperlimit) {
Serial.println("Moving LEFT");
xpos=xpos+10;
}
else Serial.println("Left limit reached");
break;
case 53:
// User pressed '5', center webcam
Serial.println("Centering Webcam");
xpos=xposcenter;
ypos=yposcenter;
break;
case 54:
// User pressed '6', rotate right 10 degrees
if (xpos-10 > xpos_lowerlimit) {
Serial.println("Moving RIGHT");
xpos=xpos-10;
}
else Serial.println("Right limit reached");
break;
case 56:
// User pressed '8', rotate up 10 degrees
if (ypos-10 > ypos_lowerlimit) {
Serial.println("Moving UP");
ypos=ypos-10;
}
else Serial.println("Upper limit reached");
break;
case 50:
// User pressed '2', rotate down 10 degrees
if (ypos+10 < ypos_upperlimit) {
Serial.println("Moving DOWN");
ypos=ypos+10;
}
else Serial.println("Lower limit reached");
break;
default:
Serial.print(value, BYTE);
Serial.println(" is not a correct key");
}
servo1.write(xpos);
servo2.write(ypos);
delay(1);
client.stop();
}}}