Page 1 of 1

Read status of heater and fan?

Posted: Thu Apr 11, 2013 6:01 am
by cosmith71
Is there a way to read if the heater and fan are on? I'd like to do a custom screen where the color of the temp reading changes with the status of the heater and fans.

Thanks,

--Colin

Re: Read status of heater and fan?

Posted: Thu Apr 11, 2013 6:22 am
by binder
Yes. You will need to use the function bitRead().

Code: Select all

// Check status of port 5
if (bitRead(ReefAngel.Relay.RelayData,Port5-1)) {
  // port 5 is on
} else {
  // port 5 is off
}
That code example will read the bit value of port5 and return a 1 if it's ON and a 0 if it's OFF. You will just need to replace the Port5 with whatever port you have your heater or fan plugged in.

Re: Read status of heater and fan?

Posted: Thu Apr 11, 2013 7:55 am
by rimai
This also works:

Code: Select all

boolean status =ReefAngel.Relay.Status(Port5);
The difference is that this method will report true if you override the port to always on and the other one doesn't.

Re: Read status of heater and fan?

Posted: Thu Apr 11, 2013 8:44 am
by cosmith71
Got it. Thanks guys!

--Colin

Re: Read status of heater and fan?

Posted: Tue Apr 16, 2013 9:49 am
by KRavEN
rimai wrote:This also works:

Code: Select all

boolean status =ReefAngel.Relay.Status(Port5);
The difference is that this method will report true if you override the port to always on and the other one doesn't.
Looking at the code it looks like either method is just reading the value of the relay status parameters. There is no Wire call to get the status of the port from the I2C relay device. What happens if a Relay.On() call is made but not a Relay.Write() or if there were some communication failure with the relay and the Relay.Write() didn't work?

Re: Read status of heater and fan?

Posted: Tue Apr 16, 2013 9:53 am
by rimai
Relay.Write() is called in each loop no matter what, but if the communication fails, it would pick up in the next loop.