Ciao a tutti ,da qualche giorno (essendo alle prime armi con arduino) mi sto scervellando per accendere 8 led da remoto con Arduino Ethernet ...
In rete avevo trovato un codice che faceva al caso mio ma puo' controllare solo un led...
#include <String.h>
#include <SPI.h>
#include <Ethernet.h>
/*
Simple Ethernet Test
Arduino server outputs simple text to browser
and controlling LED with simple checkbox
The circuit:
* Arduino Duemilanove
* Arduino Ethernet shield
* Basic FTDI breakout 5V
* LED connected to GND and digital pin 4 via resistor
*/
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; //physical mac address
byte ip[] = { 192, 168, 1, 123 }; // ip in lan
byte gateway[] = { 192, 168, 1, 1 }; // internet access via router
byte subnet[] = { 255, 255, 255, 0 }; //subnet mask
EthernetServer server(80); //server port
int ledPin = 9; // LED pin
char link[]="http://www.ioscripto.it"; //link data
String readString; //string
boolean LEDON = false; //LED status flag
void setup(){
Ethernet.begin(mac, ip, gateway, subnet);
pinMode(ledPin, OUTPUT);
Serial.begin(9600);
}
void loop(){
EthernetClient client = server.available();
if (client) {
boolean currentLineIsBlank = true;
while (client.connected()) {
if (client.available()) {
char c = client.read();
readString.concat(c); //store characters to string
//if HTTP request has ended
if (c == '\n' && currentLineIsBlank) {
Serial.print(readString);
if(readString.indexOf("L=1") > 0) {//lets check if LED should be lighted
//led has to be turned ON
digitalWrite(ledPin, HIGH); // set the LED on
LEDON = true;
}else{
//led has to be turned OFF
digitalWrite(ledPin, LOW); // set the LED OFF
LEDON = false;
}
// now output HTML data starting with standart header
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/html");
client.println();
// inizializzo pagina (da togliere se uso ajax)
client.print("<html><head><title>ARDUINO Controllo Led via WEB</title><meta http-equiv='Content-Type' content='text/html; charset=iso-8859-1' ></head><body>");
//send first heading
client.println("<h1>LED CONTROL by internet connection</h1>");
client.println("<hr />");
client.println("<h1>LED control</h1>");
//address will look like http://192.168.1.110/?L=1 when submited
client.println("<form method=get name=LED><input type=checkbox name=L value=1>LED
<input type=submit value=submit></form>");
client.println("
");
//printing LED status
client.print("<span>LED status: </span>");
if (LEDON) {
client.println("<span style='color:green'>ON</span>");
}
else
{
client.println("<span style='color:grey'>OFF</span>");
}
// chiudo pagina da togliere se uso ajax
client.println("</body></html>");
//clearing string for next read
readString="";
//stopping client
client.stop();
} //if c == /n .... devo capire che significa
} // if client available
} // while client connesso
} // if client
} //loo
Come posso fare per controllare 8 led con questo sitema??
Messaggio modificato da moderatore:
</mark> <mark>[code]</mark> <mark>
</mark> <mark>[/code]</mark> <mark>
tags aggiunto.