Rainbow with 1 LED

Hello

How do I make the LED 76 run through an LED running light in various blue to violet colors again and again until the end of the program?

wie schaffe ich es das die led 76 ein led lauflicht in diversen blau bis violette immer wieder durchläuft bis zum schluss des programms?

#include <SoftwareSerial.h>
#include <DFRobotDFPlayerMini.h>
SoftwareSerial DFPlayerSoftwareSerial(10,11);                                   //RX,TX Port
DFRobotDFPlayerMini mp3Player;                                                  //Name des Players
int Ordner =1;                                                                  //Nummer des Ordners
int switchState=0;                                                              // Schalter Speicher
#include <Adafruit_NeoPixel.h>
#define PIN 5                                                                   //pin Led Daten Anschluss
#define NUMPIXELS 91                                                           //Anzahl LED 
Adafruit_NeoPixel pixels = Adafruit_NeoPixel (NUMPIXELS,PIN,NEO_GRB+NEO_KHZ800);



void setup() {
  
  DFPlayerSoftwareSerial.begin(9600);                                           
  Serial.begin(9600);
  mp3Player.begin(DFPlayerSoftwareSerial);
  Serial.println(mp3Player.readFileCounts());
  mp3Player.volume(10);
  pixels.begin();
  pixels.show();
  pinMode (2,INPUT);                                                             //Schalter Pin Eingang donnersteuerung und saund                                                                //led befehl ausführen
  pinMode (3,INPUT);                                                            //Schalter pin eingang skorpion licht und saund
  pinMode (4,INPUT);                                                            //schalter pin eingang tageslicht und saund
  pinMode (7,OUTPUT);                                                           //nachtlicht led skorpion
  pinMode (8,OUTPUT);                                                           //nachtlicht led skorpion
}   

void loop() {          





  switchState=digitalRead(2);                                     //Taste Regen

  if (switchState==HIGH){

 mp3Player.begin(DFPlayerSoftwareSerial);
  mp3Player.volume(25);                                           //lautstärke max 30
  mp3Player.EQ(DFPLAYER_EQ_NORMAL);                               // mp3 equalizer
  mp3Player.play(1);  





                for (byte i=0; i<15;i+=1){
  pixels.setPixelColor(19,pixels.Color(0,0,i));
  pixels.setPixelColor(23,pixels.Color(0,0,i));
  pixels.setPixelColor(76,pixels.Color(0,0,i));
  pixels.setPixelColor(62,pixels.Color(0,0,i));
  pixels.show(),
  delay(100);
     }
     delay(4000);

       pixels.clear();
  pixels.show();
  mp3Player.stop();
  delay(500);
  }
}

Hello

Explain what you want to do exactly, it's not clear

No idea: you talk German and English (I am fine with both, but anybody else?).
My guess:
if you can set any color with your functions, I would assume all is RGB code for the color.
Just increment the right part (R or G or B) and sweep it to make a fading blue effect.

I think you try to do it already.
Where is the problem?

When you do pixels.clear() - does it mean you turn all LEDs off, it sets to default color (or dark)?
And later you change just one component of RDB?
This might look like just a single color, the wrong color.
Just check if you "modify" the RGB color, and which one (when not all). Maybe your code falls back to default color (or dark) and you set just one channel of RGB and the color is "wrong".

That will give you 15 shades of very dark blue.

To get "blue to violet" colors you probably want something like: Color(0,0,0) -> Color(0,0,255) -> Color(128,0,255)

To do it 'over and over' you would use a millis() timer to time each step and use global or static variables to keep track of where in the sequence you are.

ok, sorry for the complicated report. i would like a led (no. 76) to change color automatically in a rainbow. But I can only let all the colors run. how can I do that, but only the colors blue to violet and blue to violet again etc. run through.

if I set the values ​​myself, there are unclean transitions.

I want to achieve that, but only with various blue and purple...

Instead of Color, you might want to have a look at ColorHSV to set the hue directly instead of calculating it in rgb space.

