Boa noite.

Galera, alguém poderia me ajudar a posicionar os botões que acendem o LED uma ao lado do outro?

Pretendo adicionar mais botões porém gostaria de colocá-los lado a lado.

Obrigado!!!

#include <LED.h>
#include <Ethernet.h>
#include <SPI.h>
#include <avr/pgmspace.h>

prog_char string_0[] PROGMEM = "<html><body><h2>Controle de LED pela Internet</h2><font size= 4><form method=GET>";
prog_char string_1[] PROGMEM = "<br><input type=submit name=b1 value=VARANDA>";
prog_char string_2[] PROGMEM = "<br><input type=submit name=b2 value=SALA>";
prog_char string_3[] PROGMEM = "</form></body></html>";
prog_char string_4[] PROGMEM = "<font color=green><b>Ligado</b></font>";
prog_char string_5[] PROGMEM = "<font color=red><b>Desligado</b></font>";
prog_char string_6[] PROGMEM = "<meta http-equiv=refresh content=30 > "; //for auto refresh

PROGMEM const char *string_table[] = // change "string_table" name to suit
{
string_0,
string_1,
string_2,
string_3,
string_4,
string_5,
string_6,
};

char buffer[85]; // make sure this is large enough for the largest string it must hold


byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
byte ip[] = { 192, 168, 1, 177 };
byte gateway[] = { 192, 168, 1, 1 };
byte subnet[] = { 255, 255, 255, 0 };

String inString = String(35);

Server server(80);

LED led1 = LED(4);
LED led2 = LED(5);

String msg="";
int tam=0;
int st1=5,st2=5;

void setup()
{
Serial.begin(9600);
Ethernet.begin(mac, ip,gateway,subnet);
server.begin();
Serial.println("Serial READY");
Serial.println("Ethernet READY");
Serial.println("Server READY");
pinMode(4,OUTPUT);
pinMode(5,OUTPUT);
}

void loop()
{

Client client = server.available();

int led=0;
if (client) {

// an http request ends with a blank line
boolean current_line_is_blank = true;
while (client.connected()) {

if (client.available()) {

char c = client.read();
// if we've gotten to the end of the line (received a newline
// character) and the line is blank, the http request has ended,
// so we can send a reply
if (inString.length() < 35) {
inString.concat(c);

}
if (c == '\n' && current_line_is_blank) {

if(inString.indexOf("b1")>0){

led1.toggle();
if(led1.getState()) st1=4;
else st1=5;
led=1;

}
if(inString.indexOf("b2")>0){

led2.toggle();
if(led2.getState()) st2=4;
else st2=5;
led=2;

}

if(inString.indexOf("msg")>0){
char charBuf1[50];
char charBuf2[50];
//strcpy(msg,(char*)inString.substring(inString.indexOf("g")+2,inString.indexOf(" H")));
//Serial.print("msg: ");
Serial.println(msg);
}

// send a standard http response header
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/html");
client.println();
client.println("<html><header><style>input {height:90px; width:90px }</style></header><body><form method=get>");

strcpy_P(buffer, (char*)pgm_read_word(&(string_table[0]))); // Necessary casts and dereferencing, just copy.
client.println( buffer );
for (int i = 1; i < 4; i++)
{
strcpy_P(buffer, (char*)pgm_read_word(&(string_table[i]))); // Necessary casts and dereferencing, just copy.
client.println( buffer );
switch(i){

case 1: strcpy_P(buffer, (char*)pgm_read_word(&(string_table[st1]))); client.println( buffer ); break;
case 2: strcpy_P(buffer, (char*)pgm_read_word(&(string_table[st2]))); client.println( buffer ); break;
}
delay(30);
}
/*if(digitalRead(8)==HIGH){
client.println("<br>Botao 1, ON");
}else{
client.println("<br>Botao 1, OFF");
}
if(digitalRead(9)==HIGH){
client.println("<br>Botao 2, ON");
}else{
client.println("<br>Botao 2, OFF");
}
*/
//strcpy_P(buffer, (char*)pgm_read_word(&(string_table[10]))); client.println( buffer );


break;
}
if (c == '\n') {
// we're starting a new line
current_line_is_blank = true;
} else if (c != '\r') {
// we've gotten a character on the current line
current_line_is_blank = false;
}
}
}
// give the web browser time to receive the data
delay(1);
inString = "";
client.stop();
}
}

Exibições: 432

Responder esta

Respostas a este tópico

Fala ai Alexandre, boa noite

Cara vamos ver se consigo te ajudar, alterei aonde aparece botao Varanda Botao Sala adicionei uma Table em HTML la.

Abraços

Max

