for(int i=1;i < (numofrelays + 1) ;i++){
R = String("R") + i;
if(inString.indexOf(R+"=off")>0 || inString.indexOf("all=on")>0){

digitalWrite(r[i], HIGH);
value[i] = "on";
}else if(inString.indexOf(R+"=on")>0 || inString.indexOf("all=off")>0 ){

digitalWrite(r[i], LOW);
value[i] = "off";
}
client.println("<br>"+R+" <input type=submit name="+R+" value="+value[i]+">");
}
client.println("<br>All <input type=submit name=all value=off><input type=submit name=all value=on>");
client.println("</from></html></body>");

isto e o código que esto usando para o botao

gostava de meter vermelho no off e verde no on

Exibições: 3158

Responder esta

Respostas a este tópico

<html>

<style>

input {background-color:red; font-color:blue;}

input :hover {background-color:lime; font-color:teal;}

</style>

<title>minha pagina</title>

<body>

<form>

Digite dados:<br>

<input type="text" name="variavel" ></a><p>

<input type="submit" name="teste" value="Clica em mim"></a>

</form>

</body>

</html>

client.println("<html>");

client.println("<style>");

char S[4];

for(int i=1;i < (numofrelays + 1) ;i++){
R = String("R") + i;
if(inString.indexOf(R+"=off")>0 || inString.indexOf("all=on")>0){

S="BLUE";

client.println(" input {background-color:"+ S+ ";}</style>");

digitalWrite(r[i], HIGH);
value[i] = "on";
}

else if(inString.indexOf(R+"=on")>0 || inString.indexOf("all=off")>0 ){

S="Lime";

client.println(" input {background-color:"+ S+ ";}</style>");

digitalWrite(r[i], LOW);
value[i] = "off";
}


client.println("<br>"+R+" <input type=submit name="+R+" value="+value[i]+">");
}

client.println("<form>");
client.println("<br>All <input type=submit name=all value=off><input type=submit name=all value=on>");
client.println("</form></html></body>");   //form e não from

#include <Ethernet.h>
#include <SPI.h>
//network NB: Pins 10, 11, 12 and 13 are reserved for Ethernet module.
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
byte ip[] = { 192, 168, 0, 177 };

String inString = String(35);

String Led;

int led[] = {00, 2, 3, 4 ,5 ,6 ,7 ,8,9 }; //Led pins num 0 in arry is not used
int numofleds = 8; //numofleds
String value[] = {"on","on","on","on","on","on","on","on","on"}; //startup all led are off

EthernetServer server(80);
String data;
void setup()
{
Serial.begin(9600);
Ethernet.begin(mac, ip);
server.begin();
//set pin mode
for (int j = 1; j < (numofleds + 1); j++){
pinMode(led[j], OUTPUT);
}
Serial.println("Serial READY");
Serial.println("Ethernet READY");
Serial.println("Server READY");
}

void loop()
{
EthernetClient client = server.available();

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) {

// send a standard http response header
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/html");
client.println();
client.println("<html><body><form method=get>");
client.println("<p>Led controller</p>");

for(int i=1;i < (numofleds + 1) ;i++){
Led = String("led") + i;

if(inString.indexOf(Led+"=on")>0 || inString.indexOf("all=on")>0){
Serial.println(Led+"on");
digitalWrite(led[i], HIGH);
value[i] = "off";
}else if(inString.indexOf(Led+"=off")>0 || inString.indexOf("all=off")>0 ){
Serial.println(Led+"on");
digitalWrite(led[i], LOW);
value[i] = "on";
}
client.println("<br>"+Led+" <input type=submit name="+Led+" value="+value[i]+">");
}
client.println("<br>All <input type=submit name=all value=on><input type=submit name=all value=off>");
client.println("</from></html></body>");
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();
}
}

código completo

quando complico com o código que me deu da me este erro

TESTwebv2_11.ino: In function 'void loop()':
TESTwebv2_11:216: error: invalid array assignment
TESTwebv2_11:218: error: invalid operands of types 'const char [26]' and 'char [5]' to binary 'operator+'
TESTwebv2_11:227: error: invalid array assignment
TESTwebv2_11:229: error: invalid operands of types 'const char [26]' and 'char [5]' to binary 'operator+'

No exemplo resumido acima,não existe o codigo todo.Apenas trecho onde mostra que variavel S deve receber a cor para o input do html

vc nao pode me passar esse code ja com cores nos botaoes obg

Podes colocar o código todo?

Isso eh facil com CSS:

client.prinln("

<style>

input[value=off] { background-color: #0f0; }

input[value=on] { background-color: #f00; }

</style>");

RSS

© 2024   Criado por Marcelo Rodrigues.   Ativado por

Badges  |  Relatar um incidente  |  Termos de serviço