Two different feeding timers

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

Two different feeding timers

Post by jsclownfish »

I've been reading that it is a better strategy to feed your fish less amount more frequently throughout the day. I was thinking of having my autofeeder drop a little flake food each hour during the day. :) I wouldn't need the same timer for the autofeeder, maybe just 30 seconds or so. However, it would be good to have the regular long timer for when I like to feed them myself. I could just change the memory setting when I want to feed them, but I thought it might be more elegant to have a seperate timer for the autofeeder feedings vs. the manual feeding using the menu. Since the timing is embedded in the ReefAngel.FeedingModeStart() function I don't know if it can be set seperately. :geek:

Thanks,
Jon
User avatar
lnevo
Posts: 5430
Joined: Fri Jul 20, 2012 9:42 am

Two different feeding timers

Post by lnevo »

Why not copy what you need from the feeding mode start function into a FeedingModeStartCustom() function and set your timer for that function manually and call that with your autofeeder...
rimai
Posts: 12881
Joined: Fri Mar 18, 2011 6:47 pm

Re: Two different feeding timers

Post by rimai »

What lnevo said :)
Roberto.
binder
Posts: 2871
Joined: Fri Mar 18, 2011 6:20 pm
Location: Illinois
Contact:

Re: Two different feeding timers

Post by binder »

If you do what lnevo said, make sure you look at the ShowInterface function inside ReefAngel.cpp and then look under the case FEEDING_MODE section to see how to return to normal mode operations.
User avatar
lnevo
Posts: 5430
Joined: Fri Jul 20, 2012 9:42 am

Two different feeding timers

Post by lnevo »

How about another idea....in your loop when you want to trigger your auto feeder...change the feeding timer to the shorter amount, start feeding mode, then revert it back...this way you don't reinvent the wheel.. :)
Try adding this to your setup:

Code: Select all

ReefAngel.Timer[FEEDING_TIMER].SetInterval(900);
User avatar
jsclownfish
Posts: 378
Joined: Mon Oct 24, 2011 7:52 pm
Location: Saint Louis

Re: Two different feeding timers

Post by jsclownfish »

Ahh, I like that better. Seems much simpler. I can still store the second time parameter in memory. Something like this....

Code: Select all

//Fast feeder timer
#define FastFeed 105
byte Feed = 0;
....
void setup()
....
void loop()
....
if ((hour() >= 10) || (hour() <= 19)) //from 10a-7p 
{
   if (minute() ==30 && second() == 0) //once an hour on the half hour
   {
    Feed = 1;   // Turn on feeder and feedmode
    ReefAngel.Timer[FEEDING_TIMER].SetInterval(InternalMemory.read(FastFeed));			
    ReefAngel.FeedingModeStart();
    ReefAngel.Timer[FEEDING_TIMER].SetInterval(InternalMemory.FeedingTimer_read());
   }   
}
else
    {
     Feed = 0;
    }
....
Thanks, I'll give it a try!
Jon
User avatar
lnevo
Posts: 5430
Joined: Fri Jul 20, 2012 9:42 am

Re: Two different feeding timers

Post by lnevo »

Just one thing that I realized after I suggested that... need rimai or binder to chime in. I do not know what happens if you change the interval of the timer while it's running.. ? You may need to wait till the timer is over to reset the time... so maybe you start a second timer and when that's over you can reset the timer back to default... but maybe it's not needed..
rimai
Posts: 12881
Joined: Fri Mar 18, 2011 6:47 pm

Re: Two different feeding timers

Post by rimai »

To restart the timer, use this:

Code: Select all

ReefAngel.Timer[FEEDING_TIMER].Start();
Roberto.
User avatar
lnevo
Posts: 5430
Joined: Fri Jul 20, 2012 9:42 am

Re: Two different feeding timers

Post by lnevo »

Roberto,

Issue is not regarding restarting... but if he sets the timer to 90 seconds... starts the timer and then changes the interval to 900, what's the affect on the running timer? none? then he's good to go... otherwise have to wait for timer to finish and reset the interval... I wasn't sure what would happen if you change the interval on a running timer...
rimai
Posts: 12881
Joined: Fri Mar 18, 2011 6:47 pm

Re: Two different feeding timers

Post by rimai »

