URL: https://www.overclockers.at/coding-stuff/led-mit-mic-steuern-code-issue_256220/page_3 - zur Vollversion wechseln!
wenn du zeile 70 durch
ersetzt sollte der strip weiss leuchten. tut er das?Code: C++led_values[j] = 255.0;
wenns dann zu hell ist, das 1.0 durch einen größeren wert ersetzen.Code: C++led_values[j] = constrain(led_values[j] / 1.0 * 255.0, 0.0, 255.0);
nope tut sich nichts.
Code:#include <FastLED.h> #include "arduinoFFT.h" #define LED_PIN 3 #define NUM_LEDS 60 #define BRIGHTNESS 64 #define LED_TYPE WS2811 #define COLOR_ORDER GRB CRGB leds[NUM_LEDS]; #define NUM_SAMPLES 256 #define UPDATES_PER_SECOND 100 arduinoFFT FFT = arduinoFFT(); double real[NUM_SAMPLES]; double imag[NUM_SAMPLES]; uint16_t i = 0; uint32_t us_last = 0; void setup() { // put your setup code here, to run once: delay( 3000 ); // power-up safety delay FastLED.addLeds<LED_TYPE, LED_PIN, COLOR_ORDER>(leds, NUM_LEDS).setCorrection( TypicalLEDStrip ); FastLED.setBrightness( BRIGHTNESS ); pinMode(A0, INPUT); Serial.begin(9600); memset(real, NUM_SAMPLES, 0); memset(imag, NUM_SAMPLES, 0); } void loop() { // put your main code here, to run repeatedly: //samples aufnehmen if (micros() - us_last >= 100) { us_last = micros(); real[i] = static_cast<double>(analogRead(A0)); imag[i] = 0; i++; } //wenn genug samples gesammelt wurden if (i == NUM_SAMPLES) { i = 0; //FFT auf das array FFT.Windowing(real, NUM_SAMPLES, FFT_WIN_TYP_HAMMING, FFT_FORWARD); FFT.Compute(real, imag, NUM_SAMPLES, FFT_FORWARD); FFT.ComplexToMagnitude(real, imag, NUM_SAMPLES); //256 samples, davon die ersten 128 nutzbar //sample 0 nicht benutzen (=DC) //60 leds = 2x 30 LEDS // --> samples 4 - 123 (=120 samples) / 30 = 4 samples / LED double led_values[30]; for (uint8_t j = 0; j < 30; j++) { led_values[j] = 0.0; for (uint8_t k = 0; k < 4; k++) led_values[j] += real[j * 4 + k + 4]; } //skalieren auf 0...255 und rausschreiben an die leds for (uint8_t j = 0; j < 30; j++) { led_values[j] = led_values[j] / 4095.0 * 255.0; //raussschreiben an die leds leds[30 + j] = CRGB(static_cast<uint32_t>(led_values[j]), static_cast<uint32_t>(led_values[j]), static_cast<uint32_t>(led_values[j])); leds[29 - j] = CRGB(static_cast<uint32_t>(led_values[j]), static_cast<uint32_t>(led_values[j]), static_cast<uint32_t>(led_values[j])); } FastLED.show(); } }
in der loop() ist das irgendwie klar, ja *facepalm*Code:FastLED.show();
Holy Cow it's ALIIIIIIIIIIIIIVVVVE!
Dickes Merci noch mal an dieser Stelle für die Geduld!
kein problem, viel spass damit
Hab ich bei diesem code jetzt eigentlich die Möglichkeit effekte aus dem 2ten code zu integrieren?
Wenn ich den reinlade wo "// put your main code here, to run repeatedly:" steht gehts natürlich nicht.
An welcher Stelle ist der aktuelle code für die animation und das aussehen der selbigen verantwortlich?
Kann das irgendwie nicht rauslesen..
Sind die 255 verantwortlich für den Farbwert weiß?
der code
(genau genommen: zeilen 6+7) setzt die farben der leds, symmetrisch um die mitte des streifens. die R, G , und B werte ist jeweils gleich, dadurch ergibt sich eine weisse farbe mit unterschiedlichen helligkeiten.Code://skalieren auf 0...255 und rausschreiben an die leds for (uint8_t j = 0; j < 30; j++) { led_values[j] = led_values[j] / 4095.0 * 255.0; //raussschreiben an die leds leds[30 + j] = CRGB(static_cast<uint32_t>(led_values[j]), static_cast<uint32_t>(led_values[j]), static_cast<uint32_t>(led_values[j])); leds[29 - j] = CRGB(static_cast<uint32_t>(led_values[j]), static_cast<uint32_t>(led_values[j]), static_cast<uint32_t>(led_values[j])); }
Hmm.. Hab versucht ColorFromPalette zu integrieren.
Er hat dann jedes mal nach ner weiter Definition geschriehen und jetzt stehe ich bei der declaration der CRGB leds an.
Code:#include <FastLED.h> #include "arduinoFFT.h" #define LED_PIN 3 #define NUM_LEDS 60 #define BRIGHTNESS 64 #define LED_TYPE WS2811 #define COLOR_ORDER GRB CRGB leds[NUM_LEDS]; #define NUM_SAMPLES 256 #define UPDATES_PER_SECOND 100 arduinoFFT FFT = arduinoFFT(); double real[NUM_SAMPLES]; double imag[NUM_SAMPLES]; uint16_t i = 0; uint32_t us_last = 0; //Code V01 CRGBPalette16 currentPalette; TBlendType currentBlending; void setup() { // put your setup code here, to run once: delay( 3000 ); // power-up safety delay FastLED.addLeds<LED_TYPE, LED_PIN, COLOR_ORDER>(leds, NUM_LEDS).setCorrection( TypicalLEDStrip ); FastLED.setBrightness( BRIGHTNESS ); pinMode(A0, INPUT); Serial.begin(9600); memset(real, NUM_SAMPLES, 0); memset(imag, NUM_SAMPLES, 0); //code V01 currentPalette = RainbowColors_p; currentBlending = LINEARBLEND; } void loop() { // put your main code here, to run repeatedly: //samples aufnehmen if (micros() - us_last >= 100) { us_last = micros(); real[i] = static_cast<double>(analogRead(A0)); imag[i] = 0; i++; } } void FillLEDsFromPaletteColors( uint8_t colorIndex) { uint8_t brightness = 255; for( int i = 0; i < NUM_LEDS; i++) { leds[i] = ColorFromPalette( currentPalette, colorIndex, brightness, currentBlending); colorIndex += 3; } //wenn genug samples gesammelt wurden if (i == NUM_SAMPLES) { i = 0; //FFT auf das array FFT.Windowing(real, NUM_SAMPLES, FFT_WIN_TYP_HAMMING, FFT_FORWARD); FFT.Compute(real, imag, NUM_SAMPLES, FFT_FORWARD); FFT.ComplexToMagnitude(real, imag, NUM_SAMPLES); //256 samples, davon die ersten 128 nutzbar //sample 0 nicht benutzen (=DC) //60 leds = 2x 30 LEDS // --> samples 4 - 123 (=120 samples) / 30 = 4 samples / LED double led_values[30]; for (uint8_t j = 0; j < 30; j++) { led_values[j] = 0.0; for (uint8_t k = 0; k < 4; k++) led_values[j] += real[j * 4 + k + 4]; } //skalieren auf 0...255 und rausschreiben an die leds for (uint8_t j = 0; j < 30; j++) { led_values[j] = led_values[j] / 4095.0 * 255.0; //raussschreiben an die leds leds[30 + j] = ColorFromPalette( currentPalette, colorIndex, brightness, currentBlending); leds[29 - j] = ColorFromPalette( currentPalette, colorIndex, brightness, currentBlending); } FastLED.show(); } }
dein code kompiliert bei mir, wird so aber nicht funktionieren. ich würde vorschlagen den größten teil der loop unverändert stehen zu lassen, und die anderen effekte direkt vor das FastLED.show() zu schreiben:
Code:#include <FastLED.h> #include "arduinoFFT.h" #define LED_PIN 3 #define NUM_LEDS 60 #define BRIGHTNESS 64 #define LED_TYPE WS2811 #define COLOR_ORDER GRB CRGB leds[NUM_LEDS]; #define NUM_SAMPLES 256 #define UPDATES_PER_SECOND 100 arduinoFFT FFT = arduinoFFT(); double real[NUM_SAMPLES]; double imag[NUM_SAMPLES]; uint16_t i = 0; uint32_t us_last = 0; //Code V01 CRGBPalette16 currentPalette; TBlendType currentBlending; void setup() { // put your setup code here, to run once: delay( 3000 ); // power-up safety delay FastLED.addLeds<LED_TYPE, LED_PIN, COLOR_ORDER>(leds, NUM_LEDS).setCorrection( TypicalLEDStrip ); FastLED.setBrightness( BRIGHTNESS ); pinMode(A0, INPUT); Serial.begin(9600); memset(real, NUM_SAMPLES, 0); memset(imag, NUM_SAMPLES, 0); //code V01 currentPalette = RainbowColors_p; currentBlending = LINEARBLEND; } void loop() { // put your main code here, to run repeatedly: //samples aufnehmen if (micros() - us_last >= 100) { us_last = micros(); real[i] = static_cast<double>(analogRead(A0)); imag[i] = 0; i++; } //wenn genug samples gesammelt wurden if (i == NUM_SAMPLES) { i = 0; //FFT auf das array FFT.Windowing(real, NUM_SAMPLES, FFT_WIN_TYP_HAMMING, FFT_FORWARD); FFT.Compute(real, imag, NUM_SAMPLES, FFT_FORWARD); FFT.ComplexToMagnitude(real, imag, NUM_SAMPLES); //256 samples, davon die ersten 128 nutzbar //sample 0 nicht benutzen (=DC) //60 leds = 2x 30 LEDS // --> samples 4 - 123 (=120 samples) / 30 = 4 samples / LED double led_values[30]; for (uint8_t j = 0; j < 30; j++) { led_values[j] = 0.0; for (uint8_t k = 0; k < 4; k++) led_values[j] += real[j * 4 + k + 4]; } //skalieren auf 0...255 und rausschreiben an die leds for (uint8_t j = 0; j < 30; j++) { led_values[j] = led_values[j] / 4095.0 * 255.0; //raussschreiben an die leds leds[30 + j] = CRGB(static_cast<uint32_t>(led_values[j]), static_cast<uint32_t>(led_values[j]), static_cast<uint32_t>(led_values[j])); leds[29 - j] = CRGB(static_cast<uint32_t>(led_values[j]), static_cast<uint32_t>(led_values[j]), static_cast<uint32_t>(led_values[j])); } //code für andere farben / effekte kommen hier hin, z.B.: for( int j = 0; j < NUM_LEDS; j++) { leds[j] = ColorFromPalette( currentPalette, j, BRIGHTNESS, currentBlending); } FastLED.show(); } }
kannst du deine eigenen code einsetzen.Code://code für andere farben / effekte kommen hier hin, z.B.: for( int j = 0; j < NUM_LEDS; j++) { leds[j] = ColorFromPalette( currentPalette, j, BRIGHTNESS, currentBlending); }
S hat jetzt leider ein wenig gedauert, da ich das Datenkabel wieder anlöten musste
Hab das jetzt mal genau so hochgeladen und in der Zeile 88: j += 1; ergänzt.
jetzt wurden die beiden definitionen überlagert.
Das find ich eigentlich nicht schlecht, da immer ein grundlicht da ist, egal ob sich was tut oder nicht.
versuch mal das:
Code: C++#include <FastLED.h> #include "arduinoFFT.h" #define LED_PIN 3 #define NUM_LEDS 60 #define BRIGHTNESS 64 #define LED_TYPE WS2811 #define COLOR_ORDER GRB CRGB leds[NUM_LEDS]; #define NUM_SAMPLES 256 #define UPDATES_PER_SECOND 100 arduinoFFT FFT = arduinoFFT(); double real[NUM_SAMPLES]; double imag[NUM_SAMPLES]; uint16_t i = 0; uint32_t us_last = 0; //Code V01 CRGBPalette16 currentPalette; TBlendType currentBlending; void setup() { // put your setup code here, to run once: delay( 3000 ); // power-up safety delay FastLED.addLeds<LED_TYPE, LED_PIN, COLOR_ORDER>(leds, NUM_LEDS).setCorrection( TypicalLEDStrip ); FastLED.setBrightness( BRIGHTNESS ); pinMode(A0, INPUT); Serial.begin(9600); memset(real, NUM_SAMPLES, 0); memset(imag, NUM_SAMPLES, 0); //code V01 currentPalette = RainbowColors_p; currentBlending = LINEARBLEND; } void loop() { // put your main code here, to run repeatedly: //samples aufnehmen if (micros() - us_last >= 100) { us_last = micros(); real[i] = static_cast<double>(analogRead(A0)); imag[i] = 0; i++; } //wenn genug samples gesammelt wurden if (i == NUM_SAMPLES) { i = 0; //FFT auf das array FFT.Windowing(real, NUM_SAMPLES, FFT_WIN_TYP_HAMMING, FFT_FORWARD); FFT.Compute(real, imag, NUM_SAMPLES, FFT_FORWARD); FFT.ComplexToMagnitude(real, imag, NUM_SAMPLES); //256 samples, davon die ersten 128 nutzbar //sample 0 nicht benutzen (=DC) //60 leds = 2x 30 LEDS // --> samples 4 - 123 (=120 samples) / 30 = 4 samples / LED double led_values[30]; for (uint8_t j = 0; j < 30; j++) { led_values[j] = 0.0; for (uint8_t k = 0; k < 4; k++) led_values[j] += real[j * 4 + k + 4]; } //skalieren auf 0...255 und rausschreiben an die leds for (uint8_t j = 0; j < 30; j++) { led_values[j] = led_values[j] / 4095.0 * 255.0; //raussschreiben an die leds leds[30 + j] = ColorFromPalette( currentPalette, j, led_values[j], currentBlending); leds[29 - j] = ColorFromPalette( currentPalette, j, led_values[j], currentBlending); } FastLED.show(); } }
Die im FastLED hinterlegten effekte nimmt er trotzdem nicht.
Aber das Microfon reagiert dafür ausgezeichnet!
welche effekte meinst du? in meinem letzten code habe ich nur die farbe weiss gegen die RainbowColors_p palette ausgetauscht (siehe zeilen 40, 81, 82) aber vielleicht ist die schrittweite zu gering. ersetz mal zeilen 81 + 82 durch
das sollte buntere farben ergeben.Code:leds[30 + j] = ColorFromPalette( currentPalette, j * 4, led_values[j], currentBlending); leds[29 - j] = ColorFromPalette( currentPalette, j * 4, led_values[j], currentBlending);
sollte einen laufenden effekt erzeugen.Code:#include <FastLED.h> #include "arduinoFFT.h" #define LED_PIN 3 #define NUM_LEDS 60 #define BRIGHTNESS 64 #define LED_TYPE WS2811 #define COLOR_ORDER GRB CRGB leds[NUM_LEDS]; #define NUM_SAMPLES 256 #define UPDATES_PER_SECOND 100 arduinoFFT FFT = arduinoFFT(); double real[NUM_SAMPLES]; double imag[NUM_SAMPLES]; uint16_t i = 0; uint32_t us_last = 0; //Code V01 CRGBPalette16 currentPalette; TBlendType currentBlending; void setup() { // put your setup code here, to run once: delay( 3000 ); // power-up safety delay FastLED.addLeds<LED_TYPE, LED_PIN, COLOR_ORDER>(leds, NUM_LEDS).setCorrection( TypicalLEDStrip ); FastLED.setBrightness( BRIGHTNESS ); pinMode(A0, INPUT); Serial.begin(9600); memset(real, NUM_SAMPLES, 0); memset(imag, NUM_SAMPLES, 0); //code V01 currentPalette = RainbowColors_p; currentBlending = LINEARBLEND; } void loop() { // put your main code here, to run repeatedly: //samples aufnehmen if (micros() - us_last >= 100) { us_last = micros(); real[i] = static_cast<double>(analogRead(A0)); imag[i] = 0; i++; } //wenn genug samples gesammelt wurden if (i == NUM_SAMPLES) { i = 0; //FFT auf das array FFT.Windowing(real, NUM_SAMPLES, FFT_WIN_TYP_HAMMING, FFT_FORWARD); FFT.Compute(real, imag, NUM_SAMPLES, FFT_FORWARD); FFT.ComplexToMagnitude(real, imag, NUM_SAMPLES); //256 samples, davon die ersten 128 nutzbar //sample 0 nicht benutzen (=DC) //60 leds = 2x 30 LEDS // --> samples 4 - 123 (=120 samples) / 30 = 4 samples / LED double led_values[30]; for (uint8_t j = 0; j < 30; j++) { led_values[j] = 0.0; for (uint8_t k = 0; k < 4; k++) led_values[j] += real[j * 4 + k + 4]; } uint8_t start_index = static_cast<uint8_t>((millis() / 100) & 0xFF); //skalieren auf 0...255 und rausschreiben an die leds for (uint8_t j = 0; j < 30; j++) { led_values[j] = led_values[j] / 4095.0 * 255.0; //raussschreiben an die leds leds[30 + j] = ColorFromPalette( currentPalette, j + start_index, led_values[j], currentBlending); leds[29 - j] = ColorFromPalette( currentPalette, j + start_index, led_values[j], currentBlending); } FastLED.show(); } }
Oh my gosh! Das sieht jetzt ultimativ nice aus
hat jetzt alle "animationen" gestartet.Code:uint8_t start_index = static_cast<uint8_t>((millis() / 100) & 0xFF);
Code:leds[30 + j] = ColorFromPalette( currentPalette, j * 5 + start_index, BRIGHTNESS, currentBlending); leds[29 - j] = ColorFromPalette( currentPalette, j * 5 + start_index, BRIGHTNESS, currentBlending);;
probier mal das:Zitat aus einem Post von slateSCGibt es ne Möglichkeit die Richtung der Animation umzukehren, sodass sie sich nach außen ausbreitet und nicht nach innen?
Code: C++leds[j] = ColorFromPalette( currentPalette, j * 5 + start_index, BRIGHTNESS, currentBlending); leds[59 - j] = ColorFromPalette( currentPalette, j * 5 + start_index, BRIGHTNESS, currentBlending);;
overclockers.at v4.thecommunity
© all rights reserved by overclockers.at 2000-2025