Advertisement
microrobotics

SparkFun WVR Audio Dev Board

Jun 5th, 2023
1,415
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2. The SparkFun WVR is an audio development board with Wi-Fi capabilities. It supports several kinds of audio inputs and outputs.
  3.  
  4. Please ensure you have installed the SparkFun WVR library from the Arduino library manager before uploading this code.
  5.  
  6. This example will play the test.wav file when the button on pin 0 is pressed and stop the audio when the button on pin 1 is pressed. Please replace "/sd/test.wav" with the path to your actual audio file on the SD card. This example assumes the buttons are active high, meaning the signal is HIGH (3.3V) when the button is pressed and LOW (0V) when not pressed. If your buttons are wired differently, you may need to adjust the conditions in the if statements.
  7. */
  8.  
  9. #include <SparkFun_WVR.h>
  10.  
  11. WVR wvr;
  12.  
  13. // Define button pins
  14. #define BUTTON_PLAY_PIN 0
  15. #define BUTTON_STOP_PIN 1
  16.  
  17. void setup() {
  18.   // Start WVR
  19.   wvr.begin();
  20.  
  21.   // Wait for SD card to initialize
  22.   while (!wvr.sdBegin()) {
  23.     delay(1000);
  24.   }
  25.  
  26.   // Set up button pins as input
  27.   wvr.pinMode(BUTTON_PLAY_PIN, INPUT);
  28.   wvr.pinMode(BUTTON_STOP_PIN, INPUT);
  29. }
  30.  
  31. void loop() {
  32.   // Check the state of the buttons
  33.   if (wvr.digitalRead(BUTTON_PLAY_PIN) == HIGH) {
  34.     // If the play button is pressed and WVR is not currently playing
  35.     if (!wvr.isPlaying()) {
  36.       // Play file from SD card
  37.       wvr.playFile("/sd/test.wav");
  38.     }
  39.   }
  40.  
  41.   if (wvr.digitalRead(BUTTON_STOP_PIN) == HIGH) {
  42.     // If the stop button is pressed and WVR is currently playing
  43.     if (wvr.isPlaying()) {
  44.       // Stop playback
  45.       wvr.stopPlayback();
  46.     }
  47.   }
  48.  
  49.   // Small delay before loop repeats
  50.   delay(50);
  51. }
  52.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement