Countdown timer + ethernet shield

Hello everyone,

I’m having some problems to make a countdown timer with ethernet shield to show on my html file.

Actually, i want control relays with button, and when i press the button, turn relay off, automaticaly turns into “Timer - OFF” named and countdowntimer shows up but i was not able to make the command “tDown.start();” to start the countdown, everything else i believe is correct.

Can anyone help me with that?

I will be always thankful.

#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);
}
#include "Countimer.h"

This is not a core library. Surely you don’t expect us to guess where you got it.

My bad, i was very sleepy… hahaha

Librarie in attach

Countimer-master.zip (4.39 KB)

OK. Now that we have the library issue squared away, and can see what the library does, what does

countdowntimer shows up but i was not able to make the command "tDown.start();" to start the countdown

mean?

Why are you not able to call the start() method? When do you want to call it?

PaulS: OK. Now that we have the library issue squared away, and can see what the library does, what doesmean?

Why are you not able to call the start() method? When do you want to call it?

I want to call start() when i press button created on the html file.

When button turns/show OFF, automatically shows up timer set with "tDown.setCounter" and start the countdown.

I tryed already in the action that makes button turn OFF (client.print) and on the valPag.endsWith if but i don't know what i did wrong, dosnt work because all my code didn't work very well later that.

So, you tried something, somewhere. It did not do what you expected, so you don't want to share that code. That's understandable.

But, you want us to tell you what you did wrong, and how to fix it. That is not understandable.

PaulS: So, you tried something, somewhere. It did not do what you expected, so you don't want to share that code. That's understandable.

But, you want us to tell you what you did wrong, and how to fix it. That is not understandable.

What?

Code is on my first post.

I still didn't figured how to fix it.

You have to call the start() function on Countimer object. Try this in your loop:

void loop()
{
    acionamentos();

    tDown.run();

    if(!tDown.isCounterCompleted()) {
    tDown.start();
    }
    
    EthernetClient client = server.available();
    ...

 }