Audio Puzzle Errors (Need Help)

// DEFINES
// Flag to toggle debugging output
#define DEBUG

// INCLUDES
// For interfacing with analogue multiplexer
// https://github.com/stechio/arduino-ad-mux-lib
#include "/Users/jaylonlim/Documents/Arduino/Audio Puzzle/libraries/arduino-ad-mux-lib-master-2/src/Mux.h"
// DEPlayerMini module requires a serial connection. Since we're already using the hardware serial
// connection for the USB interface, we'll create an additional software-emulated serial connection
// using the SoftwareSerial library
#include <SoftwareSerial.h>
// This library exposes functions for playing sounds from DFPlayerMini module using the serial connection
//Download from https://github.com/DFRobot/DFRobotDFPlayerMini
#include "/Users/jaylonlim/Documents/Arduino/Audio Puzzle/libraries/DFRobotDFPlayerMini-master/DFRobotDFPlayerMini.h"

// CONSTANTS
//Define the number of steps in the sequence that the player must follow
const int numInputs = 10;
// The correct sequence of inputs required to solve the puzzle
const int correctSequence[numInputs] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
//This pin will be driven LOW to release a lock when puzzle is solved
const byte lockPin = 12;


// GLOBALS
//We need to read 10 digital inputs, which we'll do using 4 control pins 3-6
Mux mux (2, INPUT, Digital, 6, 5, 4, 3);
//Mux mux(Pin(2, INPUT, PinType::Digital), Pinset(6, 5, 4, 3));
// 16-channel Mux declared with analog input signal on pin A0 and channel control on digital pins 8, 9, 10 and 11.
//Mux mux(Pin(A0, INPUT, PinType::Analog), Pinset(6, 5, 4, 3));
// Initialise a soft serial interface
SoftwareSerial softwareSerial(A0, A1);  //Rx,Tx
// Create an object to access the dfPlayer
DFRobotDFPlayerMini dfPlayer;
// Array to keep track of the last state of every button input
bool lastInput[  // DEFINES
// Flag to toggle debugging output
#define DEBUG

  //Initialisation
  void Setup() {
#ifdef DEBUG
    //Initialise serial communications channel with the PC
    Serial.begin(9600);
    delay(500);
    //Initialise the software serial interface used to control the DFPlayer
    Serial.print(F("Initialising software serial interface to DFPlayer..."));
#endif
    for (int i = 0; i < 10; i++) {
      softwareSerial.begin(9600);
      delay(500);
      if (dfPlayer.begin(softwareSerial)) {
#ifdef DEBUG
        Serial.println(F("OR! "));
#endif
        break;
      } else {
        Serial.print(".");
      }
      if (i == 9) {
#ifdef DEBUG
        Serial.println(F("Failed : ("));
#endif
        return;
      }
    }
    // Set DFPlayer volume (value from 0 to 30)
    dfPlayer.volume(24);
    // set the lock pin as output and secure the lock
    pinMode(lockPin, OUTPUT);
    digitalWrite(lockPin, HIGH);
#ifdef DEBUG
    Serial.println(F("Lock secured"));
#endif

// Debug
#ifdef DEBUG
    Serial.println("Setup Complete");
#endif
  }


  //Main program loop runs indefinitely
  void Loop() {
    for (byte i = 0; i < numInputs; i++) {
      //Reads from channel i
      int currentReading = mux.read(i);
      if (lastInput[i] == LOW && currentReading == HIGH) {
        // Play the sound file called "0001 XXXX.way"/ "0001 XXXX.mp3" saved in the "mp3" folder of the SD card
        dfPlayer.playMp3Folder(i + 1);
        //Is this the correct input?
        if (correctSequence[currentstep] == i) {
          currentstep++;
#ifdef DEBUG
          Serial.print(F("Correct input! Onto step #"));
          Serial.println(currentstep);
#endif
          // Check whether the puzzle has been solved
          if (currentstep == numInputs) {
            onSolve();
          }
        }
        // Incorrect input!
        else {
          currentstep = 0;
          Serial.print(F("Incorrect input! Expected"));
          Serial.print(correctSequence[currentstep]);
          Serial.print(F(" but got"));
          Serial.println(i);
        }
      }
      // Update the stored value for this input
      lastInput[i] = currentReading;
    }
  }


  // Takes action when the puzzle becomes solved
  void onSolve() {
#ifdef DEBUG
    // Print a message
    Serial.println(F("Puzzle Solved!"));
#endif
    // Release the lock
    digitalWrite(lockPin, LOW);
    delay(500);
    digitalWrite(lockPin, HIGH);
    // Reset the step counter
    currentstep = 0;
  }

];
//What step of the sequence is the player currently on?
int currentstep = 0;


