Tut mir Leid aber leider klappt es nicht mit nächsten Effekt. Ich habe mir gedacht dass ichbes verstanden habe.
Neopixel: 2 Streifen LEDs, unterschiedlichen LEDs anzahl
-
-
OKEY ich glaube ich habe es verstanden.
If ist immer von loop gefolt.
Die pattern aber immer ganz ganz am ende.
-
Hallo Dino,
ich glaube, jetzt ist alles klar. Du hast den neuen Effekt pride() an die richtige Stelle kopiert. Dieser muss tatsächlich am Ende der Datei stehen.
Der Aufruf muss aber in loop() erfolgen.
muss also etwa in Zeile 120 hinzugefügt werden und nicht unten bei pride().
Hier nochmals der ganze, jetzt hoffentlich funktionierende Code:
C- #include <Arduino.h>
- #include <Wire.h>
- #include <SoftwareSerial.h>
- #include <FastLED.h>
- char val;
- #define FASTLED_ALLOW_INTERRUPTS 0
- #define t1 20
- #define NUM_LEDS 18
- #define LED_TYPE WS2812B
- #define COLOR_ORDER GRB
- #define MAX_POWER_MILLIAMPS 500
- CRGB leds[NUM_LEDS];
- uint8_t hue = 0;
- uint8_t patternCounter = 0;
- FASTLED_USING_NAMESPACE
- void setup() {
- pinMode(6, OUTPUT);
- Serial.begin(9600);
- FastLED.addLeds<WS2812B, 6, GRB>(leds, NUM_LEDS).setCorrection( TypicalLEDStrip );
- FastLED.addLeds<WS2812B, 5, GRB>(leds, NUM_LEDS).setCorrection( TypicalLEDStrip );
- FastLED.setBrightness(50);
- FastLED.setMaxPowerInVoltsAndMilliamps( 5, MAX_POWER_MILLIAMPS);
- }
- void fadeall() {
- for (int i = 0; i < NUM_LEDS; i++) {
- leds[i].nscale8(250);
- }
- }
- void loop() {
- if (Serial.available()) {
- val = Serial.read();
- Serial.println(val);
- }
- if (val == '1') { // Slow rainbow
- for (int i = 0; i < NUM_LEDS; i++)
- {
- leds[i] = CHSV(hue + (i * 10), 255, 255);
- }
- EVERY_N_MILLISECONDS(30)
- {
- hue++;
- }
- FastLED.show();
- }
- if (val == '2') { //movingDots
- uint16_t posBeat = beatsin16(30, 0, NUM_LEDS - 1, 0, 0);
- uint16_t posBeat2 = beatsin16(60, 0, NUM_LEDS - 1, 0, 0);
- uint16_t posBeat3 = beatsin16(30, 0, NUM_LEDS - 1, 0, 32767);
- uint16_t posBeat4 = beatsin16(60, 0, NUM_LEDS - 1, 0, 32767);
- // Wave for LED color
- uint8_t colBeat = beatsin8(45, 0, 255, 0, 0);
- leds[(posBeat + posBeat2) / 2] = CHSV(colBeat, 255, 255);
- leds[(posBeat3 + posBeat4) / 2] = CHSV(colBeat, 255, 255);
- fadeToBlackBy(leds, NUM_LEDS, 10);
- FastLED.show();
- }
- if (val == '3') { // RainbowBeat
- uint16_t beatA = beatsin16(30, 0, 255);
- uint16_t beatB = beatsin16(20, 0, 255);
- fill_rainbow(leds, NUM_LEDS, (beatA + beatB) / 2, 8);
- FastLED.show();
- }
- if (val == '4') { //3 movingdots
- uint16_t sinBeat = beatsin16(30, 0, NUM_LEDS - 1, 0, 0);
- uint16_t sinBeat2 = beatsin16(30, 0, NUM_LEDS - 1, 0, 21845);
- uint16_t sinBeat3 = beatsin16(30, 0, NUM_LEDS - 1, 0, 43690);
- leds[sinBeat] = CRGB::Aqua;
- leds[sinBeat2] = CRGB::LawnGreen;
- leds[sinBeat3] = CRGB::Aqua;
- fadeToBlackBy(leds, NUM_LEDS, 10);
- FastLED.show();
- }
- if (val == '5') { // Rainbow left right
- static uint8_t hue = 0;
- Serial.print("x");
- for (int i = 0; i < NUM_LEDS; i++) {
- leds[i] = CHSV(hue++, 255, 255);
- FastLED.show();
- fadeall();
- delay(50);
- }
- Serial.print("x");
- for (int i = (NUM_LEDS) - 1; i >= 0; i--) {
- leds[i] = CHSV(hue++, 255, 255);
- FastLED.show();
- fadeall();
- delay(50);
- }
- }
- if (val == '6') { //Pacifica
- EVERY_N_MILLISECONDS( 20) {
- pacifica_loop();
- FastLED.show();
- }
- }
- if (val == '7') { // NEUE DAZUFÜGT //<= das muss hier stehen
- pride(); //
- FastLED.show();
- }
- }
- CRGBPalette16 pacifica_palette_1 =
- { 0x000507, 0x000409, 0x00030B, 0x00030D, 0x000210, 0x000212, 0x000114, 0x000117,
- 0x000019, 0x00001C, 0x000026, 0x000031, 0x00003B, 0x000046, 0x14554B, 0x28AA50
- };
- CRGBPalette16 pacifica_palette_2 =
- { 0x000507, 0x000409, 0x00030B, 0x00030D, 0x000210, 0x000212, 0x000114, 0x000117,
- 0x000019, 0x00001C, 0x000026, 0x000031, 0x00003B, 0x000046, 0x0C5F52, 0x19BE5F
- };
- CRGBPalette16 pacifica_palette_3 =
- { 0x000208, 0x00030E, 0x000514, 0x00061A, 0x000820, 0x000927, 0x000B2D, 0x000C33,
- 0x000E39, 0x001040, 0x001450, 0x001860, 0x001C70, 0x002080, 0x1040BF, 0x2060FF
- };
- void pacifica_loop()
- {
- // Increment the four "color index start" counters, one for each wave layer.
- // Each is incremented at a different speed, and the speeds vary over time.
- static uint16_t sCIStart1, sCIStart2, sCIStart3, sCIStart4;
- static uint32_t sLastms = 0;
- uint32_t ms = GET_MILLIS();
- uint32_t deltams = ms - sLastms;
- sLastms = ms;
- uint16_t speedfactor1 = beatsin16(3, 179, 269);
- uint16_t speedfactor2 = beatsin16(4, 179, 269);
- uint32_t deltams1 = (deltams * speedfactor1) / 256;
- uint32_t deltams2 = (deltams * speedfactor2) / 256;
- uint32_t deltams21 = (deltams1 + deltams2) / 2;
- sCIStart1 += (deltams1 * beatsin88(1011, 10, 13));
- sCIStart2 -= (deltams21 * beatsin88(777, 8, 11));
- sCIStart3 -= (deltams1 * beatsin88(501, 5, 7));
- sCIStart4 -= (deltams2 * beatsin88(257, 4, 6));
- // Clear out the LED array to a dim background blue-green
- fill_solid( leds, NUM_LEDS, CRGB( 2, 6, 10));
- // Render each of four layers, with different scales and speeds, that vary over time
- pacifica_one_layer( pacifica_palette_1, sCIStart1, beatsin16( 3, 11 * 256, 14 * 256), beatsin8( 10, 70, 130), 0 - beat16( 301) );
- pacifica_one_layer( pacifica_palette_2, sCIStart2, beatsin16( 4, 6 * 256, 9 * 256), beatsin8( 17, 40, 80), beat16( 401) );
- pacifica_one_layer( pacifica_palette_3, sCIStart3, 6 * 256, beatsin8( 9, 10, 38), 0 - beat16(503));
- pacifica_one_layer( pacifica_palette_3, sCIStart4, 5 * 256, beatsin8( 8, 10, 28), beat16(601));
- // Add brighter 'whitecaps' where the waves lines up more
- pacifica_add_whitecaps();
- // Deepen the blues and greens a bit
- pacifica_deepen_colors();
- }
- // Add one layer of waves into the led array
- void pacifica_one_layer( CRGBPalette16& p, uint16_t cistart, uint16_t wavescale, uint8_t bri, uint16_t ioff)
- {
- uint16_t ci = cistart;
- uint16_t waveangle = ioff;
- uint16_t wavescale_half = (wavescale / 2) + 20;
- for ( uint16_t i = 0; i < NUM_LEDS; i++) {
- waveangle += 250;
- uint16_t s16 = sin16( waveangle ) + 32768;
- uint16_t cs = scale16( s16 , wavescale_half ) + wavescale_half;
- ci += cs;
- uint16_t sindex16 = sin16( ci) + 32768;
- uint8_t sindex8 = scale16( sindex16, 240);
- CRGB c = ColorFromPalette( p, sindex8, bri, LINEARBLEND);
- leds[i] += c;
- }
- }
- // Add extra 'white' to areas where the four layers of light have lined up brightly
- void pacifica_add_whitecaps()
- {
- uint8_t basethreshold = beatsin8( 9, 55, 65);
- uint8_t wave = beat8( 7 );
- for ( uint16_t i = 0; i < NUM_LEDS; i++) {
- uint8_t threshold = scale8( sin8( wave), 20) + basethreshold;
- wave += 7;
- uint8_t l = leds[i].getAverageLight();
- if ( l > threshold) {
- uint8_t overage = l - threshold;
- uint8_t overage2 = qadd8( overage, overage);
- leds[i] += CRGB( overage, overage2, qadd8( overage2, overage2));
- }
- }
- }
- // Deepen the blues and greens
- void pacifica_deepen_colors()
- {
- for ( uint16_t i = 0; i < NUM_LEDS; i++) {
- leds[i].blue = scale8( leds[i].blue, 145);
- leds[i].green = scale8( leds[i].green, 200);
- leds[i] |= CRGB( 2, 5, 7);
- }
- }
- //<= hier kein if (val == '7')
- // This function draws rainbows with an ever-changing,
- // widely-varying set of parameters.
- void pride()
- {
- static uint16_t sPseudotime = 0;
- static uint16_t sLastMillis = 0;
- static uint16_t sHue16 = 0;
- uint8_t sat8 = beatsin88( 87, 220, 250);
- uint8_t brightdepth = beatsin88( 341, 96, 224);
- uint16_t brightnessthetainc16 = beatsin88( 203, (25 * 256), (40 * 256));
- uint8_t msmultiplier = beatsin88(147, 23, 60);
- uint16_t hue16 = sHue16;//gHue * 256;
- uint16_t hueinc16 = beatsin88(113, 1, 3000);
- uint16_t ms = millis();
- uint16_t deltams = ms - sLastMillis ;
- sLastMillis = ms;
- sPseudotime += deltams * msmultiplier;
- sHue16 += deltams * beatsin88( 400, 5, 9);
- uint16_t brightnesstheta16 = sPseudotime;
- for ( uint16_t i = 0 ; i < NUM_LEDS; i++) {
- hue16 += hueinc16;
- uint8_t hue8 = hue16 / 256;
- brightnesstheta16 += brightnessthetainc16;
- uint16_t b16 = sin16( brightnesstheta16 ) + 32768;
- uint16_t bri16 = (uint32_t)((uint32_t)b16 * (uint32_t)b16) / 65536;
- uint8_t bri8 = (uint32_t)(((uint32_t)bri16) * brightdepth) / 65536;
- bri8 += (255 - brightdepth);
- CRGB newcolor = CHSV( hue8, sat8, bri8);
- uint16_t pixelnumber = i;
- pixelnumber = (NUM_LEDS - 1) - pixelnumber;
- nblend( leds[pixelnumber], newcolor, 64);
- }
- }
So sollte es funktionieren.
Gruss
René
-
Tut mir Leid ich kriege es nicht hin . Bitte um hilfe.
Was muss ich ändern dass es klappt?
Bitte markieren Sie mit "// <=" wo das fehler war.
wenn ich Pacifica Effekt 6 mit /* */ verstecke. es funktionniert. Alle Effekte aus den 6
-
C
- #include <Arduino.h>
- #include <Wire.h>
- #include <SoftwareSerial.h>
- #include <FastLED.h>
- char val;
- #define FASTLED_ALLOW_INTERRUPTS 0
- #define t1 20
- #define NUM_LEDS 18
- #define LED_TYPE WS2812B
- #define COLOR_ORDER GRB
- #define MAX_POWER_MILLIAMPS 500
- CRGB leds[NUM_LEDS];
- uint8_t hue = 0;
- uint8_t patternCounter = 0;
- FASTLED_USING_NAMESPACE
- void setup() {
- pinMode(6,OUTPUT);
- Serial.begin(9600);
- FastLED.addLeds<WS2812B, 6, GRB>(leds, NUM_LEDS).setCorrection( TypicalLEDStrip );
- FastLED.addLeds<WS2812B, 5, GRB>(leds, NUM_LEDS).setCorrection( TypicalLEDStrip );
- FastLED.setBrightness(50);
- FastLED.setMaxPowerInVoltsAndMilliamps( 5, MAX_POWER_MILLIAMPS);
- }
- void fadeall() { for(int i = 0; i < NUM_LEDS; i++) { leds[i].nscale8(250); } }
- void loop() {
- if(Serial.available()){
- val = Serial.read();
- Serial.println(val);
- }
- if(val=='1'){ // Slow rainbow
- for (int i = 0; i < NUM_LEDS; i++)
- {leds[i] = CHSV(hue + (i * 10), 255, 255);}
- EVERY_N_MILLISECONDS(30)
- {hue++;}
- FastLED.show();}
- if (val=='2'){ //movingDots
- uint16_t posBeat = beatsin16(30, 0, NUM_LEDS - 1, 0, 0);
- uint16_t posBeat2 = beatsin16(60, 0, NUM_LEDS - 1, 0, 0);
- uint16_t posBeat3 = beatsin16(30, 0, NUM_LEDS - 1, 0, 32767);
- uint16_t posBeat4 = beatsin16(60, 0, NUM_LEDS - 1, 0, 32767);
- // Wave for LED color
- uint8_t colBeat = beatsin8(45, 0, 255, 0, 0);
- leds[(posBeat + posBeat2) / 2] = CHSV(colBeat, 255, 255);
- leds[(posBeat3 + posBeat4) / 2] = CHSV(colBeat, 255, 255);
- fadeToBlackBy(leds, NUM_LEDS, 10);
- FastLED.show();}
- if (val=='3'){ // RainbowBeat
- uint16_t beatA = beatsin16(30, 0, 255);
- uint16_t beatB = beatsin16(20, 0, 255);
- fill_rainbow(leds, NUM_LEDS, (beatA+beatB)/2, 8);
- FastLED.show();
- }
- if (val=='4'){ //3 movingdots
- uint16_t sinBeat = beatsin16(30, 0, NUM_LEDS - 1, 0, 0);
- uint16_t sinBeat2 = beatsin16(30, 0, NUM_LEDS - 1, 0, 21845);
- uint16_t sinBeat3 = beatsin16(30, 0, NUM_LEDS - 1, 0, 43690);
- leds[sinBeat] = CRGB::Aqua;
- leds[sinBeat2] = CRGB::LawnGreen;
- leds[sinBeat3] = CRGB::Aqua;
- fadeToBlackBy(leds, NUM_LEDS, 10);
- FastLED.show();
- }
- if (val=='5') { // Rainbow left right
- static uint8_t hue = 0;
- Serial.print("x");
- for(int i = 0; i < NUM_LEDS; i++) {
- leds[i] = CHSV(hue++, 255, 255);
- FastLED.show();
- fadeall();
- delay(50);
- }
- Serial.print("x");
- for(int i = (NUM_LEDS)-1; i >= 0; i--) {
- leds[i] = CHSV(hue++, 255, 255);
- FastLED.show();
- fadeall();
- delay(50);}
- }
- if (val=='6') { //Pacifica
- EVERY_N_MILLISECONDS( 20) {
- pacifica_loop();
- FastLED.show();
- }
- }
- }
- CRGBPalette16 pacifica_palette_1 =
- { 0x000507, 0x000409, 0x00030B, 0x00030D, 0x000210, 0x000212, 0x000114, 0x000117,
- 0x000019, 0x00001C, 0x000026, 0x000031, 0x00003B, 0x000046, 0x14554B, 0x28AA50 };
- CRGBPalette16 pacifica_palette_2 =
- { 0x000507, 0x000409, 0x00030B, 0x00030D, 0x000210, 0x000212, 0x000114, 0x000117,
- 0x000019, 0x00001C, 0x000026, 0x000031, 0x00003B, 0x000046, 0x0C5F52, 0x19BE5F };
- CRGBPalette16 pacifica_palette_3 =
- { 0x000208, 0x00030E, 0x000514, 0x00061A, 0x000820, 0x000927, 0x000B2D, 0x000C33,
- 0x000E39, 0x001040, 0x001450, 0x001860, 0x001C70, 0x002080, 0x1040BF, 0x2060FF };
- void pacifica_loop()
- {
- // Increment the four "color index start" counters, one for each wave layer.
- // Each is incremented at a different speed, and the speeds vary over time.
- static uint16_t sCIStart1, sCIStart2, sCIStart3, sCIStart4;
- static uint32_t sLastms = 0;
- uint32_t ms = GET_MILLIS();
- uint32_t deltams = ms - sLastms;
- sLastms = ms;
- uint16_t speedfactor1 = beatsin16(3, 179, 269);
- uint16_t speedfactor2 = beatsin16(4, 179, 269);
- uint32_t deltams1 = (deltams * speedfactor1) / 256;
- uint32_t deltams2 = (deltams * speedfactor2) / 256;
- uint32_t deltams21 = (deltams1 + deltams2) / 2;
- sCIStart1 += (deltams1 * beatsin88(1011,10,13));
- sCIStart2 -= (deltams21 * beatsin88(777,8,11));
- sCIStart3 -= (deltams1 * beatsin88(501,5,7));
- sCIStart4 -= (deltams2 * beatsin88(257,4,6));
- // Clear out the LED array to a dim background blue-green
- fill_solid( leds, NUM_LEDS, CRGB( 2, 6, 10));
- // Render each of four layers, with different scales and speeds, that vary over time
- pacifica_one_layer( pacifica_palette_1, sCIStart1, beatsin16( 3, 11 * 256, 14 * 256), beatsin8( 10, 70, 130), 0-beat16( 301) );
- pacifica_one_layer( pacifica_palette_2, sCIStart2, beatsin16( 4, 6 * 256, 9 * 256), beatsin8( 17, 40, 80), beat16( 401) );
- pacifica_one_layer( pacifica_palette_3, sCIStart3, 6 * 256, beatsin8( 9, 10,38), 0-beat16(503));
- pacifica_one_layer( pacifica_palette_3, sCIStart4, 5 * 256, beatsin8( 8, 10,28), beat16(601));
- // Add brighter 'whitecaps' where the waves lines up more
- pacifica_add_whitecaps();
- // Deepen the blues and greens a bit
- pacifica_deepen_colors();
- }
- // Add one layer of waves into the led array
- void pacifica_one_layer( CRGBPalette16& p, uint16_t cistart, uint16_t wavescale, uint8_t bri, uint16_t ioff)
- {
- uint16_t ci = cistart;
- uint16_t waveangle = ioff;
- uint16_t wavescale_half = (wavescale / 2) + 20;
- for( uint16_t i = 0; i < NUM_LEDS; i++) {
- waveangle += 250;
- uint16_t s16 = sin16( waveangle ) + 32768;
- uint16_t cs = scale16( s16 , wavescale_half ) + wavescale_half;
- ci += cs;
- uint16_t sindex16 = sin16( ci) + 32768;
- uint8_t sindex8 = scale16( sindex16, 240);
- CRGB c = ColorFromPalette( p, sindex8, bri, LINEARBLEND);
- leds[i] += c;
- }
- }
- // Add extra 'white' to areas where the four layers of light have lined up brightly
- void pacifica_add_whitecaps()
- {
- uint8_t basethreshold = beatsin8( 9, 55, 65);
- uint8_t wave = beat8( 7 );
- for( uint16_t i = 0; i < NUM_LEDS; i++) {
- uint8_t threshold = scale8( sin8( wave), 20) + basethreshold;
- wave += 7;
- uint8_t l = leds[i].getAverageLight();
- if( l > threshold) {
- uint8_t overage = l - threshold;
- uint8_t overage2 = qadd8( overage, overage);
- leds[i] += CRGB( overage, overage2, qadd8( overage2, overage2));
- }
- }
- }
- // Deepen the blues and greens
- void pacifica_deepen_colors()
- {
- for( uint16_t i = 0; i < NUM_LEDS; i++) {
- leds[i].blue = scale8( leds[i].blue, 145);
- leds[i].green= scale8( leds[i].green, 200);
- leds[i] |= CRGB( 2, 5, 7);
- }
- }
- if (val=='7') { // NEUE DAZUFÜGT
- pride(); //
- FastLED.show();
- }
- // This function draws rainbows with an ever-changing,
- // widely-varying set of parameters.
- void pride()
- {
- static uint16_t sPseudotime = 0;
- static uint16_t sLastMillis = 0;
- static uint16_t sHue16 = 0;
- uint8_t sat8 = beatsin88( 87, 220, 250);
- uint8_t brightdepth = beatsin88( 341, 96, 224);
- uint16_t brightnessthetainc16 = beatsin88( 203, (25 * 256), (40 * 256));
- uint8_t msmultiplier = beatsin88(147, 23, 60);
- uint16_t hue16 = sHue16;//gHue * 256;
- uint16_t hueinc16 = beatsin88(113, 1, 3000);
- uint16_t ms = millis();
- uint16_t deltams = ms - sLastMillis ;
- sLastMillis = ms;
- sPseudotime += deltams * msmultiplier;
- sHue16 += deltams * beatsin88( 400, 5,9);
- uint16_t brightnesstheta16 = sPseudotime;
- for( uint16_t i = 0 ; i < NUM_LEDS; i++) {
- hue16 += hueinc16;
- uint8_t hue8 = hue16 / 256;
- brightnesstheta16 += brightnessthetainc16;
- uint16_t b16 = sin16( brightnesstheta16 ) + 32768;
- uint16_t bri16 = (uint32_t)((uint32_t)b16 * (uint32_t)b16) / 65536;
- uint8_t bri8 = (uint32_t)(((uint32_t)bri16) * brightdepth) / 65536;
- bri8 += (255 - brightdepth);
- CRGB newcolor = CHSV( hue8, sat8, bri8);
- uint16_t pixelnumber = i;
- pixelnumber = (NUM_LEDS-1) - pixelnumber;
- nblend( leds[pixelnumber], newcolor, 64);
- }
- }
-
Ganz unten vor dem letzten } bist du noch in der Funktion pacifica_deepen_colors(). Das macht eigentlich keinen Sinn.
Wenn ich das richtig sehe, ruft Effekt 6 die Funktion pacifica_loop() auf und diese Funktion ruft wiederum pacifica_deepen_colors() auf.
Die Effekte werden mit (if (val==...) aus loop() aufgerufen und springen dann eine Funktion an, die den Effekt ausführt. Wenn du einen eigenen vollständig neuen Effekt kreieren möchtest, müsstest du eine eigene Effektfunktion schreiben. Es wäre aber auch möglich, eine bestehende Effektfunktion mit anderen Parametern aufzurufen.
Dann könntest du loop() ergänzen:
-
ja ich habe mich verschrieben.
am schluss vor den letzten } ,Ich will andere Effekte weiter dazu schreiben. ich vermutte dass im Effekte 6 was faul ist. Aber glaub mir nicht
#15 am schluss verändert
-
2 Fragen:
Wo fügst du genau if (val==7) hinzu?
Sollte der Ausdruck nicht if (val=='7') lauten?
-
so bald ich if (val==7) {
}
dazu füge, kommt diese meldung:
NICHT_VER_NDERN:202:1: error: expected unqualified-id before 'if'
if (val==7)
^~
NICHT_VER_NDERN:205:1: error: expected declaration before '}' token
}
^
exit status 1
expected unqualified-id before 'if'
-
#include <Arduino.h>
#include <Wire.h>
#include <SoftwareSerial.h>
#include <FastLED.h>
//------Arduino Flop2K------//
char val;
#define FASTLED_ALLOW_INTERRUPTS 0
#define t1 20
#define NUM_LEDS 18
#define LED_TYPE WS2812B
#define COLOR_ORDER GRB
#define MAX_POWER_MILLIAMPS 500
CRGB leds[NUM_LEDS];
uint8_t hue = 0;
uint8_t patternCounter = 0;
FASTLED_USING_NAMESPACE
void setup() {
pinMode(6,OUTPUT);
Serial.begin(9600);
FastLED.addLeds<WS2812B, 6, GRB>(leds, NUM_LEDS).setCorrection( TypicalLEDStrip );
FastLED.addLeds<WS2812B, 5, GRB>(leds, NUM_LEDS).setCorrection( TypicalLEDStrip );
FastLED.setBrightness(50);
FastLED.setMaxPowerInVoltsAndMilliamps( 5, MAX_POWER_MILLIAMPS);
}
void fadeall() { for(int i = 0; i < NUM_LEDS; i++) { leds[i].nscale8(250); } }
void loop() {
if(Serial.available()){
val = Serial.read();
Serial.println(val);
}
if(val=='1'){ // Slow rainbow
for (int i = 0; i < NUM_LEDS; i++)
{leds[i] = CHSV(hue + (i * 10), 255, 255);}
EVERY_N_MILLISECONDS(30)
{hue++;}
FastLED.show();}
if (val=='2'){ //movingDots
uint16_t posBeat = beatsin16(30, 0, NUM_LEDS - 1, 0, 0);
uint16_t posBeat2 = beatsin16(60, 0, NUM_LEDS - 1, 0, 0);
uint16_t posBeat3 = beatsin16(30, 0, NUM_LEDS - 1, 0, 32767);
uint16_t posBeat4 = beatsin16(60, 0, NUM_LEDS - 1, 0, 32767);
// Wave for LED color
uint8_t colBeat = beatsin8(45, 0, 255, 0, 0);
leds[(posBeat + posBeat2) / 2] = CHSV(colBeat, 255, 255);
leds[(posBeat3 + posBeat4) / 2] = CHSV(colBeat, 255, 255);
fadeToBlackBy(leds, NUM_LEDS, 10);
FastLED.show();}
if (val=='3'){ // RainbowBeat
uint16_t beatA = beatsin16(30, 0, 255);
uint16_t beatB = beatsin16(20, 0, 255);
fill_rainbow(leds, NUM_LEDS, (beatA+beatB)/2, 8);
FastLED.show();
}
if (val=='4'){ //3 movingdots
uint16_t sinBeat = beatsin16(30, 0, NUM_LEDS - 1, 0, 0);
uint16_t sinBeat2 = beatsin16(30, 0, NUM_LEDS - 1, 0, 21845);
uint16_t sinBeat3 = beatsin16(30, 0, NUM_LEDS - 1, 0, 43690);
leds[sinBeat] = CRGB::Aqua;
leds[sinBeat2] = CRGB::LawnGreen;
leds[sinBeat3] = CRGB::Aqua;
fadeToBlackBy(leds, NUM_LEDS, 10);
FastLED.show();
}
if (val=='5') { // Rainbow left right
static uint8_t hue = 0;
Serial.print("x");
for(int i = 0; i < NUM_LEDS; i++) {
leds[i] = CHSV(hue++, 255, 255);
FastLED.show();
fadeall();
delay(50);
}
Serial.print("x");
for(int i = (NUM_LEDS)-1; i >= 0; i--) {
leds[i] = CHSV(hue++, 255, 255);
FastLED.show();
fadeall();
delay(50);}
}
if (val=='6') { //Pacifica
EVERY_N_MILLISECONDS( 20) {
pacifica_loop();
FastLED.show();
}
}
}
CRGBPalette16 pacifica_palette_1 =
{ 0x000507, 0x000409, 0x00030B, 0x00030D, 0x000210, 0x000212, 0x000114, 0x000117,
0x000019, 0x00001C, 0x000026, 0x000031, 0x00003B, 0x000046, 0x14554B, 0x28AA50 };
CRGBPalette16 pacifica_palette_2 =
{ 0x000507, 0x000409, 0x00030B, 0x00030D, 0x000210, 0x000212, 0x000114, 0x000117,
0x000019, 0x00001C, 0x000026, 0x000031, 0x00003B, 0x000046, 0x0C5F52, 0x19BE5F };
CRGBPalette16 pacifica_palette_3 =
{ 0x000208, 0x00030E, 0x000514, 0x00061A, 0x000820, 0x000927, 0x000B2D, 0x000C33,
0x000E39, 0x001040, 0x001450, 0x001860, 0x001C70, 0x002080, 0x1040BF, 0x2060FF };
void pacifica_loop()
{
// Increment the four "color index start" counters, one for each wave layer.
// Each is incremented at a different speed, and the speeds vary over time.
static uint16_t sCIStart1, sCIStart2, sCIStart3, sCIStart4;
static uint32_t sLastms = 0;
uint32_t ms = GET_MILLIS();
uint32_t deltams = ms - sLastms;
sLastms = ms;
uint16_t speedfactor1 = beatsin16(3, 179, 269);
uint16_t speedfactor2 = beatsin16(4, 179, 269);
uint32_t deltams1 = (deltams * speedfactor1) / 256;
uint32_t deltams2 = (deltams * speedfactor2) / 256;
uint32_t deltams21 = (deltams1 + deltams2) / 2;
sCIStart1 += (deltams1 * beatsin88(1011,10,13));
sCIStart2 -= (deltams21 * beatsin88(777,8,11));
sCIStart3 -= (deltams1 * beatsin88(501,5,7));
sCIStart4 -= (deltams2 * beatsin88(257,4,6));
// Clear out the LED array to a dim background blue-green
fill_solid( leds, NUM_LEDS, CRGB( 2, 6, 10));
// Render each of four layers, with different scales and speeds, that vary over time
pacifica_one_layer( pacifica_palette_1, sCIStart1, beatsin16( 3, 11 * 256, 14 * 256), beatsin8( 10, 70, 130), 0-beat16( 301) );
pacifica_one_layer( pacifica_palette_2, sCIStart2, beatsin16( 4, 6 * 256, 9 * 256), beatsin8( 17, 40, 80), beat16( 401) );
pacifica_one_layer( pacifica_palette_3, sCIStart3, 6 * 256, beatsin8( 9, 10,38), 0-beat16(503));
pacifica_one_layer( pacifica_palette_3, sCIStart4, 5 * 256, beatsin8( 8, 10,28), beat16(601));
// Add brighter 'whitecaps' where the waves lines up more
pacifica_add_whitecaps();
// Deepen the blues and greens a bit
pacifica_deepen_colors();
}
// Add one layer of waves into the led array
void pacifica_one_layer( CRGBPalette16& p, uint16_t cistart, uint16_t wavescale, uint8_t bri, uint16_t ioff)
{
uint16_t ci = cistart;
uint16_t waveangle = ioff;
uint16_t wavescale_half = (wavescale / 2) + 20;
for( uint16_t i = 0; i < NUM_LEDS; i++) {
waveangle += 250;
uint16_t s16 = sin16( waveangle ) + 32768;
uint16_t cs = scale16( s16 , wavescale_half ) + wavescale_half;
ci += cs;
uint16_t sindex16 = sin16( ci) + 32768;
uint8_t sindex8 = scale16( sindex16, 240);
CRGB c = ColorFromPalette( p, sindex8, bri, LINEARBLEND);
leds[i] += c;
}
}
// Add extra 'white' to areas where the four layers of light have lined up brightly
void pacifica_add_whitecaps()
{
uint8_t basethreshold = beatsin8( 9, 55, 65);
uint8_t wave = beat8( 7 );
for( uint16_t i = 0; i < NUM_LEDS; i++) {
uint8_t threshold = scale8( sin8( wave), 20) + basethreshold;
wave += 7;
uint8_t l = leds[i].getAverageLight();
if( l > threshold) {
uint8_t overage = l - threshold;
uint8_t overage2 = qadd8( overage, overage);
leds[i] += CRGB( overage, overage2, qadd8( overage2, overage2));
}
}
}
// Deepen the blues and greens
void pacifica_deepen_colors()
{
for( uint16_t i = 0; i < NUM_LEDS; i++) {
leds[i].blue = scale8( leds[i].blue, 145);
leds[i].green= scale8( leds[i].green, 200);
leds[i] |= CRGB( 2, 5, 7);
}
if (val=='7') { // ich will hier Effekt FastLED/Pride 2015 dazu geben
}
-
Hallo Dino,
Habe ich jetzt etwas verpasst oder fehlt in deinem Post das Programm?
Gruss
René
-
Es sieht gut aus.
Ich habe mich für 2 strips mit 18 leds entschieden. Ich habe aus verschiede Effekte ein Programm geschrieben.
Via Bluetooth kann ich die Effekte umschalten von 1 bis 6. Aber so bald ich Effekt 7 dazufüge, ich kann es nicht mehr kompilieren.
Bitte um Hilfe
Ein "{" oder "}" ist irgendwo falsch, glaube ich.
-
Ah ok. Weil es sehr schwer ist das was ich vor habe. Ich habe mich umentschiedet. Ich werde 2 oder 3 Schleife mit jede 18 LEDs nehmen. Und auf jeden Attiny85 einen Effekt auf spielen. Auf den Nano ich werde so machen, mit Taste 1 er soll Attiny85 1 einschalten, mit der 2 Attiny85 2 und so weiter..... Attiny85 braucht 5v und 300mA. Der Nano kann 5v und max 500mA abgeben. Ich hoffe dass die Informationen richtig sind.
Die Frage ist ob es technisch klappen wird.
Ich bin auf Renés Antwort gespannt. -
Hallo Dino,
natürlich schalten sich die beiden LEDs Streifen nacheinander ein. Sie werden ja auch nacheinander angesteuert. Es wird eine FOR Schleife nach der anderen abgearbeitet.
Ich hatte Deine Frage so verstanden, dass Du nur einen Streifen ansteuern kannst. Bei deinem Beispielcode war das ja auch so.
Deshalb ging es erst einmal darum, zwei Objekte anzulegen, die eine unterschiedliche Anzahl von LEDs ansteuert. Aus Deiner Antwort schließe ich, dass das funktioniert hat.
Dann musst Du jetzt halt die Schleifen umprogrammieren (z.B. Verschachteln) um eine "Pseudo"-Gleichzeitigkeit zu erhalten.
-
Servus und sorry dass ich mich so lange nicht gemeldet habe.
Alles gute in neuen Jahr: Glück, Gesundheit und Erfolg, der Rest kommt von allein.
Kair, danke aber es klappt nicht. Da schalten sich erst die LEDs bei erste Steife dann die von der zweite.
René, harte Antwort aber erlich und direkt. Mag es.
Ich habe deine Video mit Attiny85 angesehen und ich habe eine Idee. Bitte sag mir ob es klappen kann.
Ich werde den gleiche LEDs Anzahl pro Steife verwenden. Die frage;
Kann ich einen Attiny85 mit einem Nano anspeisen/betreiben? Ich wollte 3 Attiny85s nehmen. Jeder wird einen effekt haben. Und ich werde die dann mit Knopfdruck umschalten. Jemals wird ein Attiny85 eingeschaltet.
Kann das klappen? Falls ja ich kann mein Projekt fertig stellen.
MfG Dino
-
Hallo Dino,
da hast du dir kein einfaches Problem ausgesucht. Der Arduino soll zwei Dinge zur gleichen Zeit erledigen und das auch noch mit verschiedenen Geschwindigkeiten. Darin ist er nicht sehr gut. Nicht, dass es nicht möglich ist. Aber das ist dann schon etwas fortgeschrittene Programmierung.
Ich kann jetzt auch keine fertige Lösung aus dem Hut zaubern. Falls ich noch zwei Neopixel - Streifen finde, dann kann ich versuchen eine Lösung zu finden. Wird aber einen Moment dauern, ich bin wieder einmal im Verzug mit dem nächsten Video.
Gruss
René
-
Ich weiß nicht ob es wirklich so klappt, aber das wäre mein erster Versuch das umzusetzen. Du brauchst 2 Pins zum Ansteuern.
Code- #include <Adafruit_NeoPixel.h>
- #define PIN_1 6
- #define PIN_2 7
- #define NUMPIXELS_1 47
- #define NUMPIXELS_2 20
- Adafruit_NeoPixel pixels_1(NUMPIXELS_1, PIN_1, NEO_GRB + NEO_KHZ800);
- Adafruit_NeoPixel pixels_2(NUMPIXELS_2, PIN_2, NEO_GRB + NEO_KHZ800);
- #define DELAYVAL 500
- void setup() {
- pixels_1.begin();
- pixels_2.begin();
- }
- void loop() {
- pixels_1.clear();
- pixels_2.clear();
- for(int i=0; i<NUMPIXELS_1; i++) {
- pixels.setPixelColor(i, pixels_1.Color(0, 150, 0));
- pixels_1.show();
- delay(DELAYVAL);
- }
- for(int i=0; i<NUMPIXELS_2; i++) {
- pixels_2.setPixelColor(i, pixels_2.Color(0, 150, 0));
- pixels_2.show();
- delay(DELAYVAL);
- }
- }
-
Code
- #include <Adafruit_NeoPixel.h>
- #define PIN 6
- #define NUMPIXELS 47
- Adafruit_NeoPixel pixels(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);
- #define DELAYVAL 500
- void setup() {
- pixels.begin();
- }
- void loop() {
- pixels.clear();
- for(int i=0; i<NUMPIXELS; i++) {
- pixels.setPixelColor(i, pixels.Color(0, 150, 0));
- pixels.show();
- delay(DELAYVAL);
- }
- }
-
Hallo Hans hallo René
Hans das weiiss ich. Die Beispiele von Adafruit und FastLed aufladen auch. ich habe ein Problem wenn man in die Materie angreifen muss.<br>Um erlich zu sein, ich habe mir die videos von Der Hobbyelektroniker bis Servo angeschaut.
René ich bin ein Null. Ich kann die zum leuchten bringen. Ich weiss nicht wie man mit 2 Streifen anfängt. Alle Versuche gehen falsch. Muss man die mit gleichem Data Kabel/PIN steuern oder braucht man einen 2. PIN?
Man empfehlt mir immer diese Seite aber es ist alles auf englisch.
https://github.com/FastLED/Fas…tiple-Controller-Examples
Ich bin nicht gut in englisch.
Ich wünsche mir ich kann es auf deutsch oder französisch finden.
Ich nehme hier ein Beispiele von Adafruit => simple. Ich habe den Sketch maximum zum üben reduziert Da sollten sich die LEDs eine nach einandere von 0 bis 47 ein/aus. Das ist nur für eine Streife.
Ahso ok, ich muss es in der nächste Nachricht schicken..... Was muss man hier machen dass es auf 2 Streifen parallel und unterschiedlichen Geschwindigkeiten läuft?
-
Hallo Dino,
was funktioniert schon? Hast du Probleme, die LEDs zum Leuchten zu bringen oder ist dein Problem das Abstimmen der beiden Geschwindigkeiten?
Gruss
René