Ok, thanks. Then I guess I'll just keep my code as it is. It is running well now. Thanks to all of you for helping me.
Got this out by turning the output array to 8bit, dividing it instead of mapping it, and changing the way
I displayed the pixels (line by line instead of pixel by pixel)
Here is the final code :
#define LOG_OUT 1 // Utilisation de la fonction LOG
#define FFT_N 32 // Etude sur 32 points
#include <FFT.h> // insert la bibliothèque FFT
#include <Adafruit_GFX.h> // insert la bibliothèque Adafruit GFX
#include <Adafruit_SPITFT.h>
#include <Adafruit_SPITFT_Macros.h>
#include <Adafruit_NeoMatrix.h> // insert la bibliothèque Adafruit NeoMatrix pr communiquer avec la matrice led
#include <Adafruit_NeoPixel.h> // insert la bibliothèque Adafruit Neopixel, complémentaire a NeoMatrix
#ifndef PSTR
#define PSTR // Make Arduino Due happy (je sais pas à quoi ça sert, mais c'est dans l'exemple de la bibliothèque NeoMatrix, donc je le met)
#endif
#define PIN 6 // définie la pin de la matrice
/* Définition de la matrice :
* Paramètre n°1 => Largeur de la matrice
* Paramètre n°2 => Longueur de la matrice
* Paramètre n°3 => Pin de la matrice
* Paramètre n°4 => Définition du type de la matrice. A ajouter :
* - Position du premier pixel : RIGHT / LEFT + TOP / BOTTOM
* - Agencement des pixels : ROWS / COLUMS
*/
Adafruit_NeoMatrix matrix = Adafruit_NeoMatrix(16, 16, PIN,
NEO_MATRIX_BOTTOM + NEO_MATRIX_RIGHT +
NEO_MATRIX_ROWS + NEO_MATRIX_ZIGZAG,
NEO_GRB + NEO_KHZ800);
int const eq[] = {190, 160, 90, 80, 50, 40, 30, 20, 20, 10, 5, 5, 5, 0, 0, 0};
int8_t level[16];
void setup() {
TIMSK0 = 0; // turn off timer0 for lower jitter
ADCSRA = 0xe5; // set the adc to free running mode
ADMUX = 0x40; // use adc0
DIDR0 = 0x01; // turn off the digital input for adc0
matrix.begin();
matrix.setBrightness(20);
}
void loop() {
while(1) { // reduces jitter
cli(); // UDRE interrupt slows this way down on arduino1.0
for (int i = 0 ; i < 64 ; i += 2) { // save 32 samples
while(!(ADCSRA & 0x10)); // wait for adc to be ready
ADCSRA = 0xf5; // restart adc
byte m = ADCL; // fetch adc data
byte j = ADCH;
int k = (j << 8) | m; // form into an int
k -= 0x0200; // form into a signed int
k <<= 6; // form into a 16b signed int
fft_input[i] = k; // put real data into even bins
fft_input[i+1] = 0; // set odd bins to 0
}
fft_window(); // window the data for better frequency response
fft_reorder(); // reorder the data before doing the fft
fft_run(); // process the data in the fft
fft_mag_log(); // take the output of the fft
sei();
initialisation();
byte i = 0;
while (i < FFT_N/2) {
if (fft_log_out[i] >= 0) {
level[i] = (((uint8_t)fft_log_out[i]) - eq[i]) / 16;
} else {
level[i] = 0;
}
displaySound(i, level[i]);
i++;
}
matrix.show();
}
}
void initialisation() {
matrix.writeFillRect(0, 14, 16, 2, matrix.Color(0, 0, 255));
matrix.writeFillRect(0, 5, 16, 9, matrix.Color(0, 255, 0));
matrix.writeFillRect(0, 0, 16, 5, matrix.Color(255, 0, 0));
}
void displaySound(int x, int h) {
matrix.writeFastVLine(x, 0, 15-h, 0);
}