//Initialisation
void Setup() {
#ifdef DEBUG
  //Initialise serial communications channel with the PC
  Serial.begin(9600);
  delay(500);
  //Initialise the software serial interface used to control the DFPlayer
  Serial.print(F("Initialising software serial interface to DFPlayer..."));
#endif
  for (int i = 0; i < 10; i++) {
    softwareSerial.begin(9600);
    delay(500);
    if (dfPlayer.begin(softwareSerial)) {
#ifdef DEBUG
      Serial.println(F("OR! "));
#endif
      break;
    } else {
      Serial.print(".");
    }
    if (i == 9) {
#ifdef DEBUG
      Serial.println(F("Failed : ("));
#endif
      return;
    }
  }
  // Set DFPlayer volume (value from 0 to 30)
  dfPlayer.volume(24);
  // set the lock pin as output and secure the lock
  pinMode(lockPin, OUTPUT);
  digitalWrite(lockPin, HIGH);
#ifdef DEBUG
  Serial.println(F("Lock secured"));
#endif

// Debug
#ifdef DEBUG
  Serial.println("Setup Complete");
#endif
}


//Main program loop runs indefinitely
void Loop() {
  for (byte i = 0; i < numInputs; i++) {
    //Reads from channel i
    int currentReading = mux.read(i);
    if (lastInput[i] == LOW && currentReading == HIGH) {
      // Play the sound file called "0001 XXXX.way"/ "0001 XXXX.mp3" saved in the "mp3" folder of the SD card
      dfPlayer.playMp3Folder(i + 1);
      //Is this the correct input?
      if (correctSequence[currentstep] == i) {
        currentstep++;
#ifdef DEBUG
        Serial.print(F("Correct input! Onto step #"));
        Serial.println(currentstep);
#endif
        // Check whether the puzzle has been solved
        if (currentstep == numInputs) {
          onSolve();
        }
      }
      // Incorrect input!
      else {
        currentstep = 0;
        Serial.print(F("Incorrect input! Expected"));
        Serial.print(correctSequence[currentstep]);
        Serial.print(F(" but got"));
        Serial.println(i);
      }
    }
    // Update the stored value for this input
    lastInput[i] = currentReading;
  }
}


// Takes action when the puzzle becomes solved
void onSolve() {
#ifdef DEBUG
  // Print a message
  Serial.println(F("Puzzle Solved!"));
#endif
  // Release the lock
  digitalWrite(lockPin, LOW);
  delay(500);
  digitalWrite(lockPin, HIGH);
  // Reset the step counter
  currentstep = 0;
}

