0

I am creating a sound visualizer using an arduino nano,electret condenser microphone and 8X32 matrix and i keep getting the same error.

here is the code:

#include <ArduinoFFT.h>
#include <Adafruit_GFX.h>
#include <Adafruit_NeoMatrix.h>
#include <Adafruit_NeoPixel.h>

#define PIN_MATRIX 2 // Arduino Nano Pin D2 to DIN of matrix
#define PIN_MIC 0   // Arduino Nano Analog Pin A0 to microphone Vout
#define MATRIX_WIDTH 32
#define MATRIX_HEIGHT 8
#define MIC_SAMPLE_SIZE 48 // Change according to your mic module's specifications

ArduinoFFT fft;

Adafruit_NeoMatrix matrix = Adafruit_NeoMatrix(MATRIX_WIDTH, MATRIX_HEIGHT, PIN_MATRIX,
  NEO_MATRIX_TOP     + NEO_MATRIX_LEFT +
  NEO_MATRIX_COLUMNS + NEO_MATRIX_ZIGZAG,
  NEO_GRB            + NEO_KHZ800);

void setup() {
  Serial.begin(9600);
  matrix.begin();
  matrix.setTextWrap(false);
  matrix.setBrightness(50); // Adjust brightness as needed
  matrix.setTextColor(matrix.Color(255, 255, 255)); // Text color
  fft.begin(MIC_SAMPLE_SIZE); // Initialize the FFT object
}

void loop() {
  fft.Execute(); // Run FFT

  int max_index = 0;
  int max_value = 0;

  for (int i = 0; i < MIC_SAMPLE_SIZE / 2; i++) {
    int value = fft.Output[i]; // Read FFT result
    if (value > max_value) {
      max_value = value;
      max_index = i;
    }
  }

  // Map max_index to matrix columns
  int column = map(max_index, 0, MIC_SAMPLE_SIZE / 2, 0, MATRIX_WIDTH);

  // Clear matrix
  matrix.fillScreen(0);

  // Draw bar on matrix
  for (int y = 0; y < MATRIX_HEIGHT; y++) {
    matrix.drawPixel(column, y, matrix.Color(255, 255, 255)); // White color
  }

  matrix.show();
}

Here is the error:

/Users/vyomesh/Documents/Arduino/sketch_apr22a/sketch_apr22a.ino:12:1: error: invalid use of template-name 'ArduinoFFT' without an argument list
 ArduinoFFT fft;
 ^~~~~~~~~~
/Users/vyomesh/Documents/Arduino/sketch_apr22a/sketch_apr22a.ino:12:1: note: class template argument deduction is only available with -std=c++1z or -std=gnu++1z
In file included from /Users/vyomesh/Documents/Arduino/sketch_apr22a/sketch_apr22a.ino:1:0:
/Users/vyomesh/Documents/Arduino/libraries/arduinoFFT/src/ArduinoFFT.h:58:29: note: 'template<class T> class ArduinoFFT' declared here
 template <typename T> class ArduinoFFT {
                             ^~~~~~~~~~
/Users/vyomesh/Documents/Arduino/sketch_apr22a/sketch_apr22a.ino: In function 'void setup()':
/Users/vyomesh/Documents/Arduino/sketch_apr22a/sketch_apr22a.ino:25:3: error: 'fft' was not declared in this scope
   fft.begin(MIC_SAMPLE_SIZE); // Initialize the FFT object
   ^~~
/Users/vyomesh/Documents/Arduino/sketch_apr22a/sketch_apr22a.ino:25:3: note: suggested alternative: 'ffs'
   fft.begin(MIC_SAMPLE_SIZE); // Initialize the FFT object
   ^~~
   ffs
/Users/vyomesh/Documents/Arduino/sketch_apr22a/sketch_apr22a.ino: In function 'void loop()':
/Users/vyomesh/Documents/Arduino/sketch_apr22a/sketch_apr22a.ino:29:3: error: 'fft' was not declared in this scope
   fft.Execute(); // Run FFT
   ^~~
/Users/vyomesh/Documents/Arduino/sketch_apr22a/sketch_apr22a.ino:29:3: note: suggested alternative: 'ffs'
   fft.Execute(); // Run FFT
   ^~~
   ffs

exit status 1

Compilation error: invalid use of template-name 'ArduinoFFT' without an argument list

Matrix Wiring: GND-GND 5V-5V DIN-D2

Electret condenser michrophone: Positive- A0 and connected to 5V through resistor Negative- GND

Other info: Macos sonoma library name- ArduinoFFT.h

  • Restarted IDE
  • Reinstalled the library
  • tried different versions
  • sought help from ChatGPT as a last resort (still failed)

1 Answer 1

1

This is a build-related issue. It has nothing to do with your electronic design ..

According to the GitHub page of the project, you are expected to provide some parameters to the constructor:

/*
These are the input and output vectors
Input vectors receive computed results from FFT
*/
double vReal[samples];
double vImag[samples];

ArduinoFFT<double> FFT = ArduinoFFT<double>(vReal, vImag, samples, samplingFrequency);

The above code is taken from the example file FFT_01.ino hosted on the project's GitHub page.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.