#include <NativeEthernet.h>
//#include <SPI.h>
//#include <NativeEthernet.h>
unsigned long Position = 0, Facedelay = 0;
int currentposition = 0, pos = 0, linear = 0;
int i = 0, servo1 = 9, servo2 = 10;
bool mode_ = 0;
byte mac[] = {
0x04, 0xE9, 0xE5, 0x0C, 0xA4, 0x27
};
IPAddress ip(192, 168, 127, 177);
EthernetServer server(80);
void setup() {
pinMode(servo1, OUTPUT);// put your setup code here, to run once:
pinMode(servo2, OUTPUT);
digitalWrite(servo2, LOW);
// Open serial communications and wait for port to open:
Serial.begin(9600);
//while (!Serial) {
//; // wait for serial port to connect. Needed for native USB port only
//}
//Serial.println("Ethernet WebServer Example");
// start the Ethernet connection and the server:
Ethernet.begin(mac, ip);
// Check for Ethernet hardware present
if (Ethernet.hardwareStatus() == EthernetNoHardware) {
//Serial.println("Ethernet shield was not found. Sorry, can't run without hardware. :(");
while (true) {
delay(1); // do nothing, no point running without Ethernet hardware
}
}
if (Ethernet.linkStatus() == LinkOFF) {
//Serial.println("Ethernet cable is not connected.");
}
// start the server
server.begin();
Serial.print("server is at ");
Serial.println(Ethernet.localIP());
}
void forward()
{
digitalWrite(servo2, LOW);
for (i = 0; i <= pos; i++)
{
digitalWrite(servo1, HIGH);
delayMicroseconds(500);
digitalWrite(servo1, LOW);
delayMicroseconds(500);
}
}
void reverse()
{
digitalWrite(servo2, HIGH);
for (i = 0; i <= pos; i++)
{
digitalWrite(servo1, HIGH);
delayMicroseconds(500);
digitalWrite(servo1, LOW);
delayMicroseconds(500);
}
}
void loop() {
// listen for incoming clients
EthernetClient client = server.available();
if (client) {
client.println("Ready");
while (client.connected()) {
if (client.available()) {
String msg = client.readString();
Serial.print(msg);
}
if (Serial.available()) {
String cmd = Serial.readString();
client.print(cmd);
}
}
}
}