Code: Select all
#include <Adafruit_Soundboard.h>
#define PIN 4
#define LED 13 // Most Arduinos have an LED on pin 13
#define BUTTON 2 // put a simple button on pin 2 to enable/disable sound playback
void setup() {
pinMode(LED, OUTPUT); // Make the LED pin active
pinMode(BUTTON, INPUT_PULLUP);
setupSound(PIN);
}
void loop() {
}
void setupSound(int pin) {
pinMode(pin, OUTPUT);
digitalWrite(pin, HIGH); // Set the pin high as the default state
}
void activateSound(int pin) {
digitalWrite(LED, HIGH);
digitalWrite(pin, LOW); // bring the pin low to begin the activation
/*
According to the documentation, the Audio FX board needs 50ms to trigger. However,
I've found that coming from my 3.3v Arduino Pro, it needs 100ms to get the trigger
the going
*/
delay(100); // hold the pin low long enough to trigger the board; may need to be longer for consistent triggering
digitalWrite(pin, HIGH); // bring the pin high again to end the activation
digitalWrite(LED, LOW);
}