I'm not 100% sure, but I think it would not affect the current timer until it resets again or you use the function I posted.
Roberto.
User avatar
lnevo
Posts: 5430
Joined: Fri Jul 20, 2012 9:42 am

Re: Two different feeding timers

Post by lnevo »

Ok, so Jon, let's see how your test goes :)
binder
Posts: 2871
Joined: Fri Mar 18, 2011 6:20 pm
Location: Illinois
Contact:

Re: Two different feeding timers

Post by binder »

rimai wrote:I'm not 100% sure, but I think it would not affect the current timer until it resets again or you use the function I posted.
You are correct. It should not affect the current timer at all. The reason I say this is because of how Start() works. When you call Start(), it computes the end value (aka, Trigger value). Every time you call the function IsTriggered() to determine if the timer is expired/triggered, it just checks the current time against the end time. It never looks at the interval until Start() is called.

So you should be fine changing the timer. In fact, the code Jon posted with changing the interval, starting the timer, then setting it back should work just fine provided he doesn't call FeedingModeStart while it's still running the feeding mode. :)
User avatar
jsclownfish
Posts: 378
Joined: Mon Oct 24, 2011 7:52 pm
Location: Saint Louis

Re: Two different feeding timers

Post by jsclownfish »

Thanks for all the help. It seems to be working fine. It's funny how the fish seem to know food is coming when the wavemakers stop and the water calms down.

BTW, I tried to put an option in a custom menu to trigger a feed as well, but as long as the feed functions are on in the loop, it won't work. Does the loop 'override' the menu options somehow? This isn't a big deal for me, I just was surprised it didn't work.

The code looks like this....

Code: Select all

