Time restrictions for an FR1 task

177 views
Skip to first unread message

Lex Kravitz

unread,
Dec 5, 2021, 9:59:07 AM12/5/21
to FEDforum
I received a question through email that I wanted to post here.  The user asked if it was possible to modify an FR1 session to also restrict the hours that the FED3 was active.

The answer is yes!  I'm attaching a script that does this.  It operates like the normal FR1 task but only during certain hours.  If you hold down both pokes at startup it will enter a small edit menu where you can set the number of the device and set the hours that the FED3 is active, stored in the variables timedStart and timedEnd. The attached script makes use of these variables to set the times that FED3 is active.  This same approach can be used for any task.  

To give some background on how time restrictions work:
There is a variable in the FED3 library called fed3.currentHour that can be queried  at any time to get the current hour.  So if you want FED3 to dispense on a Left poke only after 5PM, you can make that part of the contingency for whether a Left poke is registered.  ie:
if (fed3.Left and fed3.currentHour >= 17 ) {           
  fed3.Feed();
}

Hope this is helpful!  -Lex
FixedRatio1_time_restricted.ino

Nora Ahmed

unread,
Mar 2, 2022, 10:27:30 PM3/2/22
to FEDforum
Could it also be adapted if I wanted to set the minutes in which the FED 3 was active? For example, I would like to have the device active for only 20 minutes upon turning it on. 

FEDforum

unread,
Mar 2, 2022, 11:18:19 PM3/2/22
to FEDforum
Hi! There is not currently a variable in the FED3 library that returns the current minute in the same way as the current hour.  I can add this to the to-do list for a future release (which is getting long BTW!)

However in the meantime you can do this in the high-level Arduino script by starting a millis() timer when you start your program (ie: something like "Starttime = millis()"), and then only dispensing if less than 20 minutes has elapsed since the program started.  If you post your code I can show you what to add.  Hope this helps! -Lex

David Mallet

unread,
Jun 16, 2023, 5:03:57 AM6/16/23
to FEDforum
Hello,

I would like my FED3 to be active during the night, from 7pm to 7am the next day.

I'd like to use the if (fed3.currentHour >= 19 && fed3.currentHour < 7) fonction.

However, in the literal sense, there is no number greater than 7 and smaller than 19, so my device will never be activated.
Do I need to specify 2 activation slots? From 19 to 24 then from 0 to 7?

Thank you for your help,
David

Lex

unread,
Jun 16, 2023, 1:22:55 PM6/16/23
to David Mallet, FEDforum
Hi David, you should be able to do this with an OR statement, ie:
if ((fed3.currentHour >= 19) || (fed3.currentHour < 7))

Please post back if that works! 

--
You received this message because you are subscribed to the Google Groups "FEDforum" group.
To unsubscribe from this group and stop receiving emails from it, send an email to fedforum+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/fedforum/815ca80b-0f4f-45ef-a8e5-72050ed1a5ecn%40googlegroups.com.

David Mallet

unread,
Jun 19, 2023, 3:09:17 AM6/19/23
to FEDforum
Hi Lex,

Thank you for your help.
I tried it this weekend and it works perfectly!

Thanks
David

Vander LeKites

unread,
Aug 31, 2023, 2:25:48 PM8/31/23
to FEDforum
Hi all,

Do you know if it is possible to activate then inactivate the machine hourly on an FR1 pellet delivery? Hoping to incorporate lights to show when the device is on, and then sounds to play when the device is inactive and tries to nosepoke for a pellet.

I've tried playing with the lights but am unable to have them turn off when the nosepokes are no longer active, wondering if it has to do with the 'disableSleep' function. Please get back to me as soon as possible.

César Vargas

unread,
Aug 31, 2023, 3:35:41 PM8/31/23
to Vander LeKites, FEDforum
Hi Vander,

Do you mean like having one hour sessions or just on the hour? If it's the latter, I've written a perioding food restriction (you determine every x number of hours that food is delivered) that you might be able to modify and just add the stimulus function(s) when the desired time or interval occurs.

Vander LeKites

unread,
Aug 31, 2023, 4:06:19 PM8/31/23
to FEDforum
Hi Cesar,

Unfortunately it's the former, one hour active followed by one hour inactive and carry that process. I think that I can make that happen, but am struggling to do it with the lights being on only when the device is active. We are trying to install a go signal only using visual cues showing the mouse that the device is active and can poke to receive pellets.

Lex

unread,
Sep 1, 2023, 7:09:11 AM9/1/23
to Vander LeKites, FEDforum
Hi Vander,
For a strategy to accomplish this, in your void loop() you can call fed3.currentHour % 2 and assign the result (this will be either 0 for the even hours, or 1 for the odd hours) to a variable called FED3Active.  Then you can turn all of the pixels on if FED3Active == 1, and turn them off if FED3Active == 0.  And also only allow the ConditiondStimulus() and Feed() functions to go when FED3Active == 1.  

Here is a loop that may do what you want, I haven't tested it but hopefully it works or at least points you in the right direction!  Best, -Lex

int  FED3Active = 1;
 
void loop() {
  if (fed3.currentHour % 2 == 0) {
    FED3Active = 0;
    fed3.pixelsOff(); 
  }
  if (fed3.currentHour % 2 == 1)  {
    FED3Active = 1;
    fed3.pixelsOn(2, 2, 2, 2); 
  }

  fed3.run();                                           //Call fed.run at least once per loop
  if (fed3.Left) {                                      //If left poke is triggered
    fed3.logLeftPoke();                           //Log left poke
    if (FED3Active == 1) {                        // Test if FED3Active == 1
      fed3.ConditionedStimulus();           //Deliver conditioned stimulus (tone and lights for 200ms)
      fed3.Feed();                                       //Deliver pellet
    }
  }
  if (fed3.Right) {                                       //If right poke is triggered
    fed3.logRightPoke();                           //Log right poke
  }
}



Reply all
Reply to author
Forward
0 new messages