Triggered tone shut off ?

50 views
Skip to first unread message

Julia Pai

unread,
Feb 25, 2022, 4:45:12 PM2/25/22
to FEDforum
Hi all,

I'm getting set up with the FED3 and am excited to start piloting some tasks.

One of the things I'd like to implement is a trial start / 'go' tone, which will indicate a period of time when the mouse can poke one of the ports in order to receive a probabilistic reward. Ideally this would be a tone that plays for 10 seconds, or until the mouse pokes one of the ports, at which the tone would stop and some other tone or light stimulus could come on. 

I'm wondering if it's possible to program a tone that can stop playing once the mouse pokes a port. From what I understand the lights can be flexibly controlled this way -- with the pixelsOn / pixelsOff command -- but the tone functions are all set to play tones for a set duration of time. 

I could try implementing the task with trial start lights on instead of a tone, but suspect that a tone stimulus would be more salient and it would be nice to have dynamic control of how long tones play. Does anyone have any thoughts on how to implement this? 

Thanks,
Julia

Lex Kravitz

unread,
Feb 25, 2022, 10:41:00 PM2/25/22
to FEDforum
Hi Julia! Yup it's possible! 

You'll first have to disable sleep. Anytime you want FED3 to actively do things (like playing a tone or keeping the Neopixels on) for a long duration you have to do this.  With sleep enabled FED3 will last ~1 week on a battery charge, without sleep it still should last 2-3 days depending on usage so it's totally fine to disable it.  In your void setup() function include fed3.disableSleep(); to do this.

After this you can call the fed3.Tone(frequency, duration) function for as long as you want - ie: fed3.Tone(1000, 10000) would be a 1kHz tone for 10s.  And when you are ready to shut it off you can use the built in Arduino noTone() function, specifying that the beeper is on pin 0.  So noTone (0) will shut any tones off on FED3. 

Putting it all together, a program like this will set up the FED3 to run without sleeping, and play a 10s tone, which terminates for 5s when the mouse pokes left. 

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

void loop() {
  fed3.run();                                           //Call fed.run at least once per loop
  fed3.Tone(1000, 10000);                               //play a 1000Khz tone for 10s
   
  if (fed3.Left) {                                      //If left poke is triggered
    noTone(0);                                          //Stop the tone
    delay(5000);                                        //wait 5s
  }
}

The fed3.Tone function uses the built in Arduino tone() function which is non-blocking, meaning you can run other code while the tone is going (such as detecting a nose-poke!). Hopefully this answers your question!  Best, -Lex

Julia Pai

unread,
Feb 27, 2022, 9:09:24 PM2/27/22
to FEDforum
Hi Lex,

Yes, this is perfect. Thanks so much for the clear and helpful response!

Reply all
Reply to author
Forward
0 new messages