Skip to content

6. Example Fixed Ratio scripts

Kravitz Lab edited this page Dec 30, 2020 · 1 revision

Example FED3 scripts you can copy and try!

Fixed-Ratio 1: The left poke is logged and also results in a conditioned stimulus and a pellet, while the right poke is logged but has no other consequence.

#include <FED3.h>                                       //Include the FED3 library 
String sketch = "FR1";                                  //Unique identifier text for each sketch
FED3 fed3 (sketch);                                     //Start the FED3 object

void setup() {
  fed3.begin();                                         //Setup the FED3 hardware
}

void loop() {
  fed3.run();                                           //Call fed.run at least once per loop

  if (fed3.Left) {                                      //If left poke is triggered
    fed3.logLeftPoke();                                 //Log left poke
    fed3.ConditionedStimulus();                         //Deliver conditioned stimulus (tone and lights)
    fed3.Feed();                                        //Deliver pellet
  }

  if (fed3.Right) {                                     //If right poke is triggered
    fed3.logRightPoke();
  }
}

> Fixed-Ratio 1 with noise: The left poke is logged and also results in a conditioned stimulus and a pellet, while the right poke is logged and makes a noise stimulus but no pellet.

#include <FED3.h>                                       //Include the FED3 library 
String sketch = "FR1_withNoise";                                  //Unique identifier text for each sketch
FED3 fed3 (sketch);                                     //Start the FED3 object

void setup() {
  fed3.begin();                                         //Setup the FED3 hardware
}

void loop() {
  fed3.run();                                           //Call fed.run at least once per loop

  if (fed3.Left) {                                      //If left poke is triggered
    fed3.logLeftPoke();                                 //Log left poke
    fed3.ConditionedStimulus();                         //Deliver conditioned stimulus (tone and lights)
    fed3.Feed();                                        //Deliver pellet
  }

  if (fed3.Right) {                                     //If right poke is triggered
    fed3.logRightPoke();
    fed3.Noise();
  }
}

Fixed-Ratio 1, pokes reversed: The right poke is logged and also results in a conditioned stimulus and a pellet, while the left poke is logged but has no other consequence.

#include <FED3.h>                                       //Include the FED3 library 
String sketch = "FR1_reversed";                                  //Unique identifier text for each sketch
FED3 fed3 (sketch);                                     //Start the FED3 object

void setup() {
  fed3.begin();                                         //Setup the FED3 hardware
}

void loop() {
  fed3.run();                                           //Call fed.run at least once per loop

  if (fed3.Left) {                                      //If left poke is triggered
    fed3.logLeftPoke();                                 //Log left poke
  }

  if (fed3.Right) {                                     //If right poke is triggered
    fed3.logRightPoke();
    fed3.ConditionedStimulus();                         //Deliver conditioned stimulus (tone and lights)
    fed3.Feed();                                        //Deliver pellet
  }
}

Fixed-Ratio script where the ratio (variable 'FR') and which poke is active (variable 'LeftActive') are customizable. Set FR to any integer to set the Fixed Ratio, and set LeftActive to true to make the Left poke active, or false to make the Right poke active

////////////////////////////////////////////////////
// Customize the fixed ratio session
////////////////////////////////////////////////////
int FR = 5;
bool LeftActive = false;                               //Set to false to make right poke active

////////////////////////////////////////////////////
// Start FED3 library and make the fed3 object
////////////////////////////////////////////////////
#include <FED3.h>                                     //Include the FED3 library 
String sketch = "FRCustom";                           //Unique identifier text for each sketch
FED3 fed3 (sketch);                                   //Start the FED3 object

void setup() {
  fed3.begin();                                       //Setup the FED3 hardware
  fed3.FR = FR;                                       //Share the FR ratio with the fed3 library so it is logged on the SD card and displayed on the screen
  if (LeftActive == false) {
    fed3.activePoke = 0;                              //update the activepoke variable in the FED3 library for logging and display. This defaults to 1, so only set to 0 if LeftActive == false
  }
}
void loop() {
  fed3.run();                                         //Call fed.run at least once per loop

  // If Left poke is triggered
  if (fed3.Left) {
    fed3.logLeftPoke();                               //Log left poke
    if (LeftActive == true) {
      if (fed3.LeftCount % FR == 0) {                 //if fixed ratio is  met
        fed3.ConditionedStimulus();                   //deliver conditioned stimulus (tone and lights)
        fed3.Feed();                                  //deliver pellet
      }
      else {                                          //if fixed ratio is not met
        fed3.Click();                                 //click stimulus
      }
    }
  }

  // If Right poke is triggered
  if (fed3.Right) {
    fed3.logRightPoke();                              //Log Right poke
    if (LeftActive == false) {
      if (fed3.RightCount % FR == 0) {                 //if fixed ratio is  met
        fed3.ConditionedStimulus();                   //deliver conditioned stimulus (tone and lights)
        fed3.Feed();                                  //deliver pellet
      }
      else {                                          //if fixed ratio is not met
        fed3.Click();                                 //click stimulus
      }
    }
  }
}