I am trying to write a lib for my rgb cube with a function which returns a array of frequencys and their amplitude. I'd like to usethe FHT.h lib for this. So i tried creating a simple Class called Sound which includes the FHT.h and so on but i can't compile it in any way.
So i read the article about the fht and just tried to "copy past" it. I am not sure if it even would work with my Arduino Mega 2560 like this but its a start:
#pragma once
#include "Arduino.h"
#define LOG_OUT = 1
#define FHT_N = 128
#include "FHT.h"
class Sound
{
public:
Sound()
{
ADCSRA = 0xe5; // set the adc to free running mode
ADMUX = 0x40; // use adc0
DIDR0 = 0x01; // turn off the digital input for adc0
};
~Sound();
inline void getValues(uint8_t *data)
{
for (int i = 0; i < FHT_N; i++) // save 256 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
fht_input[i] = k; // put real data into bins
}
fht_window(); // window the data for better frequency response
fht_reorder(); // reorder the data before doing the fht
fht_run(); // process the data in the fht
fht_mag_log(); // take the output of the fht
//need a copy here...
data = fht_log_out;//not correct!
};
};
- Is it even possible like this or do i need to include the fht in global scope?
- Moreover can i use this "enabling freerun" and so on at my Mega2560?
- How do i set the analogpin?
I am going to use the MAX4466 from adafruit....