Page 1 of 2

Get count when relay is on or off

PostPosted: Tue Jan 30, 2018 2:08 pm
by Armetas
Hello,

I'm wondering if there are some ways to count how many times relay is turned on or off in the arduino? For example: when we use temp probes in order to switch on/off heater: if temp less than 25 turn on heater and if more than 26 turn off heater. And if during the day temp drops 3 times and heater is turned on 3 times - so is it possible to calculate such thing and use somewhere else in the code?

Re: Get count when relay is on or off

PostPosted: Tue Jan 30, 2018 2:46 pm
by rimai
You can count for a day and store the data in a custom variable.
It would show up as custom variable.

Re: Get count when relay is on or off

PostPosted: Tue Jan 30, 2018 2:51 pm
by Armetas
rimai wrote:You can count for a day and store the data in a custom variable.
It would show up as custom variable.


But how to write such code in order to have such count? If I put code in the loop section when temp is less 25 then add 1 to the count - the count grows each milisecond

Re: Get count when relay is on or off

PostPosted: Tue Jan 30, 2018 7:17 pm
by rimai
You need a variable to control that.
Code: Select all
static boolean control=false;
if (ReefAngel.Relay.IsOn(Port1) && control==false)
{
  control=true;
  ReefAngel.CustomVar[0]++;
}
if (ReefAngel.Relay.IsOff(Port1) && control==true)
{
  control=false;
}

Re: Get count when relay is on or off

PostPosted: Wed Jan 31, 2018 12:10 am
by Armetas
Thanks!

By the way is there any possibility to have more custom variables that could be seen in the app? Or at least have some of them as text (not as number)?

Re: Get count when relay is on or off

PostPosted: Wed Jan 31, 2018 5:23 am
by binder
custom variables are visible in my android app.

Sent from my XT1585 using Tapatalk

Re: Get count when relay is on or off

PostPosted: Wed Jan 31, 2018 5:24 am
by Armetas
rimai wrote:You need a variable to control that.
Code: Select all
static boolean control=false;
if (ReefAngel.Relay.IsOn(Port1) && control==false)
{
  control=true;
  ReefAngel.CustomVar[0]++;
}
if (ReefAngel.Relay.IsOff(Port1) && control==true)
{
  control=false;
}


I'm getting compile error :(

error: 'class RelayClass' has no member named 'IsOn'
error: 'class RelayClass' has no member named 'IsOff'

Re: Get count when relay is on or off

PostPosted: Wed Jan 31, 2018 5:43 am
by Armetas
binder wrote:custom variables are visible in my android app.

Sent from my XT1585 using Tapatalk


Only 7 are available and all of them are number which cannot exceed ~300
I would like to have more variables shown on android app or have them as text (as I'm trying to display some information for reporting failures in my reef)

Re: Get count when relay is on or off

PostPosted: Wed Jan 31, 2018 6:53 pm
by rimai
Sorry. Try this:
Code: Select all
static boolean control=false;
if (ReefAngel.Relay.Status(Port1)==true && control==false)
{
  control=true;
  ReefAngel.CustomVar[0]++;
}
if (ReefAngel.Relay.Status(Port1)==false && control==true)
{
  control=false;
}

Re: Get count when relay is on or off

PostPosted: Wed Jan 31, 2018 9:00 pm
by binder
Armetas wrote:
binder wrote:custom variables are visible in my android app.

Sent from my XT1585 using Tapatalk


Only 7 are available and all of them are number which cannot exceed ~300
I would like to have more variables shown on android app or have them as text (as I'm trying to display some information for reporting failures in my reef)
Ahhhh... gotcha. the libraries would have to be modified to allow for larger values or to display text instead.
most likely it would have to be additional custom variables added instead of the same ones...or maybe not (at least for getting larger values). the text would require separate variables.

Sent from my XT1585 using Tapatalk