ERRORS
/Users/jaylonlim/Documents/Arduino/Audio Puzzle/Audio Puzzle.ino:28:1: error: 'Mux' does not name a type
Mux mux (2, INPUT, Digital, 6, 5, 4, 3);
^~~
/Users/jaylonlim/Documents/Arduino/Audio Puzzle/Audio Puzzle.ino:42:3: error: expected primary-expression before 'void'
void Setup() {
^~~~
/Users/jaylonlim/Documents/Arduino/Audio Puzzle/Audio Puzzle.ino:42:3: error: expected ']' before 'void'
/Users/jaylonlim/Documents/Arduino/Audio Puzzle/Audio Puzzle.ino: In function 'void Loop()':
/Users/jaylonlim/Documents/Arduino/Audio Puzzle/Audio Puzzle.ino:88:28: error: 'mux' was not declared in this scope
int currentReading = mux.read(i);
^~~
/Users/jaylonlim/Documents/Arduino/Audio Puzzle/Audio Puzzle.ino:88:28: note: suggested alternative: 'max'
int currentReading = mux.read(i);
^~~
max
/Users/jaylonlim/Documents/Arduino/Audio Puzzle/Audio Puzzle.ino:89:11: error: 'lastInput' was not declared in this scope
if (lastInput[i] == LOW && currentReading == HIGH) {
^~~~~~~~~
/Users/jaylonlim/Documents/Arduino/Audio Puzzle/Audio Puzzle.ino:93:29: error: 'currentstep' was not declared in this scope
if (correctSequence[currentstep] == i) {
^~~~~~~~~~~
/Users/jaylonlim/Documents/Arduino/Audio Puzzle/Audio Puzzle.ino:101:13: error: 'onSolve' was not declared in this scope
onSolve();
^~~~~~~
/Users/jaylonlim/Documents/Arduino/Audio Puzzle/Audio Puzzle.ino:114:7: error: 'lastInput' was not declared in this scope
lastInput[i] = currentReading;
^~~~~~~~~
/Users/jaylonlim/Documents/Arduino/Audio Puzzle/Audio Puzzle.ino: In function 'void onSolve()':
/Users/jaylonlim/Documents/Arduino/Audio Puzzle/Audio Puzzle.ino:130:5: error: 'currentstep' was not declared in this scope
currentstep = 0;
^~~~~~~~~~~
/Users/jaylonlim/Documents/Arduino/Audio Puzzle/Audio Puzzle.ino: At global scope:
/Users/jaylonlim/Documents/Arduino/Audio Puzzle/Audio Puzzle.ino:133:1: error: expected unqualified-id before ']' token
];
^
/Users/jaylonlim/Documents/Arduino/Audio Puzzle/Audio Puzzle.ino: In function 'void Loop()':
/Users/jaylonlim/Documents/Arduino/Audio Puzzle/Audio Puzzle.ino:182:6: error: redefinition of 'void Loop()'
void Loop() {
^~~~
/Users/jaylonlim/Documents/Arduino/Audio Puzzle/Audio Puzzle.ino:85:8: note: 'void Loop()' previously defined here
void Loop() {
^~~~
/Users/jaylonlim/Documents/Arduino/Audio Puzzle/Audio Puzzle.ino:185:26: error: 'mux' was not declared in this scope
int currentReading = mux.read(i);
^~~
/Users/jaylonlim/Documents/Arduino/Audio Puzzle/Audio Puzzle.ino:185:26: note: suggested alternative: 'max'
int currentReading = mux.read(i);
^~~
max
/Users/jaylonlim/Documents/Arduino/Audio Puzzle/Audio Puzzle.ino:186:9: error: 'lastInput' was not declared in this scope
if (lastInput[i] == LOW && currentReading == HIGH) {
^~~~~~~~~
/Users/jaylonlim/Documents/Arduino/Audio Puzzle/Audio Puzzle.ino:211:5: error: 'lastInput' was not declared in this scope
lastInput[i] = currentReading;
^~~~~~~~~
/Users/jaylonlim/Documents/Arduino/Audio Puzzle/Audio Puzzle.ino: In function 'void onSolve()':
/Users/jaylonlim/Documents/Arduino/Audio Puzzle/Audio Puzzle.ino:217:6: error: redefinition of 'void onSolve()'
void onSolve() {
^~~~~~~
/Users/jaylonlim/Documents/Arduino/Audio Puzzle/Audio Puzzle.ino:120:8: note: 'void onSolve()' previously defined here
void onSolve() {
^~~~~~~

exit status 1

Compilation error: 'Mux' does not name a type

Hi people, I tried to recreate an audio puzzle game with the exact same code extracted from YouTube. However, I am getting all these errors which I have tried hours trying to resolve but to no avail. Would appreciate if anyone knows the issue to the code.

I've not seen/used full paths to libraries. What happens if you remove them and just supply the .h file so:

becomes:

#include "DFRobotDFPlayerMini.h"

I think the Mux class is found in the admux namespace so you should probably use this:

admux::Mux mux (2, INPUT, Digital, 6, 5, 4, 3);

or add the following line before declaring the mux global variable:

using namespace admux;

This line starts to declare an array but then it just stops. That is why you later get the error on line 42:

bool lastInput[  // DEFINES

I have edited according to your reference and the error for Mux seems to be resolved. However, I'm getting a new error within the same line saying "Compilation error: 'Digital' was not declared in this scope". Do you perhaps have any idea how to declare the "Digital". My apologies in advance as I am very new to the coding world :sweat_smile:

That will somehow prompt a new error as the software is not able to detect the file located externally in my computer :sweat_smile:

Why do you not put them in the standard libraries folder?

// DEFINES
// Flag to toggle debugging output
#define DEBUG

// INCLUDES
// For interfacing with analogue multiplexer
// https://github.com/stechio/arduino-ad-mux-lib
#include "/Users/jaylonlim/Documents/Arduino/Audio Puzzle/libraries/arduino-ad-mux-lib-master/src/Mux.h"
// DEPlayerMini module requires a serial connection. Since we're already using the hardware serial
// connection for the USB interface, we'll create an additional software-emulated serial connection
// using the SoftwareSerial library
#include <SoftwareSerial.h>
// This library exposes functions for playing sounds from DFPlayerMini module using the serial connection
//Download from https://github.com/DFRobot/DFRobotDFPlayerMini
#include "/Users/jaylonlim/Documents/Arduino/Audio Puzzle/libraries/DFRobotDFPlayerMini-master/DFRobotDFPlayerMini.h"


// CONSTANTS
//Define the number of steps in the sequence that the player must follow
const int numInputs = 10;
// The correct sequence of inputs required to solve the puzzle
const int correctSequence[numInputs] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
//This pin will be driven LOW to release a lock when puzzle is solved
const byte lockPin = 12;

using namespace admux;
// GLOBALS
//We need to read 10 digital inputs, which we'll do using 4 control pins 3-6
//Mux mux (2, INPUT, PinType::Digital, 6, 5, 4, 3);
Mux mux(Pin(2, INPUT, PinType::Digital), Pinset(6, 5, 4, 3));
// 16-channel Mux declared with analog input signal on pin A0 and channel control on digital pins 8, 9, 10 and 11.
//Mux mux(Pin(A0, INPUT, PinType::Analog), Pinset(6, 5, 4, 3));
// Initialise a soft serial interface
SoftwareSerial softwareSerial(A0, A1);  //Rx,Tx
// Create an object to access the dfPlayer
DFRobotDFPlayerMini dfPlayer;
// Array to keep track of the last state of every button input
bool lastInput[  // DEFINES
                 // Flag to toggle debugging output

  //Initialisation
  void Setup() {
#ifdef DEBUG
    //Initialise serial communications channel with the PC
    Serial.begin(9600);
    delay(500);
    //Initialise the software serial interface used to control the DFPlayer
    Serial.print(F("Initialising software serial interface to DFPlayer..."));
#endif
    for (int i = 0; i < 10; i++) {
      softwareSerial.begin(9600);
      delay(500);
      if (dfPlayer.begin(softwareSerial)) {
#ifdef DEBUG
        Serial.println(F("OR! "));
#endif
        break;
      } else {
        Serial.print(".");
      }
      if (i == 9) {
#ifdef DEBUG
        Serial.println(F("Failed : ("));
#endif
        return;
      }
    }
    // Set DFPlayer volume (value from 0 to 30)
    dfPlayer.volume(24);
    // set the lock pin as output and secure the lock
    pinMode(lockPin, OUTPUT);
    digitalWrite(lockPin, HIGH);
#ifdef DEBUG
    Serial.println(F("Lock secured"));
#endif

// Debug
#ifdef DEBUG
    Serial.println("Setup Complete");
#endif
  }


  //Main program loop runs indefinitely
  void Loop() {
    for (byte i = 0; i < numInputs; i++) {
      //Reads from channel i
      int currentReading = mux.read(i);
      if (lastInput[i] == LOW && currentReading == HIGH) {
        // Play the sound file called "0001 XXXX.way"/ "0001 XXXX.mp3" saved in the "mp3" folder of the SD card
        dfPlayer.playMp3Folder(i + 1);
        //Is this the correct input?
        if (correctSequence[currentstep] == i) {
          currentstep++;
#ifdef DEBUG
          Serial.print(F("Correct input! Onto step #"));
          Serial.println(currentstep);
#endif
          // Check whether the puzzle has been solved
          if (currentstep == numInputs) {
            onSolve();
          }
        }
        // Incorrect input!
        else {
          currentstep = 0;
          Serial.print(F("Incorrect input! Expected"));
          Serial.print(correctSequence[currentstep]);
          Serial.print(F(" but got"));
          Serial.println(i);
        }
      }
      // Update the stored value for this input
      lastInput[i] = currentReading;
    }
  }


  // Takes action when the puzzle becomes solved
  void onSolve() {
#ifdef DEBUG
    // Print a message
    Serial.println(F("Puzzle Solved!"));
#endif
    // Release the lock
    digitalWrite(lockPin, LOW);
    delay(500);
    digitalWrite(lockPin, HIGH);
    // Reset the step counter
    currentstep = 0;
  }

];
//What step of the sequence is the player currently on?
int currentstep = 0;

Hi People, for the above code I am experiencing the following errors:

/Users/jaylonlim/Documents/Arduino/Audio Puzzle/Audio Puzzle.ino:42:3: error: expected primary-expression before 'void'
void Setup() {
^~~~
/Users/jaylonlim/Documents/Arduino/Audio Puzzle/Audio Puzzle.ino:42:3: error: expected ']' before 'void'
/Users/jaylonlim/Documents/Arduino/Audio Puzzle/Audio Puzzle.ino: In function 'void Loop()':
/Users/jaylonlim/Documents/Arduino/Audio Puzzle/Audio Puzzle.ino:89:11: error: 'lastInput' was not declared in this scope
if (lastInput[i] == LOW && currentReading == HIGH) {
^~~~~~~~~
/Users/jaylonlim/Documents/Arduino/Audio Puzzle/Audio Puzzle.ino:93:29: error: 'currentstep' was not declared in this scope
if (correctSequence[currentstep] == i) {
^~~~~~~~~~~
/Users/jaylonlim/Documents/Arduino/Audio Puzzle/Audio Puzzle.ino:101:13: error: 'onSolve' was not declared in this scope
onSolve();
^~~~~~~
/Users/jaylonlim/Documents/Arduino/Audio Puzzle/Audio Puzzle.ino:114:7: error: 'lastInput' was not declared in this scope
lastInput[i] = currentReading;
^~~~~~~~~
/Users/jaylonlim/Documents/Arduino/Audio Puzzle/Audio Puzzle.ino: In function 'void onSolve()':
/Users/jaylonlim/Documents/Arduino/Audio Puzzle/Audio Puzzle.ino:130:5: error: 'currentstep' was not declared in this scope
currentstep = 0;
^~~~~~~~~~~
/Users/jaylonlim/Documents/Arduino/Audio Puzzle/Audio Puzzle.ino: At global scope:
/Users/jaylonlim/Documents/Arduino/Audio Puzzle/Audio Puzzle.ino:133:1: error: expected unqualified-id before ']' token
];
^

exit status 1

Compilation error: expected primary-expression before 'void'

I am very new to Arduino IDE, so any help would be appreciated!

Please post complete code, your pasted code ends mid-flight.

Is that array definition missing anything?

See how your auto format has shifted the setup() over to the right?

DFRobotDFPlayerMini dfPlayer;
// Array to keep track of the last state of every button input
bool lastInput[  // DEFINES
                 // Flag to toggle debugging output

  //Initialisation
  void Setup() {
#ifdef DEBUG

Nothing looking amiss?

// DEFINES
// Flag to toggle debugging output
#define DEBUG

// INCLUDES
// For interfacing with analogue multiplexer
// https://github.com/stechio/arduino-ad-mux-lib
#include "/Users/jaylonlim/Documents/Arduino/Audio Puzzle/libraries/arduino-ad-mux-lib-master/src/Mux.h"
// DEPlayerMini module requires a serial connection. Since we're already using the hardware serial
// connection for the USB interface, we'll create an additional software-emulated serial connection
// using the SoftwareSerial library
#include <SoftwareSerial.h>
// This library exposes functions for playing sounds from DFPlayerMini module using the serial connection
//Download from https://github.com/DFRobot/DFRobotDFPlayerMini
#include "/Users/jaylonlim/Documents/Arduino/Audio Puzzle/libraries/DFRobotDFPlayerMini-master/DFRobotDFPlayerMini.h"


// CONSTANTS
//Define the number of steps in the sequence that the player must follow
const int numInputs = 10;
// The correct sequence of inputs required to solve the puzzle
const int correctSequence[numInputs] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
//This pin will be driven LOW to release a lock when puzzle is solved
const byte lockPin = 12;

using namespace admux;
// GLOBALS
//We need to read 10 digital inputs, which we'll do using 4 control pins 3-6
//Mux mux (2, INPUT, PinType::Digital, 6, 5, 4, 3);
Mux mux(Pin(2, INPUT, PinType::Digital), Pinset(6, 5, 4, 3));
// 16-channel Mux declared with analog input signal on pin A0 and channel control on digital pins 8, 9, 10 and 11.
//Mux mux(Pin(A0, INPUT, PinType::Analog), Pinset(6, 5, 4, 3));
// Initialise a soft serial interface
SoftwareSerial softwareSerial(A0, A1);  //Rx,Tx
// Create an object to access the dfPlayer
DFRobotDFPlayerMini dfPlayer;
// Array to keep track of the last state of every button input
bool lastInput[  // DEFINES
                 // Flag to toggle debugging output

//Initialisation
void Setup() {
#ifdef DEBUG
  //Initialise serial communications channel with the PC
  Serial.begin(9600);
  delay(500);
  //Initialise the software serial interface used to control the DFPlayer
  Serial.print(F("Initialising software serial interface to DFPlayer..."));
#endif
  for (int i = 0; i < 10; i++) {
    softwareSerial.begin(9600);
    delay(500);
    if (dfPlayer.begin(softwareSerial)) {
#ifdef DEBUG
      Serial.println(F("OR! "));
#endif
      break;
    } else {
      Serial.print(".");
    }
    if (i == 9) {
#ifdef DEBUG
      Serial.println(F("Failed : ("));
#endif
      return;
    }
  }
  // Set DFPlayer volume (value from 0 to 30)
  dfPlayer.volume(24);
  // set the lock pin as output and secure the lock
  pinMode(lockPin, OUTPUT);
  digitalWrite(lockPin, HIGH);
#ifdef DEBUG
  Serial.println(F("Lock secured"));
#endif

// Debug
#ifdef DEBUG
  Serial.println("Setup Complete");
#endif
}


//Main program loop runs indefinitely
void Loop () {
  for (byte i = 0; i < numInputs; i++) {
    //Reads from channel i
    int currentReading = mux.read(i);
    if (lastInput[i] == LOW && currentReading == HIGH) {
      // Play the sound file called "0001 XXXX.way"/ "0001 XXXX.mp3" saved in the "mp3" folder of the SD card
      dfPlayer.playMp3Folder(i + 1);
      //Is this the correct input?
      if (correctSequence[currentstep] == i) {
        currentstep++;
#ifdef DEBUG
        Serial.print(F("Correct input! Onto step #"));
        Serial.println(currentstep);
#endif
        // Check whether the puzzle has been solved
        if (currentstep == numInputs) {
          onSolve();
        }
      }
      // Incorrect input!
      else {
        currentstep = 0;
        Serial.print(F("Incorrect input! Expected"));
        Serial.print(correctSequence[currentstep]);
        Serial.print(F(" but got"));
        Serial.println(i);
      }
    }
    // Update the stored value for this input
    lastInput[i] = currentReading;
  }
}


// Takes action when the puzzle becomes solved
void onSolve () {
#ifdef DEBUG
  // Print a message
  Serial.println(F("Puzzle Solved!"));
#endif
  // Release the lock
  digitalWrite(lockPin, LOW);
  delay(500);
  digitalWrite(lockPin, HIGH);
  // Reset the step counter
  currentstep = 0;
}

My apologies, complete code has been posted under the reply for this comment :slight_smile:

Obviously suspect... per @Idahowalker

@jxylon

Why did you start a second topic for the same problem ?

C++ is case sensitive, setup is not the same as Setup, loop is not the same as Loop. Where did you find this code?

and even third...

All three thread that OP created - contains the same question about the same code.

@jxylon

3 topics on the same subject ? Be very careful or your account may be suspended for a period should you transgress again

Opening several topics on the same subject/same code means that replies are spread between topics making it hard to provide help

I have merged 2 of your topics into this one and closed the third one

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