This commit is contained in:
Jonathan Wyss 2024-02-28 22:52:37 +01:00
parent 471f54b81f
commit b710fed79b

81
main.c
View File

@ -8,13 +8,33 @@
#include"light_ws2812_AVR/Light_WS2812/light_ws2812.h"
#define STARTADC ADCSRA |= _BS(ADSC)
#define STARTADC ADCSRA |= (1<<ADSC)
#define PB_mic PB0
//resolution fft calc:
//https://3roam.com/fft-resolution-bandwidth-calculator/
//128 samples , 1kSPS = 7.8Hz
//interested in 0-10000 Hz
//
//128 bins a 7.8hz = 0...1000Hz
//
//we have 8 leds:
//bands 125hz/band -> 16 bins
//
//1-7.8 - ca 130hz
//2- 255hz
//3- 380
//4- 505
//5- 630
//6- 755
//7- 880
//8- 1kHz
int main (void)
{
int i;
int i,i2;
int colorb;
int colora;
int avg;
char sample[128];
char im[128];
struct cRGB led_bar1[8];
@ -27,19 +47,51 @@ int main (void)
led_bar1[i].b=0;
}
while(1)
{
//######RECORD SAMPLES#######
for(i=0;i<128;i++)
{
sample[i] = ADCH; //read Analog value register 8bit
{
STARTADC;
sample[i] = (ADCH-128)*2; //read Analog value register 8bit center -128
im[i]=0; //pseudo data for funciton
}
fix_fft(sample,im,7,0);//im[i] is always zero
//####Averaging Data####
//
for(i2=0;i2<128;i2++)
{
sample[i2] = sqrt(sample[i2] * sample[i2] + im[i2]* im[i2]);
}
for(i=0;i<8;i++)
{
for(colorb=0;colorb<256;colorb++)
for(i2=1;i2<=16;i2++)
{
sample[i] = (sample[i] + sample[i*16+i2])/2;
}
//avg written to sample[0..7]
//contains values scaled to int boundarys
//scale them to 0..256
sample[i]= map(sample[i],0,30,0,255);
led_bar1[i].r=0;;led_bar1[i].b=0;
//if(sample[i]<2) sample[i]=2;
led_bar1[i].g=sample[i];
}
ws2812_setleds((uint8_t *)led_bar1,8);
}
// _delay_ms(50);
// for(i=0;i<8;i++)
// {
/* for(colorb=0;colorb<256;colorb++)
{
led_bar1[i].r=10;led_bar1[i].g=colorb;led_bar1[i].b=0;
ws2812_sendarray((uint8_t *)led_bar1,8*3);
@ -52,15 +104,22 @@ int main (void)
ws2812_sendarray((uint8_t *)led_bar1,8*3);
_delay_ms(1);
}
led_bar1[0].r=0;led_bar1[0].g=100;led_bar1[0].b=10;
}*/
/*led_bar1[0].r=0;led_bar1[0].g=100;led_bar1[0].b=10;
ws2812_sendarray((uint8_t *)led_bar1,8*3);
_delay_ms(50);
_delay_ms(50);
led_bar1[0].r=255;led_bar1[0].g=0;led_bar1[0].b=10;
ws2812_sendarray((uint8_t *)led_bar1,8*3);
ws2812_sendarray((uint8_t *)led_bar1,8*3); */
// }
}
}
return 0;
}
int map(int value, int old_min, int old_max,int new_min, int new_max)
{
return (new_max/old_max*value);
}