Spectrum analyser with WS2812B serpentine led matrix
i new arduino coding. built 10*10 led matrix ws2812b leds , fastled library, looks awesome example sketches. decided make spectrum analyser matrix using arduino nano , found code on instructibles(instruction):
but code fits matrix pixels laid in 1 direction , matrix made serpentine layout(every column upside down). found example matrix serpentine layout can't figure out change in first code match matrix.
what suggest?
code: [select]
/*
written fischimc , supastefe
this sketch uses 10x10 rgb led-matrix spectrum analyzer
it uses ftt library analyze audio signal connected the
pin a7 of arduino nano. everytime column gets higher than
10 pixels color of each column changes.
*/
#define log_out 0 //set output of fft library linear not logarithmical
#define lin_out 1
#define fft_n 256 //set 256 point fft
#include <fft.h> //include fft library
#include <fastled.h> //include fastled library
#include <math.h> //include library mathematic funcions
#define data_pin 3 //data pin leds connected
#define num_leds 100 //amount of leds in matrix
crgb leds[num_leds];
float faktoren[10] = {1, 1.1, 1.15, 1.25, 1.45, 1.55, 1.75, 1.8, 2, 3}; //factors increase height of each column
unsigned char hs[10] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; //height of each column
float hue = 0; //hue value of colors
void setbalken(unsigned char column, unsigned char height){ //calculation of height of each column
unsigned char h = (unsigned char)map(height, 0, 255, 0, 10);
h = (unsigned char)(h * faktoren[column]);
if (h < hs[column]){
hs[column]--;
}
else if (h > hs[column]){
hs[column] = h;
}
if (height > 250){
hue+=2; //change value if want difference between colors bigger
if(hue > 25) hue=0;
}
for(unsigned char y = 0; y < 10; y++){ //set colors of pixels according column , hue
if(hs[column] > y){
leds[y+(column*10)] = chsv((hue*10)+(column*10), 255, 200);
} else {
leds[y+(column*10)] = crgb::black;
}
}
}
unsigned char grenzen[11] = {0,3,5,7,9,11,13,16,24,32,69}; //borders of frequency areas
void setup() {
fastled.addleds<ws2812b, data_pin, grb> (leds, num_leds);
serial.begin(115200); //use serial port
timsk0 = 0; //turn off timer0 lower jitter
adcsra = 0xe5; //set adc free running mode
admux = 0b01000111; //use pin a7
didr0 = 0x01; //turn off digital input
analogreference(external); //set aref external
}
void loop() {
while(1) { //reduces jitter
cli(); //udre interrupt slows way down on arduino1.0
(int = 0 ; < 512 ; += 2) { //save 256 samples
while(!(adcsra & 0x10)); //wait adc ready
adcsra = 0xf5; //restart adc
byte m = adcl; //fetch adc data
byte j = adch;
int k = (j << 8) | m; //form int
k -= 0x0200; //form signed int
k <<= 6; //form 16b signed int
fft_input[i] = k; //put real data bins
}
fft_window(); // window data better frequency response
fft_reorder(); // reorder data before doing fft
fft_run(); // process data in fft
fft_mag_lin(); // take output of fft
sei();
fft_lin_out[0] = 0;
fft_lin_out[1] = 0;
for(unsigned char = 0; < 11; i++){
unsigned char maxw = 0;
for(unsigned char x = grenzen[i]; x < grenzen[i+1];x++){
if((unsigned char)fft_lin_out[x] > maxw){
maxw = (unsigned char)fft_lin_out[x];
}
}
setbalken(i, maxw);
serial.print(maxw);
serial.print(" ");
}
serial.println("");
timsk0 = 1;
fastled.show();
timsk0 = 0;
}
}
but code fits matrix pixels laid in 1 direction , matrix made serpentine layout(every column upside down). found example matrix serpentine layout can't figure out change in first code match matrix.
what suggest?

Arduino Forum > Using Arduino > Programming Questions > Spectrum analyser with WS2812B serpentine led matrix
arduino
Comments
Post a Comment