#define FastFeed 105  //Fast feeder timer
...
byte Feed = 0;
...
// Custom Menu Code
prog_char menu1_label[] PROGMEM = "Feeding";
prog_char menu2_label[] PROGMEM = "Water Change";
prog_char menu3_label[] PROGMEM = "pH Calibration";
prog_char menu4_label[] PROGMEM = "pH Detail";
prog_char menu5_label[] PROGMEM = "Temp Detail";
prog_char menu6_label[] PROGMEM = "AutoFeed";
prog_char menu7_label[] PROGMEM = "Flow Cells";
prog_char menu8_label[] PROGMEM = "Version";
prog_char menu9_label[] PROGMEM = "Sound Bytes";
PROGMEM const char *menu_items[] = {
menu1_label, menu2_label, menu3_label,
menu4_label, menu5_label, menu6_label,
menu7_label, menu8_label, menu9_label
};
...
void MenuEntry6() //Autofeeder manual trigger
{
Feed = 1;
ReefAngel.FeedingModeStart();
}
void setup()
{
...
}
void loop()
{
...
//Autofeeder Mode
  if ( InternalMemory.read(VacationEnable) <= 2 ) // check for vacation mode
	{
         // Check if the current time is equal to the start time.
            if (NumMins(hour(), minute()) == (NumMins(InternalMemory.read(VacationStartHr), InternalMemory.read(VacationStartMin))))
            {
              if (second() == 0) 
              		{
			Feed = 1;   // Turn on feeder and feedmode
			ReefAngel.FeedingModeStart();
		        }   
            }
            else Feed = 0;
         }
  if ( InternalMemory.read(VacationEnable) == 2 ) // check for vacation mode
	{
         // Check if the current time is equal to the start time.
            if (NumMins(hour(), minute()) == (NumMins(InternalMemory.read(VacationStart2ndHr), InternalMemory.read(VacationStart2ndMin))))
            {
              if (second() == 0) 
              		{
			Feed = 1;   // Turn on feeder and feedmode
			ReefAngel.FeedingModeStart();
		        }   
            }
            else Feed = 0;
         }
  if ( InternalMemory.read(VacationEnable) == 3 ) // check for vacation mode
	{
           if ((hour() >= 10) || (hour() <= 19)) //from 10a-7p 
             {
              if (minute() ==30 && second() == 0) //once an hour on the half hour
              		{
			Feed = 1;   // Turn on feeder and feedmode
                        ReefAngel.Timer[FEEDING_TIMER].SetInterval(InternalMemory.read(FastFeed));			
                        ReefAngel.FeedingModeStart();
                        ReefAngel.Timer[FEEDING_TIMER].SetInterval(InternalMemory.FeedingTimer_read());
		        }   
             else Feed = 0;
             }
         }
...
-Jon
binder
Posts: 2871
Joined: Fri Mar 18, 2011 6:20 pm
Location: Illinois
Contact:

Re: Two different feeding timers

Post by binder »

The loop is always executed no matter what mode you are in unless you bypass it completely (not recommended). So when you trigger the feeding mode, it's going to process the loop just like normal. All of your checks to enable the autofeed mode will still be in effect. I see you setting a variable Feed but never referencing it...unless it is referenced elsewhere in the code. What you would need to do would be to override the autofeed checks in the loop when you force it from the menu....like we were doing for somebody else with the RF modes. It could be done but would require some changes to be made.
User avatar
jsclownfish
Posts: 378
Joined: Mon Oct 24, 2011 7:52 pm
Location: Saint Louis

Re: Two different feeding timers

Post by jsclownfish »

Hmm, the feed variable is my way of opening (Feed=0) and closing (Feed=1) a relay on the autofeeder. The autofeeder is actually a push button so I need to reset it each time so the next cycle to feed is open. Interestingly, it resets to Feed=0 after the Autofeed runs it's time. If I want to trigger an feed response from the menu or maybe from a memory location (remotely) then I must need to add another variable for that state I guess?

Something like this???....

Code: Select all

#define FastFeed 105  //Fast feeder timer
...
byte Feed = 0;
byte AutoFeed = 0;
...
// Custom Menu Code
prog_char menu1_label[] PROGMEM = "Feeding";
prog_char menu2_label[] PROGMEM = "Water Change";
prog_char menu3_label[] PROGMEM = "pH Calibration";
prog_char menu4_label[] PROGMEM = "pH Detail";
prog_char menu5_label[] PROGMEM = "Temp Detail";
prog_char menu6_label[] PROGMEM = "AutoFeed";
prog_char menu7_label[] PROGMEM = "Flow Cells";
prog_char menu8_label[] PROGMEM = "Version";
prog_char menu9_label[] PROGMEM = "Sound Bytes";
PROGMEM const char *menu_items[] = {
menu1_label, menu2_label, menu3_label,
menu4_label, menu5_label, menu6_label,
menu7_label, menu8_label, menu9_label
};
...
void MenuEntry6() //Autofeeder manual trigger
{
AutoFeed = 1;
Feed = 1;
ReefAngel.FeedingModeStart();
AutoFeed = 0;
}
void setup()
{
...
}
void loop()
{
...
//Autofeeder Mode
  if ( InternalMemory.read(VacationEnable) <= 2 && Autofeed == 0) // check for vacation mode
   {
         // Check if the current time is equal to the start time.
            if (NumMins(hour(), minute()) == (NumMins(InternalMemory.read(VacationStartHr), InternalMemory.read(VacationStartMin))))
            {
              if (second() == 0) 
                    {
         Feed = 1;   // Turn on feeder and feedmode
         ReefAngel.FeedingModeStart();
              }   
            }
            else Feed = 0;
         }
  if ( InternalMemory.read(VacationEnable) == 2 && Autofeed == 0) // check for vacation mode
   {
         // Check if the current time is equal to the start time.
            if (NumMins(hour(), minute()) == (NumMins(InternalMemory.read(VacationStart2ndHr), InternalMemory.read(VacationStart2ndMin))))
            {
              if (second() == 0) 
                    {
         Feed = 1;   // Turn on feeder and feedmode
         ReefAngel.FeedingModeStart();
              }   
            }
            else Feed = 0;
         }
  if ( InternalMemory.read(VacationEnable) == 3 && Autofeed == 0) // check for vacation mode
   {
           if ((hour() >= 10) || (hour() <= 19)) //from 10a-7p 
             {
              if (minute() ==30 && second() == 0) //once an hour on the half hour
                    {
         Feed = 1;   // Turn on feeder and feedmode
                        ReefAngel.Timer[FEEDING_TIMER].SetInterval(InternalMemory.read(FastFeed));         
                        ReefAngel.FeedingModeStart();
                        ReefAngel.Timer[FEEDING_TIMER].SetInterval(InternalMemory.FeedingTimer_read());
              }   
             else Feed = 0;
             }
         }
...
Post Reply