Could Someone Check This Please?

Hi,

Can digital outputs on an AtMega chip “float” if nothing is connected to them?

I have a chip connected to a Blynk app via an ESP that is providing the RTC, on the app I have a pair of LEDs monitoring the status of two digital outputs (7 & 8).

If my code is correct “timeState” should be “false” (as it’s currently 20:46) & yet the app LEDs keep changing state.

This is my hacked together code for “timeState” & the digital outputs:

timeState = (hour() == 5 && minute() >= 30)  || (hour() >= 6 && hour() <= 18);
  if (timeState = false) { // if it's night time
    digitalWrite(7, LOW); // Turn off heat lamp 1
    digitalWrite(8, LOW); }// Turn off heat lamp 2
  else { // if it's day time
    if (Temperature >= 30){ // if the temperatue is above 5 degrees
    digitalWrite(7, LOW); // turn off heat lamp 1
    digitalWrite(8, LOW); // turn off heat lamp 2
    }
    if (Temperature < 28){ // if the temperature is below 5 degrees
    digitalWrite(7, HIGH); // turn on heat lamp 1
    digitalWrite(8, LOW); // turn off heat lamp 2
    }
    if (Temperature < 27){ // if the temperature is below 1 degree
    digitalWrite(7, HIGH); // turn on heat lamp 1
    digitalWrite(8, HIGH); // turn on heat lamp 2
    }
  }
  

}
}

Please ignore the differing temperatures in the code & text.

Many thanks,

Mick.

  if (timeState = false) { // if it's night time

In this context '=' is much different from '=='.

johnwasser:   if (timeState = false) { // if it's night time

In this context '=' is much different from '=='.

Thank you,

So it should be == ?

Mick, you have got to post the whole code. Never post just part of it, unless you posted the whole code within the last few posts and this is a minor change. It's amazing how often the error is not in the part you think it might be. So please post the whole code, but before you do, please click Tools-->Auto Format, because your indentation is all screwed up right now.

Yes, in an if() function, you almost certainly want to be using == not =

PaulRB: Mick, you have got to post the whole code. Never post just part of it, unless you posted the whole code within the last few posts and this is a minor change. It's amazing how often the error is not in the part you think it might be. So please post the whole code, but before you do, please click Tools-->Auto Format, because your indentation is all screwed up right now.

Yes, in an if() function, you almost certainly want to be using == not =

Thanks, that appears to have fixed the issue.

Sorry for the indentation, I wasn't aware of the Auto Format function, it does make it easier to read!