Добрый день. Ползунок переделал от -90 до 90 с шагом 5,но так добиться результата не получилось(Подстановка значения vol вместо MYDATA1.servo_lr не дало результаты )...
Привожу полностью html страницу(страница управления)
#include <SPI.h>
#include <Ethernet.h>
#include <Servo.h>
int led = 4;
//boolean LEDON = false;
struct MYDATA // структура меню
{
int servo_ud; // положение камеры up-down
int servo_lr; // положение камеры left-right
};
MYDATA MYDATA1={0,0};
Servo microservo, microservo2 ;
int pos = 0;
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; //physical mac address
byte ip[] = { 192, 168, 0, 112 }; // ip in lan (that's what you need to use in your browser. ("192.168.1.178")
byte gateway[] = { 192, 168, 0, 3 }; // internet access via router
byte subnet[] = { 255, 255, 255, 0 }; //subnet mask
EthernetServer server(80); //server port
String readString;
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
}
pinMode(led, OUTPUT);
microservo.attach(7);
microservo2.attach(5);
// 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("<HTML>");
client.println("<HEAD>");
client.println("<meta http-equiv='Content-Type' content='text/html; charset=utf-8' /> ");
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://randomnerdtutorials.com/ethernetcss.css' />");
client.println("<TITLE>Управление LED+SERVO</TITLE>");
client.println("</HEAD>");
client.println("<BODY>");
client.println("<script type=\"text/javascript\">");
client.println("document.onkeydown = NavigateThrough;");
client.println("function NavigateThrough (event)");
client.println("{");
client.println("if (!document.getElementById) return;");
client.println("if (window.event) event = window.event;");
client.println("if (event.ctrlKey)");
client.println("{");
client.println("var link = null;");
client.println("var href = null;");
client.println("switch (event.keyCode ? event.keyCode : event.which ? event.which : null)");
client.println(" {");
client.println("case 0x25:");
client.println("link = document.getElementById ('servo_left');");
client.println("break;");
client.println("case 0x27:");
client.println("link = document.getElementById ('servo_right');");
client.println("break;");
client.println("case 0x26:");
client.println("link = document.getElementById ('servo_up');");
client.println("break;");
client.println("case 0x28:");
client.println("link = document.getElementById ('servo_dn');");
client.println("break;");
client.println("}");
client.println("if (link) document.location = link.href;");
client.println("}");
client.println("}");
client.println("</script>");
client.println("<H1>Управление LED+SERVO</H1>");
client.println("<hr />");
client.println("<br />");
client.println("<H2>Arduino + Ethernet Shield</H2>");
client.println("<br />");
client.println("<a href=\"/?button1on\"\">Включить LED</a>");
client.println("<a href=\"/?button1off\"\">Выключить LED</a><br />");
client.println("<br />");
client.println("<br />");
client.println("<a href=\"/?button2on\" id=\"servo_left\">Поворот влево</a>");
client.println("<a href=\"/?button2off\" id=\"servo_right\">Поворот вправо</a><br />");
client.println("<br />");
client.println("<br />");
client.println("<a href=\"/?button3on\" id=\"servo_up\">Поворот вверх</a>");
client.println("<a href=\"/?button3off\" id=\"servo_dn\">Поворот вниз</a><br />");
client.println("<br />");
client.println("КАМЕРА");
client.println("<br />");
client.println("<iframe src=\" http://www.alexor.ru/upload/medialibrary/8d9/10703.gif.jpg\" width=\"320\" height=\"240\"\"></iframe>");
client.println("<label for=fader>Управление по горизонтали</label><br>");
client.println("<label for=fader>ВЛЕВО  </label>");
client.println("<output for=fader id=volume1>0%</output>");
client.println("<label for=fader>  ВПРАВО</label><br>");
client.println("<input type=range min=-90 max=90 value=0 id=fader step=5 list=volsettings1 oninput=\"outputUpdate1(value)\">");
client.println("<datalist id=volsettings1>");
client.println("<option>-90</option>");
client.println("<option>-80</option>");
client.println("<option>-60</option>");
client.println("<option>-40</option>");
client.println("<option>-20</option>");
client.println("<option>0</option>");
client.println("<option>20</option>");
client.println("<option>40</option>");
client.println("<option>60</option>");
client.println("<option>80</option>");
client.println("<option>90</option>");
client.println("</datalist><br><br>");
client.println("<script>");
client.println("function outputUpdate1(vol) {");
client.println(" document.querySelector('#volume1').value = vol+\"%\";");
client.println(" var xhr = new XMLHttpRequest();");
client.println("if (vol<0){");
client.println(" xhr.open('GET','http://192.168.0.112/?'+vol);");
client.println(" xhr.send(null); ");
client.println(" }");
client.println("else {");
client.println(" xhr.open('GET','http://192.168.0.112/?'+vol);");
client.println(" xhr.send(null);");
client.println(" }");
client.println(" }");
client.println(" </script>");
client.println("</BODY>");
client.println("</HTML>");
delay(1);
//stopping client
client.stop();
//controls the Arduino if you press the buttons
if (readString.indexOf("?button1on") >0){
digitalWrite(led, HIGH);
// LEDON = true;
}
if (readString.indexOf("?button1off") >0){
digitalWrite(led, LOW);
// LEDON = false;
}
if(readString.indexOf("?button2on") >0) // ok
CAMLEFT();
if(readString.indexOf("?button2off") >0) // ok
CAMRIGHT();
if(readString.indexOf("?button3on") >0) // ok
CAMUP();
if(readString.indexOf("?button3off") >0) // ok
CAMDN();
readString="";
}
}
}
}
}
void CAMLEFT()
{
MYDATA1.servo_lr=max(MYDATA1.servo_lr-5,-90);
microservo.attach(7);
microservo.write(MYDATA1.servo_lr+90);
delay(200);
microservo.detach();
}
void CAMRIGHT()
{
MYDATA1.servo_lr=min(MYDATA1.servo_lr+5,90);
microservo.attach(7);
microservo.write(MYDATA1.servo_lr+90);
delay(200);
microservo.detach();
}
void CAMUP()
{
MYDATA1.servo_ud=min(MYDATA1.servo_ud+5,90);
microservo2.attach(5);
microservo2.write(MYDATA1.servo_ud+90);
delay(200);
microservo2.detach();
}
void CAMDN()
{
MYDATA1.servo_ud=max(MYDATA1.servo_ud-5,-90);
microservo2.attach(5);
microservo2.write(MYDATA1.servo_ud+90);
delay(200);
microservo2.detach();
}