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