Multiple on/off times

Do you have a question on how to do something.
Ask in here.
User avatar
Sacohen
Posts: 1833
Joined: Sun Apr 21, 2013 6:25 am
Location: Davie, FL

Multiple on/off times

Post by Sacohen »

I'm not quite ready to do this, so I don't need to get into coding it yet.

I have a de-nitrification chamber that I pump water from the sump into 4 times a day.
1am, 7am, 1pm and 7pm.

It runs for 25 min and then triggers a dosing pump I have that drips the nitragone into the chamber for 21 min.

My main question right now is can I do something like this?
User avatar
cosmith71
Posts: 1437
Joined: Fri Mar 29, 2013 3:51 pm
Location: Oklahoma City

Re: Multiple on/off times

Post by cosmith71 »

Yep, set them up as dosing pumps. Let me see if the wizard can do that for you...
User avatar
cosmith71
Posts: 1437
Joined: Fri Mar 29, 2013 3:51 pm
Location: Oklahoma City

Re: Multiple on/off times

Post by cosmith71 »

Wizard doesn't like the 25 minutes. Can one of the programming geniuses chime in?

--C
User avatar
Sacohen
Posts: 1833
Joined: Sun Apr 21, 2013 6:25 am
Location: Davie, FL

Re: Multiple on/off times

Post by Sacohen »

The dosing pump is setup for starting every x minutes for x seconds.
I didn't try it, but I didn't think it would work with a 4 hr time span for 20 to 25 min.

I'm sure there is a way to do it, but like I said it doesn't need to be nailed down right now.
rimai
Posts: 12881
Joined: Fri Mar 18, 2011 6:47 pm

Re: Multiple on/off times

Post by rimai »

Yes, it is easy to do.
Roberto.
User avatar
Sacohen
Posts: 1833
Joined: Sun Apr 21, 2013 6:25 am
Location: Davie, FL

Re: Multiple on/off times

Post by Sacohen »

Great. When I get to that step of setting everything up I will re-visit this topic.
User avatar
Sacohen
Posts: 1833
Joined: Sun Apr 21, 2013 6:25 am
Location: Davie, FL

Re: Multiple on/off times

Post by Sacohen »

Ok. I'm ready to get this done.
I want to control my NatuReef de-nitrification chamber with the Reef Angel.
Port 5 needs to come on for 20 min.
When that is done Port 8 needs to come on for 20min.
I need to do this 4 times a day at 1am, 7am 1pm and 7pm (with the ability to add more cycles in the future)

While all this is happening (or at least the first 20min when the pump in the sump is exchanging water) I want to disable the Water Level Expansion (Port6) from coming on and adding water to the sump.
rimai
Posts: 12881
Joined: Fri Mar 18, 2011 6:47 pm

Re: Multiple on/off times

Post by rimai »

Try this:

Code: Select all

  ReefAngel.Relay.Set(Port5,now()%21600<1200) // Runs for 1200s every 21600 seconds
  ReefAngel.Relay.Set(Port8,(now()+1200)%21600<1200) // Runs for 1200s every 21600 seconds with 1200s offset
  if (ReefAngel.Relay.Status(Port5))
    ReefAngel.Relay.Off(Port6);
  else
    ReefAngel.WaterLevelATO(Port6,60,75,79);
Roberto.
User avatar
Sacohen
Posts: 1833
Joined: Sun Apr 21, 2013 6:25 am
Location: Davie, FL

Re: Multiple on/off times

Post by Sacohen »

Roberto;

I'm getting the following error when I added the code above and changed the parameters for the Water Lever.
Steves_Custom_Wave_Sketch.cpp: In function 'void loop()':
Steves_Custom_Wave_Sketch:72: error: expected `;' before 'ReefAngel'
Steves_Custom_Wave_Sketch:75: error: 'else' without a previous 'if'
It looks like it is referring to something in the custom wave section, but I didn't touch that, I just added your code right before the Custom Wave code.


Here is my full code;

Code: Select all

[quote]
#include <ReefAngel_Features.h>
#include <Globals.h>
#include <RA_Wifi.h>
#include <[color=#CC6600]Wire[/color].h>
#include <[color=#CC6600]OneWire[/color].h>
#include <Time.h>
#include <DS1307RTC.h>
#include <InternalEEPROM.h>
#include <RA_NokiaLCD.h>
#include <RA_ATO.h>
#include <RA_Joystick.h>
#include <[color=#006699]LED[/color].h>
#include <RA_TempSensor.h>
#include <[color=#006699]Relay[/color].h>
#include <RA_PWM.h>
#include <[color=#006699]Timer[/color].h>
#include <Memory.h>
#include <InternalEEPROM.h>
#include <RA_Colors.h>
#include <RA_CustomColors.h>
#include <[color=#006699]Salinity[/color].h>
#include <[color=#006699]RF[/color].h>
#include <[color=#006699]IO[/color].h>
#include <[color=#006699]ORP[/color].h>
#include <[color=#006699]AI[/color].h>
#include <[color=#006699]PH[/color].h>
#include <[color=#006699]WaterLevel[/color].h>
#include <[color=#CC6600]ReefAngel[/color].h>

[color=#7E7E7E]////// Place global variable code below here[/color]


[color=#7E7E7E]////// Place global variable code above here[/color]


[color=#CC6600]void[/color] [color=#CC6600][b]setup[/b][/color]()
{
    [color=#7E7E7E]// This must be the first line[/color]
    [color=#CC6600]ReefAngel[/color].[color=#CC6600]Init[/color]();  [color=#7E7E7E]//Initialize controller[/color]
    [color=#7E7E7E]// Ports toggled in Feeding Mode[/color]
    [color=#CC6600]ReefAngel[/color].[color=#006699]FeedingModePorts[/color] = 0;
    [color=#7E7E7E]// Ports toggled in Water Change Mode[/color]
    [color=#CC6600]ReefAngel[/color].[color=#006699]WaterChangePorts[/color] = [color=#006699]Port4Bit[/color];
    [color=#7E7E7E]// Ports toggled when Lights On / Off menu entry selected[/color]
    [color=#CC6600]ReefAngel[/color].[color=#006699]LightsOnPorts[/color] = [color=#006699]Port1Bit[/color] | [color=#006699]Port2Bit[/color];
    [color=#7E7E7E]// Ports turned off when Overheat temperature exceeded[/color]
    [color=#CC6600]ReefAngel[/color].[color=#006699]OverheatShutoffPorts[/color] = [color=#006699]Port1Bit[/color] | [color=#006699]Port2Bit[/color];
    [color=#7E7E7E]// Use T2 probe as temperature and overheat functions[/color]
    [color=#CC6600]ReefAngel[/color].[color=#006699]TempProbe[/color] = [color=#006699]T2_PROBE[/color];
    [color=#CC6600]ReefAngel[/color].[color=#006699]OverheatProbe[/color] = [color=#006699]T2_PROBE[/color];
    [color=#7E7E7E]// Set the Overheat temperature setting[/color]
    [color=#CC6600]InternalMemory[/color].[color=#CC6600]OverheatTemp_write[/color]( 825 );
    [color=#7E7E7E]//Set Standard Menu[/color]
    [color=#CC6600]ReefAngel[/color].[color=#CC6600]AddStandardMenu[/color]();


    [color=#7E7E7E]// Ports that are always on[/color]
    [color=#CC6600]ReefAngel[/color].[color=#006699]Relay[/color].[color=#CC6600]On[/color]( [color=#006699]Port4[/color] );

    [color=#7E7E7E]////// Place additional initialization code below here[/color]
    

    [color=#7E7E7E]////// Place additional initialization code above here[/color]
}

[color=#CC6600]void[/color] [color=#CC6600][b]loop[/b][/color]()
{
    [color=#CC6600]ReefAngel[/color].[color=#CC6600]StandardLights[/color]( [color=#006699]Port1[/color],12,0,22,0 );
    [color=#CC6600]ReefAngel[/color].[color=#CC6600]StandardLights[/color]( [color=#006699]Port2[/color],13,0,21,0 );
    [color=#CC6600]ReefAngel[/color].[color=#006699]Relay[/color].[color=#CC6600]Set[/color]( [color=#006699]Port3[/color], ![color=#CC6600]ReefAngel[/color].[color=#006699]Relay[/color].[color=#CC6600]Status[/color]( [color=#006699]Port1[/color] ) );
    [color=#CC6600]ReefAngel[/color].[color=#CC6600]StandardLights[/color]( [color=#006699]Port7[/color],13,0,21,0 );
  [color=#CC6600]ReefAngel[/color].[color=#006699]Relay[/color].[color=#CC6600]Set[/color]([color=#006699]Port5[/color],[color=#CC6600]now[/color]()%21600<1200) [color=#7E7E7E]// Runs for 1200s every 21600 seconds[/color]
  [color=#CC6600]ReefAngel[/color].[color=#006699]Relay[/color].[color=#CC6600]Set[/color]([color=#006699]Port8[/color],([color=#CC6600]now[/color]()+1200)%21600<1200) [color=#7E7E7E]// Runs for 1200s every 21600 seconds with 1200s offset[/color]
  [color=#CC6600]if[/color] ([color=#CC6600]ReefAngel[/color].[color=#006699]Relay[/color].[color=#CC6600]Status[/color]([color=#006699]Port5[/color]))
    [color=#CC6600]ReefAngel[/color].[color=#006699]Relay[/color].[color=#CC6600]Off[/color]([color=#006699]Port6[/color]);
  [color=#CC6600]else[/color]
    [color=#CC6600]ReefAngel[/color].[color=#CC6600]WaterLevelATO[/color]([color=#006699]Port6[/color],720,21,23);
    [color=#CC6600]ReefAngel[/color].[color=#006699]PWM[/color].[color=#CC6600]SetActinic[/color](MyCustomWave(50));
    [color=#CC6600]if[/color]( [color=#CC6600]ReefAngel[/color].[color=#006699]DisplayedMenu[/color]==[color=#006699]FEEDING_MODE[/color] ) [color=#CC6600]ReefAngel[/color].[color=#006699]PWM[/color].[color=#CC6600]SetActinic[/color](0);
    [color=#CC6600]if[/color]( [color=#CC6600]ReefAngel[/color].[color=#006699]DisplayedMenu[/color]==[color=#006699]WATERCHANGE_MODE[/color] ) [color=#CC6600]ReefAngel[/color].[color=#006699]PWM[/color].[color=#CC6600]SetActinic[/color](0);
    [color=#CC6600]if[/color] (hour()<12 || hour()>=22) [color=#CC6600]ReefAngel[/color].[color=#006699]PWM[/color].[color=#CC6600]SetActinic[/color](30);
    [color=#7E7E7E]////// Place your custom code below here[/color]
    

    [color=#7E7E7E]////// Place your custom code above here[/color]

    [color=#7E7E7E]// This should always be the last line[/color]
    [color=#CC6600]ReefAngel[/color].[color=#CC6600]Portal[/color]( [color=#006699]"Sacohen"[/color],[color=#006699]"Seth0310"[/color] );
    [color=#CC6600]ReefAngel[/color].[color=#CC6600]ShowInterface[/color]();
}

[color=#CC6600]void[/color] DrawCustomMain()
{
    [color=#CC6600]int[/color] x,y;
    [color=#CC6600]char[/color] text[10];
    [color=#7E7E7E]// Parameters[/color]
#if defined DisplayLEDPWM && ! defined RemoveAllLights
    [color=#CC6600]ReefAngel[/color].[color=#006699]LCD[/color].[color=#CC6600]DrawMonitor[/color]( 15, 20, [color=#CC6600]ReefAngel[/color].[color=#006699]Params[/color],
    [color=#CC6600]ReefAngel[/color].[color=#006699]PWM[/color].[color=#CC6600]GetDaylightValue[/color](), [color=#CC6600]ReefAngel[/color].[color=#006699]PWM[/color].[color=#CC6600]GetActinicValue[/color]() );
#else [color=#7E7E7E]// defined DisplayLEDPWM && ! defined RemoveAllLights[/color]
    [color=#CC6600]ReefAngel[/color].[color=#006699]LCD[/color].[color=#CC6600]DrawMonitor[/color]( 15, 20, [color=#CC6600]ReefAngel[/color].[color=#006699]Params[/color] );
#endif [color=#7E7E7E]// defined DisplayLEDPWM && ! defined RemoveAllLights[/color]
    [color=#CC6600]pingSerial[/color]();

    [color=#7E7E7E]// Water Level[/color]
    [color=#CC6600]ReefAngel[/color].[color=#006699]LCD[/color].[color=#CC6600]DrawText[/color]( COLOR_DARKGOLDENROD,DefaultBGColor,75,66, [color=#006699]"WL:"[/color] );
    [color=#CC6600]ReefAngel[/color].[color=#006699]LCD[/color].[color=#CC6600]DrawText[/color]( COLOR_DARKGOLDENROD,DefaultBGColor,99,66, [color=#CC6600]ReefAngel[/color].[color=#006699]WaterLevel[/color].[color=#CC6600]GetLevel[/color]() );
    [color=#CC6600]pingSerial[/color]();

    [color=#7E7E7E]// Main Relay Box[/color]
    [color=#CC6600]byte[/color] TempRelay = [color=#CC6600]ReefAngel[/color].[color=#006699]Relay[/color].[color=#006699]RelayData[/color];
    TempRelay &= [color=#CC6600]ReefAngel[/color].[color=#006699]Relay[/color].[color=#006699]RelayMaskOff[/color];
    TempRelay |= [color=#CC6600]ReefAngel[/color].[color=#006699]Relay[/color].[color=#006699]RelayMaskOn[/color];
    [color=#CC6600]ReefAngel[/color].[color=#006699]LCD[/color].[color=#CC6600]DrawOutletBox[/color]( 12, 92, TempRelay );
    [color=#CC6600]pingSerial[/color]();

    [color=#7E7E7E]// Date and Time[/color]
    [color=#CC6600]ReefAngel[/color].[color=#006699]LCD[/color].[color=#CC6600]DrawDate[/color]( 6, 122 );
    [color=#CC6600]pingSerial[/color]();
}

[color=#CC6600]void[/color] DrawCustomGraph()
{
}
[color=#CC6600]byte[/color] MyCustomWave([color=#CC6600]byte[/color] maxspeed)
{
  [color=#CC6600]static[/color] [color=#CC6600]byte[/color] randomspeed=0;
  [color=#CC6600]if[/color] ([color=#CC6600]now[/color]()%11<5)
  {
    [color=#CC6600]return[/color] randomspeed;
  }
  [color=#CC6600]else[/color] [color=#CC6600]if[/color] ([color=#CC6600]now[/color]()%11>=5 && [color=#CC6600]now[/color]()%11<10)
  {
    [color=#CC6600]return[/color] maxspeed;
  }
  [color=#CC6600]else[/color]
  {
    randomspeed=[color=#CC6600]random[/color](35,maxspeed);
    [color=#CC6600]return[/color] 0;
  }
}

[/quote]
rimai
Posts: 12881
Joined: Fri Mar 18, 2011 6:47 pm

Re: Multiple on/off times

Post by rimai »

Oh, sorry...
I missed two ; at the end of the first 2 lines before the comments.
Roberto.
User avatar
Sacohen
Posts: 1833
Joined: Sun Apr 21, 2013 6:25 am
Location: Davie, FL

Re: Multiple on/off times

Post by Sacohen »

It looks like just one right here after <1200) and before the comment

ReefAngel.Relay.Set(Port5,now()%21600<1200); // Runs for 1200s every 21600 seconds
if (ReefAngel.Relay.Status(Port5))
ReefAngel.Relay.Off(Port6);

If I put a ; after the (Port5) I get an error.
If I put 2 ; after <1200) and before the comment it compiles fine also.

Which should it be?
User avatar
lnevo
Posts: 5430
Joined: Fri Jul 20, 2012 9:42 am

Multiple on/off times

Post by lnevo »

Something else is wrong. Its not that line. Check the few lines above.
User avatar
Sacohen
Posts: 1833
Joined: Sun Apr 21, 2013 6:25 am
Location: Davie, FL

Re: Multiple on/off times

Post by Sacohen »

Is it this line...

ReefAngel.Relay.Set( Port3, !ReefAngel.Relay.Status( Port1 ) );

That looks wrong to me, but I'm not sure how it is supposed to be.
I ran thru the wizard again and that's how it came out again.

From everything else I see it looks like it should be like this...

ReefAngel.Relay.Set( Port3, );
ReefAngel.Relay.Status( Port1 );

But Port3 is supposed to be opposite Port1.
User avatar
lnevo
Posts: 5430
Joined: Fri Jul 20, 2012 9:42 am

Re: Multiple on/off times

Post by lnevo »

It's these two lines...

This is how it should look:

Code: Select all

 
ReefAngel.Relay.Set(Port5,now()%21600<1200); // Runs for 1200s every 21600 seconds 
ReefAngel.Relay.Set(Port8,(now()+1200)%21600<1200); // Runs for 1200s every 21600 seconds with 1200s offset
They were both missing the ;
User avatar
Sacohen
Posts: 1833
Joined: Sun Apr 21, 2013 6:25 am
Location: Davie, FL

Re: Multiple on/off times

Post by Sacohen »

Thanks somehow when I was checking and changing things I deleted the 2nd line...

Code: Select all

ReefAngel.Relay.Set(Port8,(now()+1200)%21600<1200); // Runs for 1200s every 21600 seconds with 1200s offset
Something else strange is going on now. My water level has stopped working.

It started showing 200% and then went to 0%.

I tried running the Water Calibration again and when it runs the 100% portion it shows 0%.

Now it is switching between 200% and 0% and I here Port6 which controls the ATO Pump switching on and off.
I unplugged the ATO pump when it went to 200% the first time because it started putting water in the sump.

I don't think it is this code, because I haven't uploaded it yet.

Take a look at the relay activity for Port 6...

Image
User avatar
Sacohen
Posts: 1833
Joined: Sun Apr 21, 2013 6:25 am
Location: Davie, FL

Re: Multiple on/off times

Post by Sacohen »

Roberto or Lee can you explain what the code is doing?

Code: Select all

  ReefAngel.Relay.Set(Port5,now()%21600<1200); // Runs for 1200s every 21600 seconds
  ReefAngel.Relay.Set(Port8,(now()+1200)%21600<1200); // Runs for 1200s every 21600 seconds with 1200s offset
  if (ReefAngel.Relay.Status(Port5))
    ReefAngel.Relay.Off(Port6);
  else
    ReefAngel.WaterLevelATO(Port6,60,75,79);
Obviously the comments say Runs for 1200s every 21600 seconds and Runs for 1200s every 21600 seconds with 1200s offset and that translates to runs for 20 min every 6 hours and runs form 20 min every 6 hours with a 20 min offset.

It isn't working right and I want to not only try to figure it out, but understand what is written so I can write more in the future.

At 11:40 pm Port 8 came on and went of at 12:00 am and then Port5 came on at 12:00am and went off at 12:20am.

Then at Port At 5:36 Port8 came on and went of at 5:56 am and Port5 came on at 5:56 am and off at 6:16am.

First of all Port5 should come on before Port8.
Second it needs to happen at 1am not 12am and 7am not 6am.

I know the portal is not up to the minute, but the Port on's and off's look like they ramp up over a 5 min period.
Which point should I trust?
Right now I'm going with the beginning of the ramp up as the on and the beginning of the ramp down as the off.

Image
Image


I don't actually have the pumps for this activity plugged in yet, they are still running on the old timers because I want to make sure everything is working correctly before I switch them over.
User avatar
cosmith71
Posts: 1437
Joined: Fri Mar 29, 2013 3:51 pm
Location: Oklahoma City

Re: Multiple on/off times

Post by cosmith71 »

I think the answer is that the on time is somewhere between the start of the ramp and the top. It sees that there is no activity during one refresh, and activity during the next, so it puts a ramp in between.

Here's what the code does.

Code: Select all

  ReefAngel.Relay.Set(Port5,now()%21600<1200); // Runs for 1200s every 21600 seconds
Port5 is the port we are switching. The second part is a boolean (true/false) value. 0 would mean off (false), 1 would mean on (true). now() is the number of seconds since 1/1/1970, so it's just a timer that is always increasing. % is the modulus operator. It returns the remainder from division, like 6/4 = 1 remainder 2. So, the second part of the statement says if the remainder of now() divided by 21600 is less than 1200 (the statement is true) then turn the pump on, otherwise turn the pump off.

So, every 6 hours (21600 seconds), we can divide the value of now() (which is universal and increases every second) and get a remainder that is less than 1200 (20 minutes). After 20 minutes, the remainder is larger than that and we know to turn the pump off.

It's a little simpler like this:

Code: Select all

if (now()%21600 < 1200) { ReefAngel.Relay.Set(Port5 , 1 ); }    // Pump on
else { ReefAngel.Relay.Set(Port5 , 0 ); }  // Pump off
So, we have two ways to code the same thing.

The second line works the same, although the +1200 confuses me as to why it works to offset. I can't wrap my head around it right now.

The "if" statement says if Port5 is on, then turn port6 off, else let the ATO control port6.

Hope this helps,

--Colin
billw
Posts: 38
Joined: Sat Aug 04, 2012 1:20 pm
Location: Lexington, KY

Re: Multiple on/off times

Post by billw »

The first line (port5) turns that port on every 6 hours at 12 am, 6 am, 12 noon and 6 pm. To shift it an hour ahead you would have to change the expression to (now()- 3600).

In the 2nd line controlling port8, the expression (+ 1200 ) should be (- 1200). Otherwise the logic is fine.

Sent from my Samsung Galaxy tablet - expect terse answers and typoes
User avatar
cosmith71
Posts: 1437
Joined: Fri Mar 29, 2013 3:51 pm
Location: Oklahoma City

Re: Multiple on/off times

Post by cosmith71 »

Hmmm, since you are adding 1200 and looking at the remainder only, wouldn't the value be the same?

Say now()=1, then now()+1200=1201

Then 1%1200 = 1
and 1201%1200 = 1

Am I missing something here?

--Colin
billw
Posts: 38
Joined: Sat Aug 04, 2012 1:20 pm
Location: Lexington, KY

Re: Multiple on/off times

Post by billw »

That's true but you are dividing by 21600 not 1200. If you added 21600 to the now() expression it would have no effect as you stated above. But when you add a smaller value (1200 in this case) to now() you shift the "on" window 1200 seconds earlier in time. When you subtract a value you shift the window later.

Picture now() returning 21599. Now() % 21600 would result in the port being off at this instance. If you desired that the port be on at this instance, you would have to add an offset of 1second which would slide that "on" window earlier by one second.

Sent from my Samsung Galaxy tablet - expect terse answers and typoes


edited
Last edited by billw on Mon May 27, 2013 7:28 am, edited 2 times in total.
User avatar
Sacohen
Posts: 1833
Joined: Sun Apr 21, 2013 6:25 am
Location: Davie, FL

Re: Multiple on/off times

Post by Sacohen »

I'm not sure, you got me confused a little bit, but the offset is to trigger a separate dosing pump to deliver the Nitragone liquid to the chamber for 20 min after the first pump does a water exchange for 20 min.
User avatar
cosmith71
Posts: 1437
Joined: Fri Mar 29, 2013 3:51 pm
Location: Oklahoma City

Re: Multiple on/off times

Post by cosmith71 »

billw wrote:That's true but you are dividing by 21600.
That's what I was missing! :oops:

Forgive me, it's early.

So something like this?

Code: Select all

  ReefAngel.Relay.Set(Port5,(now()-3600)%21600<1200); // Runs for 1200s every 21600 seconds
  ReefAngel.Relay.Set(Port8,((now()-3600)-1200)%21600<1200); // Runs for 1200s every 21600 seconds with 1200s offset
  if (ReefAngel.Relay.Status(Port5))
    ReefAngel.Relay.Off(Port6);
  else
    ReefAngel.WaterLevelATO(Port6,60,75,79);
billw
Posts: 38
Joined: Sat Aug 04, 2012 1:20 pm
Location: Lexington, KY

Re: Multiple on/off times

Post by billw »

That should do it. Port5 on at 1AM,7AM,1PM,and 7PM and port 8 20 minutes later.
User avatar
Sacohen
Posts: 1833
Joined: Sun Apr 21, 2013 6:25 am
Location: Davie, FL

Re: Multiple on/off times

Post by Sacohen »

billw wrote:The first line (port5) turns that port on every 6 hours at 12 am, 6 am, 12 noon and 6 pm. To shift it an hour ahead you would have to change the expression to (now()- 3600).

In the 2nd line controlling port8, the expression (+ 1200 ) should be (- 1200). Otherwise the logic is fine.

Sent from my Samsung Galaxy tablet - expect terse answers and typoes
I'm not sure where the 3600 goes. I tried the code below, but the compiler failed and I really didn't understand the error message yet.

This is the error message.
Steves_Custom_Wave_Sketch.cpp: In function 'void loop()':
Steves_Custom_Wave_Sketch:72: error: void value not ignored as it ought to be
Steves_Custom_Wave_Sketch:72: error: expected `;' before ')' token

Like this...

Code: Select all

  ReefAngel.Relay.Set(Port5,(now()- 3600)%21600<1200); // Runs for 1200s every 21600 seconds
  ReefAngel.Relay.Set(Port8,(now()- 3600)-1200)%21600<1200); // Runs for 1200s every 21600 seconds with 1200s offset
  if (ReefAngel.Relay.Status(Port5))
    ReefAngel.Relay.Off(Port6);
  else
    ReefAngel.WaterLevelATO(Port6,720,22,24);
I saw Colin's after I posted this.
What he had passed the compiling, so I'll upload it and see what it does before I actually move the plugs over to the RA.

Thanks for the help everyone.
It makes a little more sense.
Slow but surely I'll get a hang of this.
Last edited by Sacohen on Mon May 27, 2013 7:59 am, edited 1 time in total.
billw
Posts: 38
Joined: Sat Aug 04, 2012 1:20 pm
Location: Lexington, KY

Re: Multiple on/off times

Post by billw »

Sorry about that. You need an extra open paren in the port8 expression right before (now())

Set(Port8,((now()- 3600)
User avatar
cosmith71
Posts: 1437
Joined: Fri Mar 29, 2013 3:51 pm
Location: Oklahoma City

Re: Multiple on/off times

Post by cosmith71 »

Code: Select all

  ReefAngel.Relay.Set(Port8,(now()- 3600)-1200)%21600<1200); // Runs for 1200s every 21600 seconds with 1200s offset
Should be:

Code: Select all

  ReefAngel.Relay.Set(Port8,((now()- 3600)-1200)%21600<1200); // Runs for 1200s every 21600 seconds with 1200s offset
User avatar
Sacohen
Posts: 1833
Joined: Sun Apr 21, 2013 6:25 am
Location: Davie, FL

Re: Multiple on/off times

Post by Sacohen »

Well the 1pm cycle just went by and it looks like everything worked ok.
Port5 came on at 1pm and ran until 1:20pm and then Port8 came on at 1:20pm and ran until 1:40pm and all that time Potr6 (the ATO port) did not trigger and I know it was low enough to trigger when the De-nitrate water exchange started happening.

It looks like it's set up correctly now. I may watch 1 more cycle (at 7pm) to see if it is still good.

Thanks again everyone.
User avatar
Sacohen
Posts: 1833
Joined: Sun Apr 21, 2013 6:25 am
Location: Davie, FL

Re: Multiple on/off times

Post by Sacohen »

The only issue I have with set up so far is that when Port5 stops Port6 for the ATO automatically kicks in because the De-nitrification chamber has not quite returned all of the water back to the sump yet.

Is there a way we can add a 2 min delay after the water exchange happens on Port5 before Port6 will do anything?

Code: Select all

  ReefAngel.Relay.Set(Port5,(now()-3600)%21600<1200); // Runs for 1200s every 21600 seconds
  ReefAngel.Relay.Set(Port8,((now()-3600)-1200)%21600<1200); // Runs for 1200s every 21600 seconds with 1200s offset
  if (ReefAngel.Relay.Status(Port5))
    ReefAngel.Relay.Off(Port6);
  else
    ReefAngel.WaterLevelATO(Port6,720,29,31);
I'm guessing it would be something like..

Code: Select all

  if (ReefAngel.Relay.Status(Port5) + 120)
    ReefAngel.Relay.Off(Port6);
But I don't know the correct syntax of ; and ) yet.
User avatar
cosmith71
Posts: 1437
Joined: Fri Mar 29, 2013 3:51 pm
Location: Oklahoma City

Re: Multiple on/off times

Post by cosmith71 »

ReefAngel.Relay.Status returns a 0 for off and a 1 for on (boolean, true/false) so you can't just add 120 there.

Try this:

This goes near the top right above ////// Place global variable code above here

Code: Select all

unsigned long ATOUpdate=0;
Remove this:

Code: Select all

if (ReefAngel.Relay.Status(Port5))
    ReefAngel.Relay.Off(Port6);
  else
    ReefAngel.WaterLevelATO(Port6,720,29,31);
And try this instead:

Code: Select all

if (ReefAngel.Relay.Status(Port5) && ATOUpdate==0) // Check to see if port 5 is on and update time is empty
  { ATOUpdate = now();                             // If so, set the update time to now
    ReefAngel.Relay.Off (Port6); }                 // and turn off the ATO pump
if (now() - ATOUpdate >= 120 && ATOUpdate != 0)    // If it's been 120 sec, and the update time is NOT empty
  { ATOUpdate = 0;                                 // Empty out the update time
    ReefAngel.WaterLevelATO(Port6,720,29.31); }    // and turn the ATO sensor back on
--Colin
User avatar
Sacohen
Posts: 1833
Joined: Sun Apr 21, 2013 6:25 am
Location: Davie, FL

Re: Multiple on/off times

Post by Sacohen »

Thanks Colin, I'll try it when I get home tonight, but is the

Code: Select all

if (ReefAngel.Relay.Status(Port5) && ATOUpdate==0) // Check to see if port 5 is on and update time is empty
  { ATOUpdate = now();                             // If so, set the update time to now
going to interfere with the 2nd part of the De-nitrification process (the dosing of the Nitragone liquid for 20 min)

In this code...

Code: Select all

ReefAngel.Relay.Set(Port5,(now()-3600)%21600<1200); // Runs for 1200s every 21600 seconds
  ReefAngel.Relay.Set(Port8,((now()-3600)-1200)%21600<1200); // Runs for 1200s every 21600 seconds with 1200s offset
Post Reply