I purchased an adafruit sound board, which allows you to trigger audio via the serial monitor.
I can successfully play files by using the Serial monitor. I can also successfully play sound files by (separately) wiring up a momentary button to the Sound Board. But what I want to do is programmatically trigger various sound files based on reading the input of a push button from arduino.
I am adapting their sample code, attempting to do the following:
void handleButton(){ //detect state of button push
buttonState = digitalRead(buttonPin);
if (buttonState != lastButtonState) {
if (buttonState == LOW) { // if the current state is LOW then the button went from on to off:
if (buttonPushCounter < numModes){
buttonPushCounter++;
} else {
buttonPushCounter = 0;
}
//Serial.println("#1"); //doesn't work
//ss.println("#1"); //doesn't work
}
// Delay a little bit for debouncing
//delay(buttonDelay);
}
// save the current state as the last state, for next time through the loop
lastButtonState = buttonState;
}
Where #1 would trigger the first sound file. But I have a feeling that because the code is listening for keyboard input within the serial monitor itself, that I'm either sending this info wrong or it's not possible to do this way. How would I programmatically trigger these files via Serial? Or is there some way to do it by sending signals to the board's GPIO without wiring up separate buttons for each file?
I noticed that the example's read looks like this:
while (!Serial.available());
char cmd = Serial.read();
flushInput();
switch (cmd) {
case '#': {
Serial.print("Enter track #");
uint8_t n = readnumber();
Serial.print("\nPlaying track #"); Serial.println(n);
if (! sfx.playTrack(n) ) {
Serial.println("Failed to play track?");
}
break;
}