fading on different color presets

This commit is contained in:
Jonathan Wyss 2024-03-27 19:16:38 +01:00
parent d994c95941
commit 365dd49fbd

87
main.c
View File

@ -31,37 +31,49 @@
//8- 1kHz
//
const float log_scale = 64./log(64./SCALE_FACTOR + 1.);
int msec;
int sec;
uint16_t ticks;
int ticks_sample;
ISR(TIMER1_OVF_vect)
{
if(ticks < 65000)
{
ticks_sample++;
if(ticks < 65000)
{
ticks++;
}
if(ticks > 65000)
{
}
if(ticks >= 65000)
{
ticks=0;
}
if(sec<255)
{
sec++;
}
else
{
sec=0;
}
}
}
int main (void)
{
int i,i2;
int i4=0;
int sum,avg;
char sample[64];
char buff[64];
float fac_r=0.1;
float fac_g=0.1;
float fac_b=1;
msec=0;
float fac_g=0.5;
float fac_b=0.7;
sec=0;
ticks=0;
ticks_sample=0;
struct cRGB led_bar1[8];
Fader fader1[4]={{5,5,5},{7,3,2},{3,7,2},{2,3,7}};
//DDRB = (1<<mic);//would be setting output, default is input so no need for setting
setupADC();
setupTimer();
@ -81,49 +93,50 @@ int main (void)
sei();
while(1)
{
//######RECORD SAMPLES######
sum = 0;
ticks=0;
//######RECORD SAMPLES######
sum = 0;
ticks_sample=0;
if(sec>3)
{
fac_r=(float)fader1[i4].r/10;
fac_g=(float)fader1[i4].g/10;
fac_b=(float)fader1[i4].b/10;
if(i4<3) {i4++;}
else {i4=0;}
sec=0;
}
for(i=0;i<64;i++)
{
STARTADC;
sample[i] = (ADCH-128); //read Analog value register 8bit center -128
//sample[i] = (sample[i] <= NOISE) ? 0 : (sample[i] - NOISE); //noise reduction
//im[i]=0; //pseudo data for funciton
//
sum+=sample[i];//dc-bias
}
//samplingrate -> 1/ca30'000'00r
avg = sum/64;//calculate bias
for(i=0;i<64;i++)
{
sample[i]-=avg;//remove bias
}
fix_fftr(sample,6,0);//im[i] is alwa§§ys zero
//####Averaging Data####
//
fix_fftr(sample,6,0);
//####Averaging Data####
for(i=0;i<64;i++)
{
if(sample[i]<0) sample[i] = 0;
if(sample[i]>64) sample[i]=64;
if(sample[i]>64) sample[i]=64; //define upper limit
sample[i] = sample[i] *SCALE_FACTOR;
sample[i] = (sample[i]*0.7 + buff[i]*0.3);
buff[i] = sample[i];
sample[i] = (sample[i]*0.7 + buff[i]*0.3); //influence of last sample on current sample
buff[i] = sample[i]; //store sample for next round
}
for(i=0;i<8;i++)
for(i=0;i<8;i++) //we store 8 frequency domains acros the whole 64 stpectrum
{
for(i2=1;i2<=4;i2++)
{
sample[i] = ((sample[i] + sample[i*8+i2])/2);
sample[i] = ((sample[i] + sample[i*8+i2])/2);//average each 4 following spectrums, write results to sample[0..7]
}
//avg written to sample[0..7]
if(sample[i]<20)
{
led_bar1[i].r=(char)sample[i]*fac_r;
@ -145,7 +158,7 @@ int main (void)
}
}
ws2812_setleds(led_bar1,8);
while(ticks<60){ asm("");}//workaround for stoping gcc optimizing
while(ticks_sample<60){asm("");}//workaround for stoping gcc optimizing
}
return 0;
}
@ -169,11 +182,3 @@ void setupTimer(void)
* 255/0.017204*0.001=15 counts = 1ms
* 256 gives 1ms
*/
void wait_period(void)
{
// TIFR |=(1<<TOV1); //clear overflow flag
}