Expected primary-expression before '.' token

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
  }
}

missing ending semicolon

1 Like

For a compile error post verbose compile log in code tags. The message may be some distance away from the offending line and takes experience to find them.

Your sketch doesn't declare an instance of the AudioOut class. It can't use the class itself. It's like trying to say int = 2 + 2; instead of int x = 2 + 2;.

Is this sketch something you wrote yourself, and if not, where did it come from?

OP hasn't been back since I got a 'like' right away. I suspect that was the compile problem, and they're still busy sorting the rest out.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.