Timers

Do you have a question on how to do something.
Ask in here.
Post Reply
User avatar
jsclownfish
Posts: 375
Joined: Mon Oct 24, 2011 7:52 pm
Location: Saint Louis

Timers

Post by jsclownfish »

In the new code for wavemakers how do would I display the timers. I was using this before...

Code: Select all

    int t=ReefAngel.Timer[1].Trigger-now();
    if (t>=0)
      ReefAngel.LCD.Clear(255,105,33,135,43);
      ReefAngel.LCD.DrawText(0, DefaultBGColor,105,33,t);
It looks like I would use ReefAngel.WMRTimer.Trigger-now(), but that isn't recognized. I am still using the same code above for the side to side powerheads, but I am adding a few more smaller ones on the back wall to increase flow in other directions. I am using random times and the new function to direct them, but it would be nice to display the times as well on those powerheads.

Thanks,
Jon
binder
Posts: 2865
Joined: Fri Mar 18, 2011 6:20 pm
Location: Illinois
Contact:

Re: Timers

Post by binder »

if you are using the standard Wavemaker function, here is the code for determination of the timer:
Actually, this is just the condition that determines when to toggle the port inside the Wavemaker function

Code: Select all

(now()%(WMTimer*2))<WMTimer
In order to determine how many seconds are left, you would need to do something like this:

Code: Select all

// WMTimer is the value for the wavemaker
// put in whatever value you use for your wavemakers
int t = WMTimer - (now()%(WMTimer*2));

// if you are using wavemaker one, it can be this:
int t = InternalMemory.WM1Timer_read() - (now()%(InternalMemory.WM1Timer_read()*2));
What you want to do is compute the same time that the function computes and then subtract that value from the value of the timer. We may be able to simplify things a little and create a function for you to call.
Then you can use your existing code to display it on the screen.

If you are using the WavemakerRandom functions, then you will not be able to display the remaining time.
User avatar
jsclownfish
Posts: 375
Joined: Mon Oct 24, 2011 7:52 pm
Location: Saint Louis

Re: Timers

Post by jsclownfish »

Hmm. I have large "wavemaker" powerheads on the sides of the tank and I wanted to add a couple more smaller ones to help in dead spots around the rock. I tried this to control them...

Code: Select all

// Wavemaker Code with night option
  if (ReefAngel.Timer[1].IsTriggered() )
  {
    if ((hour() >= 21) || (hour() <= 8)) //from 9p-Midnight 
    {  //PWMSlope(byte startHour, byte startMinute, byte endHour, byte endMinute, byte startPWM, 
       // byte endPWM, byte Duration, byte oldValue)
      wmpulse=PWMSlope(21,0,8,0,5,30,179,30);
      if (wmdelay)
      {
        ReefAngel.Timer[1].SetInterval(wmpulse);  // WM delay function from 30-170 sec.
        ReefAngel.Timer[1].Start();
        ReefAngel.Relay.Off(Port5);
        ReefAngel.Relay.Off(Port6);
        if (wmport==Port5) wmport=Port6; else wmport=Port5;
        wmdelay=false;
      }
      else
      {
        ReefAngel.Timer[1].SetInterval(200-wmpulse);  // WM bursts timing from 170-30 sec.
        ReefAngel.Timer[1].Start();
        ReefAngel.Relay.On(wmport);
        wmdelay=true;
      }
    }
    else
    {
      //8a-10p normal wave settings
      ReefAngel.Timer[1].SetInterval(InternalMemory.WM1Timer_read());
      ReefAngel.Timer[1].Start();
      ReefAngel.Relay.Toggle(Port5);
      ReefAngel.Relay.Toggle(Port6);
    }
  }
//extra small powerheads to increase circulation
 if (ReefAngel.Timer[5].IsTriggered())
  { 
  ReefAngel.Timer[5].SetInterval(random(15,90)); 
  ReefAngel.Timer[5].Start();
  ReefAngel.Relay.Toggle(Box1_Port5);
  ReefAngel.Relay.Toggle(Box1_Port6);
  }
and the pumps seem to work OK, and I could display the two different timers, but the random one is not accurate. I guess that is because it runs the random timing function after the trigger is set. Maybe I could assign the random # to a variable and have it cound down from that # somehow?
binder
Posts: 2865
Joined: Fri Mar 18, 2011 6:20 pm
Location: Illinois
Contact:

