Varible constantly setting itself to 0 and I don't know why

Im trying to create a clock to use for automating LED events at a certain time of day (I do not want to buy a RTC), but for some reason in the clock I made it keeps contantly setting the seconds to 0 every time it runs. I have very little arduino coding experience.

Code :

String T = "Time: ";
String H = " hours, ";
String M = " minutes, ";
String S = " seconds";

int s;
int m;
int h;

void setup()
{
  Serial.begin(9600);
}
void loop() {

  delay(1000);

  if (s < 60);
  {
    s = s + 1;

    Serial.print("Time: ");
    Serial.print(s);
    Serial.println(S);
  }

  if (s = 60)
  {
    m = m + 1;
    s = 0;
    Serial.print("Time: ");
    Serial.print(m);
    Serial.print(M);
    Serial.print(s);
    Serial.println(S);
  }

  if (m = 60)
  {
    h += 1;
    m = 0;
    s = 0;
    Serial.print("Time: ");
    Serial.print(h);
    Serial.print(H);
    Serial.print(m);
    Serial.print(M);
    Serial.print(s);
    Serial.println(S);
  }

  if (h = 24)
  {
    h = 0;
    m = 0;
    s = 0;
    Serial.print("Time: ");
    Serial.print(s);
    Serial.println(S);
  }
}

A typical beginners error:

s=60 is an assignment. You mean a comparison s==60.

I did that the first time and it didn't work. But for some reason it wants to now, so thanks. :+1:

You can use the TimeLib library without an RTC. It will keep track of time using millis() in the background (non-blocking) and won't be nearly as much of a hack as what you're trying to do.

I was unaware that there was such a library, but also the problem with using the library is that i have no idea how to. And my code does its job fine so far.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.