Hi all, I have a programming question. I'm a noob and i don't know how to start so please help me.
I have an arduino mega 2560 r3 an ethernet shield 5100 and a toggle switch.
I would like to drive a small 220v lamp relay output is on pin 22
In the space below i have paste my code. This code put on or off my lamp via ip/web page, but how could I add a button (on pin 13 like input) so I could read his state and update webpage state?
Maaaaany thanks in advance
//---------------------------------------------------------
#include <Ethernet.h>
#include <SPI.h>
#include <WebServer.h> // webduino
//variabili statiche per il mac address e lìip address
static byte mac_Add[] = {
0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
//cambiare l'ip in funzione della propria rete
static byte ip_Add[] = {
192, 168, 1, 220 };
//creazione Webduino
WebServer webserver("", 80);
//Variabili per la memorizzazione uscite relè
boolean Rele_Camera= false;
//=============================================================================
//funzione pagina Start
void Start(WebServer &server, WebServer::ConnectionType type,
char *url_param, bool param_complete)
{
//restituisce al browser l'intestazione http 200 OK
server.httpSuccess();
//gestisco il tipo di richiesta HEAD
if (type != WebServer::HEAD)
{
String s = "";
if (param_complete == true)
{
s = url_param;
if ( s == "R1=ON")
{
Rele_Camera = true;
digitalWrite(22, LOW);
}
else if ( s == "R1=OFF")
{
Rele_Camera = false;
digitalWrite(22, HIGH);
}
P(htmlHead) =
""
""
"Controllo Rele"
""
"";
server.printP(htmlHead);
server.print("<table border="1">");
server.print("Stato ReleComandi");
if(Rele1 == true)
server.print("<td style="color: purple;">CAMERA ON");
else
server.print("<td style="color: black;">CAMERA OFF");
if(Rele1 == false)
server.print("<input type="button" value="clicca qui""
"onclick="location.href='index.htm?R1=ON'">");
else
server.print("<input type="button" value="clicca qui""
"onclick="location.href='index.htm?R1=OFF'">");
server.print("");
server.print("");
}
}
//=============================================================================
void setup()
{
//inizializzo l'ethernet shield con il mac e il address
Ethernet.begin(mac_Add, ip_Add);
//definisci l'azione di default che verrà eseguita quando l'utente
//naviga nella root del sito
webserver.setDefaultCommand(&Start);
webserver.addCommand("index.htm", &Start);
//avvia il web server
webserver.begin();
delay(100);
//definisci pin 22
pinMode(22, OUTPUT);
//inizializza i le uscite
digitalWrite(22, HIGH);
}
void loop()
{
webserver.processConnection();
}
//END