Skip to content

3. Functions

Kravitz Lab edited this page Aug 19, 2022 · 21 revisions

These functions can be called in your custom sketch

Trial control functions

  • logLeftPoke(): Causes FED3 to increment LeftCount and log the left poke and duration to the SD card
  • logRightPoke(): Causes FED3 to increment RightCount and log the right poke and duration to the SD card
  • randomizeActivePoke(max);: randomize which poke is active on the next trial. Argument specifies maximum consecutive trials on the same side before forcing a switch. Example:
fed3.randomizeActivePoke(3);    //randomize which poke is active.  If same poke is chosen 4 times in a row switch sides. 
  • ConditionedStimulus(duration): Turn all pixels on a green/blue color and a 4000Hz tone for specified duration (duration defaults to 200ms if not specified)
  • Timeout(int seconds): Causes FED3 to enter a "timeout" where nothing is active for the specified number of seconds

Audio functions

  • Click(): Short "click" (800Hz tone for 8ms)
  • Noise(duration): Random noise stimulus of a specified duration. (duration defaults to 200ms if not specified). Note: This function uses delay() and is blocking!
  • Tone(frequency, duration): Tone of set frequency (in Hz) and duration (in milliseconds). This function does not block your code from continuing to run.
  • stopTone(): Stop tone immediately, ie: if you start a 10s tone but want it to terminate early due to a nosepoke.

Neopixels functions

  • pixelsOff(): Turn all Neopixels off
  • pixelsOn(R, G, B, W): Turn all Neopixels on with RGBW set from 0-255 each. Remember to disable sleep if you want these to stay on. Example:
fed3.pixelsOn(10, 0, 0, 0);  //All pixels light up dimly in red 
  • leftPixel(R, G, B, W): Turn on left-most pixel. Note: you must have EnableSleep set to false to keep this pixel lit
  • rightPixel(R, G, B, W): Turn on right-most pixel. Note: you must have EnableSleep set to false to keep this pixel lit
  • leftPokePixel(R, G, B, W): Turn on neopixel inside the left poke (FED3.1 only). Note: you must have EnableSleep set to false to keep this pixel lit
  • rightPokePixel(R, G, B, W): Turn on neopixel inside the rightpoke (FED3.1 only). Note: you must have EnableSleep set to false to keep this pixel lit. Example:
fed3.rightPokePixel(0, 0, 10, 0);  //Pixel in right poke light up dimly in blue

Feeding functions

  • Feed(): Causes FED3 to drop a pellet. FED3 will continue attempting to drop pellet until it is detected in the pellet well, and will initiate jam clearing operations automatically if it fails to dispense on the following schedule: Every 5th attempt (MinorJam); Every 10th attempt (VibrateJam); Every 10th attempt (ClearJam). Once it detects a pellet it increments PelletCount and waits for up to 60 seconds for the pellet to be removed so it can calculate retInterval.

Arguments for Feed(): The Feed() function has an optional argument to send a pulse on the output port after the pellet is taken. This is useful for aligning with fiber photometry or other recordings. To send a pulse, give the fed3.Feed() function an optional argument for the duration of the pulse. Useage:
fed3.Feed(100); will send a 100ms pulse when the pellet is taken.
fed3.Feed(); still works, and will not send a pulse.

Normally, the Feed() function extinguishes the Neopixels when it detects a pellet. However, if you don't want them to turn off you can set a second optional second argument to false in the Feed() function. To do this, you need to set both optional arguments in the Feed() function. Useage:
fed3.Feed(100, false); will send a 100ms pulse and leave pixels on
fed3.Feed(0, false); will not send a pulse, but will leave the pixels on
fed3.Feed(); still works, and will do neither

You will also have to call fed3.disableSleep() in your setup loop if you plan to leave the Neopixels on for long durations, as power to them gets cut when sleep modes are active.

  • MinorJam(): Causes FED3 pellet disk to make a small backwards movement
  • VibrateJam(): Causes FED3 pellet disk to make a vibrating movement for ~10 seconds, stopping this movement if a pellet is detected
  • ClearJam(): Causes FED3 pellet disk to make a full rotation backwards and forwards, stopping this movement if a pellet is detected

BNC port functions

  • BNC(delay, number): Send number of pulses of length delay from the BNC output port. Note: This function uses delay() and is blocking! Example:
fed3.BNC(20, 5); //send five 20ms pulses from the BNC port
  • ReadBNC(): Set the BNC port to be an input and read it. If it goes HIGH it will set the variable BNCinput to true. Example:
fed3.ReadBNC(); 
  • pulseGenerator(int pulse_width, int frequency, int repetitions): More advanced pulse generator that can control the pulse width (in ms), frequency (in Hz), and # of repetitions for a pulse train. Note: This function uses delay() and is blocking! Example:
fed3.pulseGenerator(10, 20, 20); //send a 20Hz train of 10ms pulses lasting 1 second (20 pulses)

Display functions

  • UpdateDisplay(): Update all values on FED3 display

SDcard logging functions

  • logdata(): Log current data to the SD card. This will print one line to the data file containing the following fields:
MM:DD:YYYY hh:mm:ss, LibaryVersion_Sketch, Device_Number, Battery_Voltage, Motor_Turns, Trial_Info, FR, Event,
Active_Poke, Left_Poke_Count, Right_Poke_Count, Pellet_Count, Block_Pellet_Count, Retrieval_Time, Poke_Time

Sleep functions

  • disableSleep(): Disable sleep functionality. Call in setup loop after fed3.begin. This is useful for using NeoPixels. Example:
fed3.begin();
fed3.disableSleep();