ok, but i would like to let the colors run like in the link video, and not define them with values...

You already have a loop that increments a value to go through 16 shades of blue. Likewise, you can go through all the hue values as follows.

for (uint16_t i = 0; i < 65535; i++) {
  pixels.setPixelColor(19, pixels.ColorHSV(i));
  // ...
}

See the following link for more information.

1 Like

Hello, I tried this but I'm probably too stupid to get it...

when I enter this and press the switch, the led is red all the time...

#include <SoftwareSerial.h>
#include <DFRobotDFPlayerMini.h>
SoftwareSerial DFPlayerSoftwareSerial(10,11);                                   //RX,TX Port
DFRobotDFPlayerMini mp3Player;                                                  //Name des Players
int Ordner =1;                                                                  //Nummer des Ordners
int switchState=0;                                                              // Schalter Speicher
#include <Adafruit_NeoPixel.h>
#define PIN 5                                                                   //pin Led Daten Anschluss
#define NUMPIXELS 91                                                           //Anzahl LED 
Adafruit_NeoPixel pixels = Adafruit_NeoPixel (NUMPIXELS,PIN,NEO_GRB+NEO_KHZ800);



void setup() {
  
  DFPlayerSoftwareSerial.begin(9600);                                           
  Serial.begin(9600);
  mp3Player.begin(DFPlayerSoftwareSerial);
  Serial.println(mp3Player.readFileCounts());
  mp3Player.volume(10);
  pixels.begin();
  pixels.show();
  pinMode (2,INPUT);                                                             //Schalter Pin Eingang donnersteuerung und saund                                                                //led befehl ausführen
  pinMode (3,INPUT);                                                            //Schalter pin eingang skorpion licht und saund
  pinMode (4,INPUT);                                                            //schalter pin eingang tageslicht und saund
  pinMode (7,OUTPUT);                                                           //nachtlicht led skorpion
  pinMode (8,OUTPUT);                                                           //nachtlicht led skorpion
}   

void loop() {          





                                                                  //0-18 kleiner blitz-    19-28 ws2812-   29-58 grosser blitz-     59-78 ws2812    79-91 mond
  switchState=digitalRead(2);                                     //Taste Regen
  if (switchState==HIGH){

    for (uint16_t i=0;i<65535;i++){
      pixels.setPixelColor(59,pixels.ColorHSV(i));
      pixels.setPixelColor(64,pixels.ColorHSV(i));
      pixels.show();
      delay(5000);
      pixels.clear();
    }
  }
  }


You will have to wait a very long time to see any change in colour.

What happens when you reduce this delay to 100ms or so?

[edit]

Oh, and perhaps try to simplify your sketch further by getting rid of the button press detection for now.

1 Like

I adjusted this to 100 and it still stays red. what am I doing wrong???

I managed it after several attempts... thanks for the cool hsv tip...

how can I run this loop over and over again until I finish it at the end?

 switchState=digitalRead(2);                                     //Taste Regen
  if (switchState==HIGH){

    for (uint16_t i=36768;i<45613;i++){
      pixels.setPixelColor(59,pixels.ColorHSV(i));
      pixels.setPixelColor(64,pixels.ColorHSV(i));
      pixels.show();
      delay(1);
      pixels.clear();

Assuming you have a button connected to pin 2 and +5V and you have a pull down resistor connected to pin 2, as your setup suggests, the following should run the for-loop until you press the button.

while (digitalRead(2)) {
  // Your `for`-loop here.
}

If you do not have a pull down resistor connected to pin 2, then I would suggest to enable the internal pull-up resistor,

void setup() {
  pinMode(2, INPUT_PULLUP);
  // ...
}

connect the button to pin 2 and ground, and use the following test to see whether the button was pressed.

while (not digitalRead(2)) {
  // Your `for`-loop here.
}

If you put all of this in setup, then it will run until the button is pressed and then never again (at least not until a reboot).

1 Like

Many thanks for the super detailed help

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.