/*---H-bridge Pin assignments for this code..... First H-Bridge ----- Arduino ____________ Iris (+) IN1 ---- 22 Iris (-) 1N2 ---- 23 Zoom (+) IN3 ---- 24 Zoom (-) IN4 ---- 25 Second H-Bridge ---- Arduino ____________ Focus (+) IN3 ---- 26 Focus (-) IN4 ---- 27 --*/ #include //install libraries for the ethernet #include #include #include #include #include #include byte mac[] = { 0x90, 0xA2, 0xDA, 0x00, 0xD3, 0x7B}; // <-Set your ethernet card's MAC address. this should be ok. byte ip[] = { 10,16,176,223 }; //<--Replace with your ip address EthernetServer server(80); //<--Create a Web Server. WWW runs on port 80 by default. String camString; //Create a string to use for buttons String message = ""; //same here // Setup for tilt stepper motor..... //declare variables for the motor pins int motorPin1 = 30; int motorPin2 = 31; int motorPin3 = 32; int motorPin4 = 33; int motorSpeed = 1000; //variable to set stepper speed int count = 0; // count of steps made int countsperrev = 512/2; // number of steps per full revolution int lookup[8] = {B01000, B01100, B00100, B00110, B00010, B00011, B00001, B01001}; // define antenna rotor control pins #define power 34 #define CW 35 #define CCW 36 void setup(){ Serial.begin(9600); for (int i=2; i<53; i++){ //quickly make all pins outputs pinMode(i, OUTPUT); digitalWrite (i,LOW); // and set them low } Ethernet.begin( mac,ip); //<-- start the ethernet card server.begin(); //<-- start the web server //declare the tilt stepper motor pins as outputs pinMode(motorPin1, OUTPUT); pinMode(motorPin2, OUTPUT); pinMode(motorPin3, OUTPUT); pinMode(motorPin4, OUTPUT); // Set up rotor control pins pinMode(CW,OUTPUT); pinMode(CCW,OUTPUT); pinMode(power,OUTPUT); digitalWrite(CW,HIGH); digitalWrite(CCW,HIGH); digitalWrite(power,HIGH); } void loop(){ EthernetClient client = server.available(); //<-- start listening for someone to talk to us if (client) { Serial.println("connection"); while (client.connected()) { if (client.available()) { char c = client.read(); if (camString.length() < 100) { camString += c; } if (c == '\n') { // <-someone knocked. lets show them a webpage full of buttons! client.println("HTTP/1.1 200 OK"); client.println("Content-Type: text/html"); //client.printlnln(); client.println(F("")); client.println(F("")); client.println(F("Arduino CamControl")); client.println(F("")); client.println(F("")); client.println(F("Lens Control
")); client.println(F("")); client.println(F("")); client.println(F("")); client.println(F("")); client.println(F("")); client.println(F("")); client.println(F("")); client.println(F("
")); //Build rotor control buttons & tilt control buttons. client.println(""); client.println(F("")); client.println(F("")); client.println(F("")); client.println(F("")); client.println(F("

")); client.println(""); client.println(""); delay(1); client.stop(); // The block below watches for button presses and applies the correct actions....... if(camString.substring(6,12) == "zoomin") //<-- Zoom in button pressed. { zoomin(); //<-- jump to routine that sends appropriate commands to motors } if(camString.substring(6,13) == "zoomout") //<-- Same as above but for Zoom Out { zoomout(); } if(camString.substring(6,15) == "zoominall") //<--zooms in all the way { zoominall(); } if(camString.substring(6,16) == "zoomoutall") //<--zooms out all the way { zoomoutall(); } if(camString.substring(6,14) == "irisopen") { irisopen(); } if(camString.substring(6,15) == "irisclose") { irisclose(); } if(camString.substring(6,13) == "focusin") { focusin(); } if(camString.substring(6,14) == "focusout") { focusout(); } if(camString.substring(6,15) == "focusin20") { focusin20(); } if(camString.substring(6,16) == "focusout20") { focusout20(); } if(camString.substring(6,11) == "right") { righ(); } if(camString.substring(6,10) == "left") { left(); } if(camString.substring(6,8) == "up") { ccw(); } if(camString.substring(6,10) == "down") { cw(); } camString=""; //<-- this clears the command string so it doesnt keep doing the same command over and over! } } } } } // This block holds all the routines that control what the pins do when buttons are pressed. void zoomin() { digitalWrite(24, HIGH); digitalWrite(25, LOW); delay(100); digitalWrite(24, LOW); digitalWrite(25, LOW); } void zoomoutall() { digitalWrite(24, LOW); digitalWrite(25, HIGH); delay(3000); digitalWrite(24, LOW); digitalWrite(25, LOW); } void zoominall() { digitalWrite(24, HIGH); digitalWrite(25, LOW); delay(3000); digitalWrite(24, LOW); digitalWrite(25, LOW); } void zoomout() { digitalWrite(24, LOW); digitalWrite(25, HIGH); delay(100); digitalWrite(24, LOW); digitalWrite(25, LOW); } void irisopen() { digitalWrite(22, HIGH); digitalWrite(23, LOW); delay(30); digitalWrite(22, LOW); digitalWrite(23, LOW); } void irisclose() { digitalWrite(22, LOW); digitalWrite(23, HIGH); delay(30); digitalWrite(22, LOW); digitalWrite(23, LOW); } void focusin() { digitalWrite(26, HIGH); digitalWrite(27, LOW); delay(30); digitalWrite(26, LOW); digitalWrite(27, LOW); } void focusin20() { digitalWrite(26, HIGH); digitalWrite(27, LOW); delay(700); digitalWrite(26, LOW); digitalWrite(27, LOW); } void focusout() { digitalWrite(26, LOW); digitalWrite(27, HIGH); delay(30); digitalWrite(26, LOW); digitalWrite(27, LOW); } void focusout20() { digitalWrite(26, LOW); digitalWrite(27, HIGH); delay(700); digitalWrite(26, LOW); digitalWrite(27, LOW); } void right() { digitalWrite(CW,LOW); delay(50); digitalWrite(power,LOW); delay (1000); digitalWrite(CW,HIGH); delay(50); digitalWrite(power,HIGH); } void left() { digitalWrite(CCW,LOW); delay(50); digitalWrite(power,LOW); delay (1000); digitalWrite(CCW,HIGH); delay(50); digitalWrite(power,HIGH); } void cw(){ for (int T=1;T<512;T++){ digitalWrite(9,HIGH); digitalWrite(10,LOW); digitalWrite(11,LOW); digitalWrite(12,LOW); delay(4); digitalWrite(9,LOW); digitalWrite(10,HIGH); digitalWrite(11,LOW); digitalWrite(12,LOW); delay(4); digitalWrite(9,LOW); digitalWrite(10,LOW); digitalWrite(11,HIGH); digitalWrite(12,LOW); delay(4); digitalWrite(9,LOW); digitalWrite(10,LOW); digitalWrite(11,LOW); digitalWrite(12,HIGH); delay(4); } } void ccw(){ for (int T=1;T<512;T++){ digitalWrite(9,LOW); digitalWrite(10,LOW); digitalWrite(11,LOW); digitalWrite(12,HIGH); delay(4); digitalWrite(9,LOW); digitalWrite(10,LOW); digitalWrite(11,HIGH); digitalWrite(12,LOW); delay(4); digitalWrite(9,LOW); digitalWrite(10,HIGH); digitalWrite(11,LOW); digitalWrite(12,LOW); delay(4); digitalWrite(9,HIGH); digitalWrite(10,LOW); digitalWrite(11,LOW); digitalWrite(12,LOW); delay(4); } }