/* Door Sjoerd de Jong Openen en sluiten gordijnen */ #include #include #include Servo microservo; byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };//Macadres byte ip[] = { 192, 168, 240, 7 }; //LAN IP-adres byte gateway[] = { 192, 168, 240, 254 }; //Gateway byte subnet[] = { 255, 255, 255, 0 };//subnet mask EthernetServer server(80);//server port String readString; unsigned long time; boolean moving = false; boolean halfMoving = false; boolean halfOpen = false; boolean closed = true; 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 } microservo.attach(7); microservo.writeMicroseconds(1400); //niet bewegen bij start // start the Ethernet connection and the server: Ethernet.begin(mac, ip, gateway, subnet); server.begin(); Serial.print("server is at "); Serial.println(Ethernet.localIP()); } 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(""); client.println(""); client.println(""); client.println(""); client.println("Gordijnen Peerlenburg open/dicht"); client.println(""); client.println(""); client.println("

Gordijnen open of dicht

"); client.println("
"); client.println("
"); client.println("

Servo op pin 7,

"); client.println("
"); client.println("
"); client.println("halfopen

"); client.println("Open

"); client.println("stop

"); client.println("dicht
"); client.println("
"); client.println(""); client.println(""); delay(1); //stopping client client.stop(); //controls the Arduino if you press the buttons if (readString.indexOf("?open") > 0) { // in steps of 1 degree if (closed) { microservo.writeMicroseconds(2000); //Open (linksom) time = millis(); moving = true; closed = false; } if (halfOpen) { halfMoving = true; halfOpen = false; } } if (readString.indexOf("?halfopen") > 0) { // in steps of 1 degree if (!(halfOpen)) { if (closed) { microservo.writeMicroseconds(2000); //Open (linksom) time = millis(); halfMoving = true; halfOpen = true; closed = false; } else { microservo.writeMicroseconds(1000); //Dicht (rechtsom) time = millis(); halfMoving = true; halfOpen = true; } } } if (readString.indexOf("?dicht") > 0) { if (!(closed)) { microservo.writeMicroseconds(1000); //Dicht (rechtsom) time = millis(); if (halfOpen) { halfMoving = true; halfOpen = false; closed = true; } else { moving = true; closed = true; } } } if (readString.indexOf("?stop") > 0) { microservo.writeMicroseconds(1400); //stop moving = false; halfMoving = false; } //clearing string for next read readString = ""; } } } } if (moving) { if (millis() - time >= 10000) { microservo.writeMicroseconds(1400); moving = false; } } if (halfMoving) { if (millis() - time >= 5000) { microservo.writeMicroseconds(1400); halfMoving = false; } } }