FHT arduino and HT1632c
Alrighty so the things up and running, besides a few ms of delay and some noise on the last 2 bands of the meter, 30, and 31, and some noise from the bottom of the spectrum, anyways can ya'll help with these issues?
Oh and yes I know the X and Y are backwards at first on the text, I screwed up there and just didn't wanna fix it yet.
Oh and yes I know the X and Y are backwards at first on the text, I screwed up there and just didn't wanna fix it yet.
#include <ht1632c.h>
#define LOG_OUT 1 // use the log output function
#define FHT_N 64 // set to 256 point fft
#include <FHT.h> // include the library
ht1632c dotmatrix = ht1632c(PORTD, 7, 6, 4, 5, GEOM_32x16, 2);
int pinArray[] = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15};
int LedXs[] = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31};
int countx = 0;
int county = 0;
void setup()
{
Serial.begin(115200);
dotmatrix.clear();
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
}
void loop() {
while(1) { // reduces jitter
cli(); // UDRE interrupt slows this way down on arduino1.0
for (int i = 0 ; i < FHT_N ; i++) { // save 256 samples
if ( (i & 0x01) == 0 ){county++; if(county >= 33){county = 0; } }/*needed to use 33 instead of 31
because something do with counting evens, only reason I know that is because I asked Mark
in the support email thing, so thanks mark.*/
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
sei();
countx = (fht_log_out[county]/15.9375)-2; //The -2 is for the noise issue..
Spectrum(countx, (county));
dotmatrix.sendframe();
//
}
}
void Spectrum(int htX, int htY){
switch(htX){
case 0:
dotmatrix.plot(htY, 0, BLACK);
dotmatrix.plot(htY,1,BLACK);
dotmatrix.plot(htY,2,BLACK);
dotmatrix.plot(htY,3,BLACK);
dotmatrix.plot(htY,4,BLACK);
dotmatrix.plot(htY,5,BLACK);
dotmatrix.plot(htY,6,BLACK);
dotmatrix.plot(htY,7,BLACK);
dotmatrix.plot(htY,8,BLACK);
dotmatrix.plot(htY,9,BLACK);
dotmatrix.plot(htY,10,BLACK);
dotmatrix.plot(htY,11,BLACK);
dotmatrix.plot(htY,12,BLACK);
dotmatrix.plot(htY,13,BLACK);
dotmatrix.plot(htY,14,BLACK);
dotmatrix.plot(htY,15,BLACK);
break;
case 1:
dotmatrix.plot(htY, 0, GREEN);
dotmatrix.plot(htY, 1, BLACK);
dotmatrix.plot(htY,2,BLACK);
dotmatrix.plot(htY,3,BLACK);
dotmatrix.plot(htY,4,BLACK);
dotmatrix.plot(htY,5,BLACK);
dotmatrix.plot(htY,6,BLACK);
dotmatrix.plot(htY,7,BLACK);
dotmatrix.plot(htY,8,BLACK);
dotmatrix.plot(htY,9,BLACK);
dotmatrix.plot(htY,10,BLACK);
dotmatrix.plot(htY,11,BLACK);
dotmatrix.plot(htY,12,BLACK);
dotmatrix.plot(htY,13,BLACK);
dotmatrix.plot(htY,14,BLACK);
dotmatrix.plot(htY,15,BLACK);
break;
case 2:
dotmatrix.plot(htY, 0, GREEN);
dotmatrix.plot(htY, 1, GREEN);
dotmatrix.plot(htY, 2, BLACK);
dotmatrix.plot(htY,3,BLACK);
dotmatrix.plot(htY,4,BLACK);
dotmatrix.plot(htY,5,BLACK);
dotmatrix.plot(htY,6,BLACK);
dotmatrix.plot(htY,7,BLACK);
dotmatrix.plot(htY,8,BLACK);
dotmatrix.plot(htY,9,BLACK);
dotmatrix.plot(htY,10,BLACK);
dotmatrix.plot(htY,11,BLACK);
dotmatrix.plot(htY,12,BLACK);
dotmatrix.plot(htY,13,BLACK);
dotmatrix.plot(htY,14,BLACK);
dotmatrix.plot(htY,15,BLACK);
break;
case 3:
dotmatrix.plot(htY, 0, GREEN);
dotmatrix.plot(htY, 1, GREEN);
dotmatrix.plot(htY, 2, GREEN);
dotmatrix.plot(htY, 3, BLACK);
dotmatrix.plot(htY,4,BLACK);
dotmatrix.plot(htY,5,BLACK);
dotmatrix.plot(htY,6,BLACK);
dotmatrix.plot(htY,7,BLACK);
dotmatrix.plot(htY,8,BLACK);
dotmatrix.plot(htY,9,BLACK);
dotmatrix.plot(htY,10,BLACK);
dotmatrix.plot(htY,11,BLACK);
dotmatrix.plot(htY,12,BLACK);
dotmatrix.plot(htY,13,BLACK);
dotmatrix.plot(htY,14,BLACK);
dotmatrix.plot(htY,15,BLACK);
break;
case 4:
dotmatrix.plot(htY, 0, GREEN);
dotmatrix.plot(htY, 1, GREEN);
dotmatrix.plot(htY, 2, GREEN);
dotmatrix.plot(htY, 3, GREEN);
dotmatrix.plot(htY, 4, BLACK);
dotmatrix.plot(htY,5,BLACK);
dotmatrix.plot(htY,6,BLACK);
dotmatrix.plot(htY,7,BLACK);
dotmatrix.plot(htY,8,BLACK);
dotmatrix.plot(htY,9,BLACK);
dotmatrix.plot(htY,10,BLACK);
dotmatrix.plot(htY,11,BLACK);
dotmatrix.plot(htY,12,BLACK);
dotmatrix.plot(htY,13,BLACK);
dotmatrix.plot(htY,14,BLACK);
dotmatrix.plot(htY,15,BLACK);
break;
case 5:
dotmatrix.plot(htY, 0, GREEN);
dotmatrix.plot(htY, 1, GREEN);
dotmatrix.plot(htY, 2, GREEN);
dotmatrix.plot(htY, 3, GREEN);
dotmatrix.plot(htY, 4, GREEN);
dotmatrix.plot(htY, 5, BLACK);
dotmatrix.plot(htY,6,BLACK);
dotmatrix.plot(htY,7,BLACK);
dotmatrix.plot(htY,8,BLACK);
dotmatrix.plot(htY,9,BLACK);
dotmatrix.plot(htY,10,BLACK);
dotmatrix.plot(htY,11,BLACK);
dotmatrix.plot(htY,12,BLACK);
dotmatrix.plot(htY,13,BLACK);
dotmatrix.plot(htY,14,BLACK);
dotmatrix.plot(htY,15,BLACK);
break;
case 6:
dotmatrix.plot(htY, 0, GREEN);
dotmatrix.plot(htY, 1, GREEN);
dotmatrix.plot(htY, 2, GREEN);
dotmatrix.plot(htY, 3, GREEN);
dotmatrix.plot(htY, 4, GREEN);
dotmatrix.plot(htY, 5, GREEN);
dotmatrix.plot(htY, 6, BLACK);
dotmatrix.plot(htY,7,BLACK);
dotmatrix.plot(htY,8,BLACK);
dotmatrix.plot(htY,9,BLACK);
dotmatrix.plot(htY,10,BLACK);
dotmatrix.plot(htY,11,BLACK);
dotmatrix.plot(htY,12,BLACK);
dotmatrix.plot(htY,13,BLACK);
dotmatrix.plot(htY,14,BLACK);
dotmatrix.plot(htY,15,BLACK);
break;
case 7:
dotmatrix.plot(htY, 0, GREEN);
dotmatrix.plot(htY, 1, GREEN);
dotmatrix.plot(htY, 2, GREEN);
dotmatrix.plot(htY, 3, GREEN);
dotmatrix.plot(htY, 4, GREEN);
dotmatrix.plot(htY, 5, GREEN);
dotmatrix.plot(htY, 6, GREEN);
dotmatrix.plot(htY, 7, BLACK);
dotmatrix.plot(htY,8,BLACK);
dotmatrix.plot(htY,9,BLACK);
dotmatrix.plot(htY,10,BLACK);
dotmatrix.plot(htY,11,BLACK);
dotmatrix.plot(htY,12,BLACK);
dotmatrix.plot(htY,13,BLACK);
dotmatrix.plot(htY,14,BLACK);
dotmatrix.plot(htY,15,BLACK);
break;
case 8:
dotmatrix.plot(htY, 0, GREEN);
dotmatrix.plot(htY, 1, GREEN);
dotmatrix.plot(htY, 2, GREEN);
dotmatrix.plot(htY, 3, GREEN);
dotmatrix.plot(htY, 4, GREEN);
dotmatrix.plot(htY, 5, GREEN);
dotmatrix.plot(htY, 6, GREEN);
dotmatrix.plot(htY, 7, GREEN);
dotmatrix.plot(htY, 8, BLACK);
dotmatrix.plot(htY,9,BLACK);
dotmatrix.plot(htY,10,BLACK);
dotmatrix.plot(htY,11,BLACK);
dotmatrix.plot(htY,12,BLACK);
dotmatrix.plot(htY,13,BLACK);
dotmatrix.plot(htY,14,BLACK);
dotmatrix.plot(htY,15,BLACK);
break;
case 9:
dotmatrix.plot(htY, 0, GREEN);
dotmatrix.plot(htY, 1, GREEN);
dotmatrix.plot(htY, 2, GREEN);
dotmatrix.plot(htY, 3, GREEN);
dotmatrix.plot(htY, 4, GREEN);
dotmatrix.plot(htY, 5, GREEN);
dotmatrix.plot(htY, 6, GREEN);
dotmatrix.plot(htY, 7, GREEN);
dotmatrix.plot(htY, 8, ORANGE);
dotmatrix.plot(htY, 9, BLACK);
dotmatrix.plot(htY,10,BLACK);
dotmatrix.plot(htY,11,BLACK);
dotmatrix.plot(htY,12,BLACK);
dotmatrix.plot(htY,13,BLACK);
dotmatrix.plot(htY,14,BLACK);
dotmatrix.plot(htY,15,BLACK);
break;
case 10:
dotmatrix.plot(htY, 0, GREEN);
dotmatrix.plot(htY, 1, GREEN);
dotmatrix.plot(htY, 2, GREEN);
dotmatrix.plot(htY, 3, GREEN);
dotmatrix.plot(htY, 4, GREEN);
dotmatrix.plot(htY, 5, GREEN);
dotmatrix.plot(htY, 6, GREEN);
dotmatrix.plot(htY, 7, GREEN);
dotmatrix.plot(htY, 8, ORANGE);
dotmatrix.plot(htY, 9, ORANGE);
dotmatrix.plot(htY, 10, BLACK);
dotmatrix.plot(htY,11,BLACK);
dotmatrix.plot(htY,12,BLACK);
dotmatrix.plot(htY,13,BLACK);
dotmatrix.plot(htY,14,BLACK);
dotmatrix.plot(htY,15,BLACK);
break;
case 11:
dotmatrix.plot(htY, 0, GREEN);
dotmatrix.plot(htY, 1, GREEN);
dotmatrix.plot(htY, 2, GREEN);
dotmatrix.plot(htY, 3, GREEN);
dotmatrix.plot(htY, 4, GREEN);
dotmatrix.plot(htY, 5, GREEN);
dotmatrix.plot(htY, 6, GREEN);
dotmatrix.plot(htY, 7, GREEN);
dotmatrix.plot(htY, 8, ORANGE);
dotmatrix.plot(htY, 9, ORANGE);
dotmatrix.plot(htY, 10, ORANGE);
dotmatrix.plot(htY, 11, BLACK);
dotmatrix.plot(htY,12,BLACK);
dotmatrix.plot(htY,13,BLACK);
dotmatrix.plot(htY,14,BLACK);
dotmatrix.plot(htY,15,BLACK);
break;
case 12:
dotmatrix.plot(htY, 0, GREEN);
dotmatrix.plot(htY, 1, GREEN);
dotmatrix.plot(htY, 2, GREEN);
dotmatrix.plot(htY, 3, GREEN);
dotmatrix.plot(htY, 4, GREEN);
dotmatrix.plot(htY, 5, GREEN);
dotmatrix.plot(htY, 6, GREEN);
dotmatrix.plot(htY, 7, GREEN);
dotmatrix.plot(htY, 8, ORANGE);
dotmatrix.plot(htY, 9, ORANGE);
dotmatrix.plot(htY, 10, ORANGE);
dotmatrix.plot(htY, 11, ORANGE);
dotmatrix.plot(htY, 12, BLACK);
dotmatrix.plot(htY,13,BLACK);
dotmatrix.plot(htY,14,BLACK);
dotmatrix.plot(htY,15,BLACK);
break;
case 13:
dotmatrix.plot(htY, 0, GREEN);
dotmatrix.plot(htY, 1, GREEN);
dotmatrix.plot(htY, 2, GREEN);
dotmatrix.plot(htY, 3, GREEN);
dotmatrix.plot(htY, 4, GREEN);
dotmatrix.plot(htY, 5, GREEN);
dotmatrix.plot(htY, 6, GREEN);
dotmatrix.plot(htY, 7, GREEN);
dotmatrix.plot(htY, 8, ORANGE);
dotmatrix.plot(htY, 9, ORANGE);
dotmatrix.plot(htY, 10, ORANGE);
dotmatrix.plot(htY, 11, ORANGE);
dotmatrix.plot(htY, 12, ORANGE);
dotmatrix.plot(htY, 13, BLACK);
dotmatrix.plot(htY,14,BLACK);
dotmatrix.plot(htY,15,BLACK);
break;
case 14:
dotmatrix.plot(htY, 0, GREEN);
dotmatrix.plot(htY, 1, GREEN);
dotmatrix.plot(htY, 2, GREEN);
dotmatrix.plot(htY, 3, GREEN);
dotmatrix.plot(htY, 4, GREEN);
dotmatrix.plot(htY, 5, GREEN);
dotmatrix.plot(htY, 6, GREEN);
dotmatrix.plot(htY, 7, GREEN);
dotmatrix.plot(htY, 8, ORANGE);
dotmatrix.plot(htY, 9, ORANGE);
dotmatrix.plot(htY, 10, ORANGE);
dotmatrix.plot(htY, 11, ORANGE);
dotmatrix.plot(htY, 12, ORANGE);
dotmatrix.plot(htY, 13, ORANGE);
dotmatrix.plot(htY, 14, BLACK);
dotmatrix.plot(htY,15,BLACK);
break;
case 15:
dotmatrix.plot(htY, 0, GREEN);
dotmatrix.plot(htY, 1, GREEN);
dotmatrix.plot(htY, 2, GREEN);
dotmatrix.plot(htY, 3, GREEN);
dotmatrix.plot(htY, 4, GREEN);
dotmatrix.plot(htY, 5, GREEN);
dotmatrix.plot(htY, 6, GREEN);
dotmatrix.plot(htY, 7, GREEN);
dotmatrix.plot(htY, 8, ORANGE);
dotmatrix.plot(htY, 9, ORANGE);
dotmatrix.plot(htY, 10, ORANGE);
dotmatrix.plot(htY, 11, ORANGE);
dotmatrix.plot(htY, 12, ORANGE);
dotmatrix.plot(htY, 13, ORANGE);
dotmatrix.plot(htY, 14, RED);
dotmatrix.plot(htY, 15, BLACK);
break;
case 16:
dotmatrix.plot(htY, 0, GREEN);
dotmatrix.plot(htY, 1, GREEN);
dotmatrix.plot(htY, 2, GREEN);
dotmatrix.plot(htY, 3, GREEN);
dotmatrix.plot(htY, 4, GREEN);
dotmatrix.plot(htY, 5, GREEN);
dotmatrix.plot(htY, 6, GREEN);
dotmatrix.plot(htY, 7, GREEN);
dotmatrix.plot(htY, 8, ORANGE);
dotmatrix.plot(htY, 9, ORANGE);
dotmatrix.plot(htY, 10, ORANGE);
dotmatrix.plot(htY, 11, ORANGE);
dotmatrix.plot(htY, 12, ORANGE);
dotmatrix.plot(htY, 13, ORANGE);
dotmatrix.plot(htY, 14, RED);
dotmatrix.plot(htY, 15, RED);
break;
}
}