Hello, I am a student and I am trying to play an audio from an SD card using an Arduino MKR Zero that is connected to a speaker and button. This is only my second time using arduino and this error code keeps coming up: expected primary-expression before '.' token. It mainly happens on the line "while (AudioOut.isPlaying()) {". Any help would be appreciated. This is my code below:
#include <ArduinoSound.h>
#include <SD.h>
#include <SPI.h>
// Pin definitions
const int buttonPin = 2;
const int speakerPin = A0;
// Audio file
File audioFile;
// Button state
bool isPlaying = false;
void setup() {
Serial.begin(9600);
while (!Serial);
// Initialize button pin
pinMode(buttonPin, INPUT_PULLDOWN);
// Initialize SD card
if (!SD.begin(SDCARD_SS_PIN)) {
Serial.println("SD card initialized failed!");
while (1); // Stop execution if SD card fails
}
Serial.println("SD card initialized.");
// Open the audio file on th SD card
audioFile = SD.open("ele.wav");
if (!audioFile) {
Serial.println("Audio file not found!");
while (1); // Stop execution if audio file fails
}
// Initialise the audio library
if (!AudioOut.begin()) {
Serial.println("AudioOut failed to initialize.");
while (1); // Stop execution if AudioOut fails
}
Serial.println("Setup complete. Press the button to play audio.");
}
void loop() {
// Read button state
if (digitalRead(buttonPin) == HIGH && !isPlaying) {
Serial.println("Button pressed. Playing audio...");
isPlaying = true;
// Play the audio file
AudioOut.play(audioFile);
// Wait for playback to finish
while (AudioOut.isPlaying()) {
delay(10); // Prevents other actions during playback
}
Serial.println("Playback finished.");
audioFile.seek(0); // Reset file to the beginning
isPlaying = false
}
}