Re: Timers

Post by binder »

Correct. The random one will not show properly. You are also correct with storing the value. Instead of doing this:

Code: Select all

ReefAngel.Timer[5].SetInterval(random(15,90));
You could do this:

Code: Select all

wt = random(15,90);
ReefAngel.Timer[5].SetInterval(wt);
Then you would have to add this:

Code: Select all

int wt;
outside of the loop() (up by the other global variables) and you could use wt as the value to count down from.
User avatar
jsclownfish
Posts: 375
Joined: Mon Oct 24, 2011 7:52 pm
Location: Saint Louis

Re: Timers

Post by jsclownfish »

I tried this...

Code: Select all

//extra small powerheads to increase circulation
 if (ReefAngel.Timer[5].IsTriggered())
  { 
  wmaker2=random(15,90);
  ReefAngel.Timer[5].SetInterval(wmaker2); 
  ReefAngel.Relay.Toggle(Box1_Port5);
  ReefAngel.Relay.Toggle(Box1_Port6);
  }
  
but the interval was much larger than 90 seconds (>1000). Does the random function like this change the units from seconds to minutes or something?

Thanks,
Jon
rimai
Posts: 12857
Joined: Fri Mar 18, 2011 6:47 pm

Re: Timers

Post by rimai »

You missed the start of the timer again.

Code: Select all

//extra small powerheads to increase circulation
if (ReefAngel.Timer[5].IsTriggered())
  { 
  wmaker2=random(15,90);
  ReefAngel.Timer[5].SetInterval(wmaker2); 
  ReefAngel.Timer[5].Start(); 
  ReefAngel.Relay.Toggle(Box1_Port5);
  ReefAngel.Relay.Toggle(Box1_Port6);
  }
Roberto.
rimai
Posts: 12857
Joined: Fri Mar 18, 2011 6:47 pm

Re: Timers

Post by rimai »

Oh, one other note....
Timer[5] is used by the controller to control the writing to memory of parameters that draw the graphs on the screen.
Timers 1 and 2 are free to use if you are not using them for dosing pumps.
Roberto.
User avatar
jsclownfish
Posts: 375
Joined: Mon Oct 24, 2011 7:52 pm
Location: Saint Louis

Re: Timers

Post by jsclownfish »

OK, thanks. I'll try it tonight. BTW, does the RA+ have more timer options? I am currently only want to use two for the four wavemakers, but at some point I also want to install the dosing pump. I seem to remember more were available on the 2560.

Also, are the parameters for the graphs always written to memory and written over as needed? I was thinking about graphing one of the flow meters over time or graphing making the graph on the remote monitor, but I wasn't sure how it was done.

Thanks,
-Jon
rimai
Posts: 12857
Joined: Fri Mar 18, 2011 6:47 pm

Re: Timers

Post by rimai »

Oh, you can define your own timers. :)
Put this about setup():

Code: Select all

TimerClass MyTimer;
Then you can use it just like you've done with the other timers:

Code: Select all

  MyTimer.SetInterval(100);
  MyTimer.Start();
The parameters are always stored in the memory no matter what.
Roberto.
User avatar
jsclownfish
Posts: 375
Joined: Mon Oct 24, 2011 7:52 pm
Location: Saint Louis

Re: Timers

Post by jsclownfish »

I'm a little confused about Timers and libraries v0.9.x. If I want Dosing pumps, 2 wavemaker timers, and ATO, which should I be using. Now that the dosing pumps aren't using timers, which ones are available? Or should I just define my own as you suggested above?

Thanks,
Jon
rimai
Posts: 12857
Joined: Fri Mar 18, 2011 6:47 pm

Re: Timers

Post by rimai »

Wavemaker are not using timers anymore.
ATO never used a timer.
There are 2 types of Dosing pump functions: DosingPumpRepeat doesn't use timers anymore and DosingPump, which is the only remaining one that uses timers.
But feel free to create your own timers. This way, you know for sure they are being exclusevily being used by your function.
Roberto.
binder
Posts: 2865
Joined: Fri Mar 18, 2011 6:20 pm
Location: Illinois
Contact:

Re: Timers

Post by binder »

If you use the Timers, you can do a "countdown" or keep track of the remaining time easier. There's a little more work involved to get the time remaining if you don't use the timers. The upside though is decreased code size from not using the Timers.
Post Reply