#include <LED.h>
#include <Ethernet.h>
#include <SPI.h>
#include <avr/pgmspace.h>

prog_char string_0[] PROGMEM = "<html><meta http-equiv=refresh content=30 ><body>";//for auto refresh
prog_char string_1[] PROGMEM = "<h2>Controle de LED pela Internet</h2><form method=GET>
prog_char string_2[] PROGMEM = "<table><tr><td><input type=submit name=b1 value=VARANDA></td>";
prog_char string_3[] PROGMEM = "<td><input type=submit name=b2 value=SALA></td></tr>";
prog_char string_4[] PROGMEM = "<tr><td><font color=green><b>Ligado</b></font></td>";
prog_char string_5[] PROGMEM = "<td><font color=red><b>Desligado</b></font></td><tr></table>";
prog_char string_6[] PROGMEM = "</form></body></html> "; 

PROGMEM const char *string_table[] = // change "string_table" name to suit
{
string_0,
string_1,
string_2,
string_3,
string_4,
string_5,
string_6,
};

char buffer[85]; // make sure this is large enough for the largest string it must hold


byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
byte ip[] = { 192, 168, 1, 177 };
byte gateway[] = { 192, 168, 1, 1 };
byte subnet[] = { 255, 255, 255, 0 };

String inString = String(35);

Server server(80);

LED led1 = LED(4);
LED led2 = LED(5);

String msg="";
int tam=0;
int st1=5,st2=5;

void setup()
{
Serial.begin(9600);
Ethernet.begin(mac, ip,gateway,subnet);
server.begin();
Serial.println("Serial READY");
Serial.println("Ethernet READY");
Serial.println("Server READY");
pinMode(4,OUTPUT);
pinMode(5,OUTPUT);
}

void loop()
{

Client client = server.available();

int led=0;
if (client) {

// an http request ends with a blank line
boolean current_line_is_blank = true;
while (client.connected()) {

if (client.available()) {

char c = client.read();
// if we've gotten to the end of the line (received a newline
// character) and the line is blank, the http request has ended,
// so we can send a reply
if (inString.length() < 35) {
inString.concat(c);

}
if (c == '\n' && current_line_is_blank) {

if(inString.indexOf("b1")>0){

led1.toggle();
if(led1.getState()) st1=4;
else st1=5;
led=1;

}
if(inString.indexOf("b2")>0){

led2.toggle();
if(led2.getState()) st2=4;
else st2=5;
led=2;

}

if(inString.indexOf("msg")>0){
char charBuf1[50];
char charBuf2[50];
//strcpy(msg,(char*)inString.substring(inString.indexOf("g")+2,inString.indexOf(" H")));
//Serial.print("msg: ");
Serial.println(msg);
}

// send a standard http response header
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/html");
client.println();
client.println("<html><header><style>input {height:90px; width:90px }</style></header><body><form method=get>");

strcpy_P(buffer, (char*)pgm_read_word(&(string_table[0]))); // Necessary casts and dereferencing, just copy.
client.println( buffer );
for (int i = 1; i < 4; i++)
{
strcpy_P(buffer, (char*)pgm_read_word(&(string_table[i]))); // Necessary casts and dereferencing, just copy.
client.println( buffer );
switch(i){

case 1: strcpy_P(buffer, (char*)pgm_read_word(&(string_table[st1]))); client.println( buffer ); break;
case 2: strcpy_P(buffer, (char*)pgm_read_word(&(string_table[st2]))); client.println( buffer ); break;
}
delay(30);
}
/*if(digitalRead(8)==HIGH){
client.println("<br>Botao 1, ON");
}else{
client.println("<br>Botao 1, OFF");
}
if(digitalRead(9)==HIGH){
client.println("<br>Botao 2, ON");
}else{
client.println("<br>Botao 2, OFF");
}
*/
//strcpy_P(buffer, (char*)pgm_read_word(&(string_table[10]))); client.println( buffer );


break;
}
if (c == '\n') {
// we're starting a new line
current_line_is_blank = true;
} else if (c != '\r') {
// we've gotten a character on the current line
current_line_is_blank = false;
}
}
}
// give the web browser time to receive the data
delay(1);
inString = "";
client.stop();
}
}

Max, boa noite.

Agradeço a ajuda porém não funcionou.

Ao lado de cada botão fica o status do botão, "Ligado" ou "Desligado".

Com este código no 1º botão o status fica em cima e no 2º botão ao clicar para acender ele muda de posição.

Sabe o que poderia ser?

Obrigado.

RSS

© 2024   Criado por Marcelo Rodrigues.   Ativado por

Badges  |  Relatar um incidente  |  Termos de serviço