Bom dia pessoal,
Estou tendo um problema em criar um contador regressivo para mostrar junto ao código html do ethernet.
Ao clicar no botão e o mesmo virar na opção OFF, ele fará aparecer o valor setado de timer no comando “tDown.setCounter” e assim começar a contagem regressiva até zero.
Porém, ao clicar e o botão virar OFF, apenas consegui fazer aparecer o timer e não de fato começar a contagem com o comando start(), se coloco o start() ele faz estragar o resto do código, tentei tanto colocar o comando de start na função de transformar o botão em off quanto no de mudar o status.
Segue código abaixo e em anexo a libraries.
Alguem saberia como faço para dar o start assim que o botão virar OFF?
Obrigado.
#define Tempo 2
#include <SPI.h>
#include <Ethernet.h
#include "Countimer.h"
Countimer tDown;
byte mac[] = { 0x90, 0xA2, 0xDA, 0x0D, 0x83, 0xEA };
IPAddress ip(192,168,1,177);
byte gateway[] = { 192 , 168, 1, 1 };
byte subnet[] = { 255, 255, 255, 0 };
EthernetServer server(80);
byte COD = B1000;
String A2_carga = "Timer";
boolean A2_estado=false;
void setup()
{
pinMode(Tempo,OUTPUT);
Ethernet.begin(mac, ip);
tDown.setCounter(0, 0, 21, tDown.COUNT_DOWN, tDownComplete);
}
void loop()
{
acionamentos();
tDown.run(); // AQUI ATIVA O TIMER
EthernetClient client = server.available();
if (client)
{
boolean currentLineIsBlank = true;
String valPag;
while (client.connected())
{
if (client.available())
{
char c = client.read();
valPag.concat(c);
if(valPag.endsWith("0001"))
{
COD = COD ^ B0001;
A2_estado = !A2_estado;
}
if (c == '\n' && currentLineIsBlank)
{
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/html");
client.println();
client.print("<HTML> ");
client.println("<head>");
client.println("<title>Timer</title>");
client.println("<meta http-equiv='Content-Type' content='text/html; charset=ISO-8859-1'>");
client.println("</head>");
client.println("<body>");
client.print("
");
//=========================================================================================================================
//Botao Timer
client.print("<center><button onclick=\"window.location.href='http://192.168.1.177/0001'\">\0</button> > Codigo: 0001 > ");
if(A2_estado)
{
client.print("<B><span style=\"color: #ff0000;\">");
client.print(A2_carga);
client.print(" - OFF");
client.print("</span></B></center>
");
client.print(tDown.getCurrentTime()); //AQUI MOSTRA O TEMPO QUE FALTA DEFINIDO NO SETCOUNTER
}
else
{
client.print("<B><span style=\"color: #28bf7b;\">");
client.print(A2_carga);
client.print(" - ON");
client.print("</span></B></center>
");
}
client.print("");
client.print(" <meta http-equiv=\"refresh\" content=\"5; url=http://192.168.1.177/\"> ");
client.println("</HTML>");
break;
}
}
}
delay(3);
client.stop();
}
}
void acionamentos()
{
if(A2_estado) digitalWrite(Tempo,HIGH);
else digitalWrite(Tempo,LOW);
}
void tDownComplete()
{
digitalWrite(13, LOW);
}
Countimer-master.zip (4.39 KB)