//fastled colorpallet.ino verwuselt by marderchen for rainbow headphones soundvisu=^.^= MEOW (controling 48 WS2812 LEDs on PB7 with analog audio input) #define t1 PA1 //PB12 #define t2 PB13 #define t3 PB14 #define t4 PB15 #define t5 PA8 #define t6 PB11 #define t7 PB10 #define t8 PB0 #define sound PA0 #define soundb PA1 #define pruf PB5 long allfcount = micros(); long maintime = millis(); int onpress[17]; long soundcachL[512]; //cute F103 this is realy big long soundcachR[512]; int zeit1 =0; int zeit3=0; int zeit4=0; long zeita =10; //untervallspeed int zeitr=10; int zeitb =10; //anzeitverlängerung int zeitc =30; //auszeitverlängerung int teiler =1; //emfpindlichkeit int fcount1 =0; int present =3; int soundi =0; int soundi2 =0; int soundminimum =2; int setled=10; int setled3=10; int setled4=10; int colorindex2 =0; int setled2 =10; int zeit2=0; int volcount =0; int ka =0; int taster =0; int peaklowL=0; int peaklowR=0; int peakhighL=0; int peakhighR=0; int peakcach =0; int peakcachR =0; int peakcounter =0; int peakL =0; int peakR =0; int peakslowL =0; int peakslowR =0; int verschiebL=0; int barheight=20; //fastled #include #define LED_PIN PB7 #define NUM_LEDS 48 #define BRIGHTNESS 255 #define LED_TYPE WS2812 #define COLOR_ORDER GRB CRGB leds[NUM_LEDS]; CRGBPalette16 currentPalette; TBlendType currentBlending; #define UPDATES_PER_SECOND 1000 //cute its fast extern CRGBPalette16 myRedWhiteBluePalette; extern const TProgmemPalette16 myRedWhiteBluePalette_p PROGMEM; //end void setup() { pinMode(pruf, OUTPUT); pinMode(t1, INPUT); pinMode(t2, INPUT); pinMode(t3, INPUT); pinMode(t4, INPUT); pinMode(t5, INPUT); pinMode(t6, INPUT); pinMode(t7, INPUT); pinMode(t8, INPUT); delay( 3000 ); // power-up safety delay FastLED.addLeds(leds, NUM_LEDS).setCorrection( TypicalLEDStrip ); FastLED.setBrightness( BRIGHTNESS ); currentPalette = RainbowColors_p; //thanks for the cute rainbow currentBlending = BLEND; } void loop() { zeitreise(); istinput(); rechneplasma(); voladjust(); if (analogRead(sound) > 10) {soundi = analogRead(sound)-zeitc;} if (analogRead(soundb) > 10) {soundi2 = analogRead(sound)-zeitc;} fillsoundcach(); rechnepeak(); static uint8_t startIndex = 0; startIndex = startIndex + setled/1.5; /* motion speed */ //SetupTotallyRandomPalette(); colorindex2 = startIndex +20; FillLEDsFromPaletteColors( startIndex); FastLED.show(); FastLED.delay(1000 / UPDATES_PER_SECOND); } void istinput(void){ if (zeit1 >=1) { if (digitalRead(t1) == HIGH && onpress[0] ==0) { onpress[0] =1; } //minisound if (onpress[0] == 1) { onpress[1]++;} if (onpress[1] == 2) { taster++; if (taster >128) {taster=0;} digitalWrite(pruf, HIGH );} //tudinge if (onpress[1] >= 10) { onpress[1] =0; onpress[0]=0; digitalWrite(pruf, LOW );} /* if (digitalRead(t2) == HIGH && onpress[2] ==0) { onpress[2] =1; } if (onpress[2] == 1) { onpress[3]++;} if (onpress[3] == 2) { if (soundminimum <4000) {soundminimum+=1;} digitalWrite(pruf, HIGH );} //tudinge if (onpress[3] >= 10) { onpress[3] =0; onpress[2]=0; digitalWrite(pruf, LOW );} if (digitalRead(t3) == HIGH && onpress[4] ==0) { onpress[4] =1; } if (onpress[4] == 1) { onpress[5]++;} if (onpress[5] == 2) { teiler--; digitalWrite(pruf, HIGH );} //tudinge if (onpress[5] >= 10) { onpress[5] =0; onpress[4]=0; digitalWrite(pruf, LOW );} if (digitalRead(t4) == HIGH && onpress[6] ==0) { onpress[6] =1; } if (onpress[6] == 1) { onpress[7]++;} if (onpress[7] == 2) { teiler++; digitalWrite(pruf, HIGH );} //tudinge if (onpress[7] >= 10) { onpress[7] =0; onpress[6]=0; digitalWrite(pruf, LOW );} if (digitalRead(t5) == HIGH && onpress[8] ==0) { onpress[8] =1; } if (onpress[8] == 1) { onpress[9]++;} if (onpress[9] == 2) { zeitb--; digitalWrite(pruf, HIGH );} //tudinge if (onpress[9] >= 10) { onpress[9] =0; onpress[8]=0; digitalWrite(pruf, LOW );} if (digitalRead(t6) == HIGH && onpress[10] ==0) { onpress[10] =1; } if (onpress[10] == 1) { onpress[11]++;} if (onpress[11] == 2) { zeitb++; digitalWrite(pruf, HIGH );} //tudinge if (onpress[11] >= 10) { onpress[11] =0; onpress[10]=0; digitalWrite(pruf, LOW );} if (digitalRead(t7) == HIGH && onpress[12] ==0) { onpress[12] =1; } //zeitc -signal if (onpress[12] == 1) { onpress[13]++;} if (onpress[13] == 2) { zeitc-=4; digitalWrite(pruf, HIGH );} //tudinge if (onpress[13] >= 10) { onpress[13] =0; onpress[12]=0; digitalWrite(pruf, LOW );} if (digitalRead(t8) == HIGH && onpress[14] ==0) { onpress[14] =1; } if (onpress[14] == 1) { onpress[15]++;} if (onpress[15] == 2) {zeitc+=2; digitalWrite(pruf, HIGH );} //tudinge if (onpress[15] >= 10) { onpress[15] =0; onpress[14]=0; digitalWrite(pruf, LOW );} */ zeit1=0; }} void fillsoundcach(void){ for( int s = 0; s < barheight; s++) { soundi = analogRead(sound)-zeitc; soundi2 = analogRead(sound)-zeitc; zeita = ((soundi /teiler)) +zeitb; zeitr = ((soundi2 /teiler)) +zeitb; soundcachL[s]= zeita; soundcachR[s]=zeitr; /* if (soundcachL[s] < zeita && soundcachL[s] < (NUM_LEDS/2)) { soundcachL[s]-=10;} if (soundcachL[s]> zeita) {soundcachL[s]+=10;} if (soundcachR[s] < zeitr && soundcachR[s] < (NUM_LEDS/2)) {soundcachR[s]+=5;} if (soundcachR[s] > zeitr) {soundcachR[s]-=5;} */ }} void rechnepeak(void) { peakcach = peaklowL; peaklowL = peakhighL; peakhighL = peakcach ; for( int p = 0; p < barheight; p++) { if (peaklowL > soundcachL[p]) {peaklowL = soundcachL[p];} if (peakhighL < soundcachL[p]) {peakhighL = soundcachL[p];} } peakL = peakhighL - peaklowL; peakcach = peaklowR; peaklowR = peakhighR; peakhighR = peakcach; for( int p = 0; p < barheight; p++) { if (peaklowR > soundcachR[p]) {peaklowR = soundcachR[p];} if (peakhighR < soundcachR[p]) {peakhighR = soundcachR[p];} } peakR = peakhighR - peaklowR; if (peakL > peakslowL) {peakslowL++;} if (peakL < peakslowL) {peakslowL--;} if (peakR > peakslowR) {peakslowR++;} if (peakR < peakslowR) {peakslowR--;} if (zeit3 >1 && (peakslowL-verschiebL) >=10) {verschiebL++; zeit3=0;} if (zeit3 >1 && (peakslowL-verschiebL) <=10) {verschiebL--; zeit3=0;} } void zeitreise(void){ while ((millis()- maintime) >= 10) { zeit1++; zeit2++; ka++; zeit3++; maintime = millis(); } while ((micros()- allfcount) >= 15) { zeit4++; allfcount = micros(); } } void voladjust (void){ if (zeit2 >= 25 && setled <10) {zeitc--; zeit2 =0;} if (zeit2 >= 25 && setled >10) {zeitc++; zeit2=0;} } void rechneplasma(void){ zeita = ((soundi /teiler)) +zeitb; zeitr = ((soundi2 /teiler)) +zeitb; if (setled2 < zeita && setled2 < (NUM_LEDS/2)) {setled2++;} if (setled2 > zeita) {setled2--;} if (setled3 < zeitr && setled3 < (NUM_LEDS/2)) {setled3++;} if (setled3 > zeitr) {setled3--;} if (zeit4 >=1) { if (setled < zeita && setled < (NUM_LEDS/2)) {setled++;} if (setled > zeita) {setled--;} if (setled4 < zeitr && setled4 < (NUM_LEDS/2)) {setled4++;} if (setled4 > zeitr) {setled4--;} zeit4 =0;} } void FillLEDsFromPaletteColors( uint8_t colorIndex) { uint8_t brightness = 200; // uint8_t brightness = 117+ (ka*6); if (ka >24) {ka=0;} peakcounter++; if (peakcounter >=2) {peakcounter =0;} for( int i = 0; i < NUM_LEDS; i++) { switch (present) { case 1: barheight =20; if (i < setled) {leds[i] = ColorFromPalette( currentPalette, colorIndex, brightness, currentBlending);} if (i < setled4) {leds[(NUM_LEDS-i)-1] = ColorFromPalette( currentPalette, colorIndex, brightness, currentBlending);} if (i> setled && i< 20) { leds[i] = CRGB::Black; } if (i> setled4 && i< 20) { leds[(NUM_LEDS-i)-1] = CRGB::Black;} if ( i == (ka+1)| i == (ka-1) ) { leds[i] = CRGB::Black; leds[(NUM_LEDS-i)-1] = CRGB::Black;} if ( i == ka ) { leds[i] = CRGB::White; leds[(NUM_LEDS-i)-1] = CRGB::White;} if (i == (setled2 +3)) {leds[i] = ColorFromPalette( currentPalette, colorindex2, brightness, currentBlending);} if (i == (setled3 +3)) {leds[(NUM_LEDS-i)-1] = ColorFromPalette( currentPalette, colorindex2, brightness, currentBlending);} colorIndex += 1+(setled/3); colorindex2 += setled; break; case 2: barheight =511; leds[i] = ColorFromPalette( currentPalette, soundcachL[i], brightness, currentBlending); if (i >= 29) {leds[(NUM_LEDS-i)-1] = ColorFromPalette( currentPalette, soundcachR[(i-28)], brightness, currentBlending);} if (i >= 20 && i <=27){leds[i] = CRGB::Black;} break; case 3: leds[i] = CRGB::Black; if ( i <(peakslowL-verschiebL)) {leds[i] = CRGB::White; leds[(NUM_LEDS-i)-1] = CRGB::White;} break; }}} //programm by marderchen =^.^= /* MMMMMMMM MMMMMMMMEEEEEEEEEEEEEEEEEEEEEE OOOOOOOOO WWWWWWWW WWWWWWWW M:::::::M M:::::::ME::::::::::::::::::::E OO:::::::::OO W::::::W W::::::W M::::::::M M::::::::ME::::::::::::::::::::E OO:::::::::::::OO W::::::W W::::::W M:::::::::M M:::::::::MEE::::::EEEEEEEEE::::EO:::::::OOO:::::::OW::::::W W::::::W M::::::::::M M::::::::::M E:::::E EEEEEEO::::::O O::::::O W:::::W WWWWW W:::::W M:::::::::::M M:::::::::::M E:::::E O:::::O O:::::O W:::::W W:::::W W:::::W M:::::::M::::M M::::M:::::::M E::::::EEEEEEEEEE O:::::O O:::::O W:::::W W:::::::W W:::::W M::::::M M::::M M::::M M::::::M E:::::::::::::::E O:::::O O:::::O W:::::W W:::::::::W W:::::W M::::::M M::::M::::M M::::::M E:::::::::::::::E O:::::O O:::::O W:::::W W:::::W:::::W W:::::W M::::::M M:::::::M M::::::M E::::::EEEEEEEEEE O:::::O O:::::O W:::::W W:::::W W:::::W W:::::W M::::::M M:::::M M::::::M E:::::E O:::::O O:::::O W:::::W:::::W W:::::W:::::W M::::::M MMMMM M::::::M E:::::E EEEEEEO::::::O O::::::O W:::::::::W W:::::::::W M::::::M M::::::MEE::::::EEEEEEEE:::::EO:::::::OOO:::::::O W:::::::W W:::::::W M::::::M M::::::ME::::::::::::::::::::E OO:::::::::::::OO W:::::W W:::::W M::::::M M::::::ME::::::::::::::::::::E OO:::::::::OO W:::W W:::W MMMMMMMM MMMMMMMMEEEEEEEEEEEEEEEEEEEEEE OOOOOOOOO WWW WWW `..`... `...... `.. .. `........`....... `........`........ `.. `.. `.. `.. `.. `.. `.. `.. `.. `.. `.. `.. `.. `.. `.. `.. `.. `.. `.. `.. `...... `. `.. `...... `...... `.. `.. `.. `.. `.. `.. `.. `.. `.. `.. `.. `.. `.. `.. `.. `.. `.. `.. `.. `.. .. `.. `.. `..`........`........ */