Rainbow only on selected LEDs

Google translator
am currently in the process of building a domino clock with an ESp8266 and 63 LEDs.
A web server to set the LEDs is already available and works perfectly.
Now I would like to create a rainbow effect and that's where I get stuck.
They are WS2812B LEDs with Fastled.
I can get a rainbow effect on all LEDs at the same time.
Question:
How do I have to program it that only selected LEDs have a rainbow effect.

my code.

#include "FastLED.h"
#define NUM_LEDS 63
#define DATA_PIN 1
CRGB leds[NUM_LEDS];

int r = 100, g = 100, b = 0;
int BRIGHTNESS  = 200;

int hhone[] = {8};
int hhtwo[] = {4, 20};
int hhthree[] = {4, 8, 20};
int hhfour[] = {4, 6, 18, 20};
int hhfive[] = {4, 6, 8 , 18, 20};
int hhsix[] = {4, 5, 6, 18, 19, 20};
int hhseven[] = {12, 4, 5, 6, 18, 19, 20};
int hheight[] = {0, 2, 4, 8, 12, 14, 16, 20};
int hhnine[] = {0, 2, 16, 14 , 12, 4, 6, 18, 20};
int hhten[] = {0, 2, 4, 6, 8, 12, 14, 16, 18, 20};
int hheleven[] = {0, 1, 2, 4, 6, 8, 14, 15, 16, 18, 20};
int hhtwelve[] = {0, 1, 2, 4, 5, 6, 14, 15, 16, 18, 19, 20};
int *arrays[26] = {hhone, hhtwo, hhthree, hhfour, hhfive, hhsix, hhseven, hheight, hhnine, hhten, hheleven, hhtwelve, tenone, tentwo, tenthree, tenfour, tenfive, minone, mintwo, minthree, minfour, minfive, minsix, minseven, mineight, minnine};
FastLED.addLeds<WS2812B, DATA_PIN, RGB>(leds, NUM_LEDS);
setArray(mintwo, 2)
FastLED.show();

Google is normally my best friend, but nothing found
Of course I've already started a few attempts but can't get it.
I hope for help.

How do I have to program it that only selected LEDs have a rainbow effect.

You only set the LEDs you want to use and leave alone or set to off the LEDs you don’t want on.

When posting code post all of it. If you knew what bits of code were wrong you would be able to fix it. Most of the time when people post bits of code the error is in the bits they don’t post. Post code that will compile. Your code will not compile and tells us little of what you are doing.

Google is normally my best friend, but nothing found

You can not be serious. This comes up here at least every week.

Hello, split my code into several tabs and you can't attach a zip file.
I uploaded it to MediaFire and here is the link to the Domino Clock.

Domino-Clock

Sorry I don’t go off site for links. Too dangerous.
So post each tab as a .ino file as an attachment.

here is my complete project.
I would now like to have a button below at page3.h where you can see the clock (LEDs) in a rainbow.

Luu5.ino (9.83 KB)

eeprom.ino (282 Bytes)

farbe.ino (1.67 KB)

page1.h (2.68 KB)

page2.h (5.52 KB)

page3.h (3.13 KB)

server.ino (6.58 KB)

timer.ino (767 Bytes)

uhr.ino (5.65 KB)

A web server to set the LEDs is already available and works perfectly.

Are you sure?
You have two functions with the same name, and the first one is used recursively with no way to clime out of the recursion. Maybe this is being overridden by the second function of the same name. But what were you thinking here?

void setArray(int num, int s)
{
  if (num < 26 && num >= 0)
    setArray(arrays[num], s);
}

void setArray(int arry[], int s)
{
  for (int i = 0; i < s; i++)
  {
    leds[arry[i]].setRGB(g, r, b);
  }
}

How do I have to program it that only selected LEDs have a rainbow effect.

Well you already know how to limit the number of LEDs you change, as you have shown by:-

for (int i = 42; i < NUM_LEDS; i++)
      {
        leds[i] = CRGB::Black;
      }

That is what you do, you limit the LEDs that your rainbow effect operates on.

I would now like to have a button below at page3.h where you can see the clock (LEDs) in a rainbow.

That seems to be HTML code, I don't do that.
But if you want the numbers in the rainbow colours the change the g, r, b values in the second setArray function. Make them arrays and set each array to the different colours you want.

Your best bet going forward, before adding layers of complication is to write a sketch that just does what you want to do in the final program.

I do think you could improve your code structure. When you find yourself writing almost the same lines over and over, you need to use loops and an array and maybe two dimensional arrays.

You have two functions with the same name

I have improved that, there is a mistake like that.

have two pictures attached. the way the clock looks and where I would like to have a rainbow button.

It is 8.55 a.m. in the picture

I can manage that in HTML, but how I have to program it is the question (arrays? Rainbow).

in all rainbow examples all LEDs always go on and that is my problem.

I would like to be able to switch color, rainbow, color etc.

IMG_5908.jpg

interface.jpg

IMG_5908.jpg

interface.jpg

I have improved that, there is a mistake like that.

Sorry what does that mean?
If you have new code can you post what that now looks like.

So do you want the LEDs that are currently off to be a colour, including the blank digits or just the ones in the blocks being lit?

It seems your code turns off all LEDs and then over writes the ones you want to turn on. So instead of setting every LED to Black set it to a colour.

but how I have to program it is the question (arrays? Rainbow)

Yes have three array, one for each colour component and set all the LEDs in the digit first before turning the specific one on. For a single colour just use one entry in the colour array, or for multi colours step through the colours array with an increasing index.

so i put everything on black

start rainbow effect

and turn on all LEDs that should be visible.

have I understood that correctly.

have I understood that correctly.

I don’t know what you mean by

start rainbow effect

so i put everything on black

No you replace the black with your rainbow or single colour effect.

If you have new code for your setArray function will you please post it.

one try rainbow effect

#include <FastLED.h>

#define NUM_LEDS 21
#define DATA_PIN 1 
#define LED_TYPE WS2812B 
#define SATURATION 255
;
int hhtwelve[] = {3,7,8,9,10,11,12,13,17};

int *arrays[1] = {hhtwelve};

int r = 0, g = 0, b = 0;

CRGB leds[NUM_LEDS];

uint8_t hue = 0;

void setup() {
  FastLED.addLeds<LED_TYPE, DATA_PIN>(leds, NUM_LEDS);
}

void setArray(int arry[], int s)
{
  for (int i = 0; i < s; i++)
  {
    leds[arry[i]].setRGB(g, r, b);
  }
}

void loop() {
for (int i = 0; i < NUM_LEDS; ++i) {
    leds[i] = CHSV(hue + (i * 10), 255, 255);
  }

  //You can change the pattern speed here
  EVERY_N_MILLISECONDS(15){
    hue++;
  }
  setArray(hhtwelve, 9);
  FastLED.show();
 }

12 LEDs light up for 12 o'clock
int hhtwelve [] I programmed the LED negative

have defined all who are black

it works

do I have to go on like this?

it works

So then extend it further to the others.

I changed everything. here is my new code.

have already changed the HTML code
so a button for the rainbow

Domino_Clock.zip (10.7 KB)

I guess I didn't understand

here is an example of what works in my opinion

/--------- It is 12 o'clock, pixels 0 - 20 --the are black
int hhtwelve[] = {3,7,8,9,10,11,12,13,17};
//-----------Rainbow  
static uint8_t startIndex = 0;
  startIndex = startIndex + 1; /* higher = faster motion */
  fill_rainbow( leds, NUM_LEDS, startIndex);

//-----------Pixel 21 - 63 Black
  for (int i = 21; i < NUM_LEDS; i++)
  {
    leds[i] = CRGB::Black;
  }
//--------output-----------------
  setArray(hhtwelve, 9);  
  FastLED.show();

  FastLED.delay(1000 / 60);

right or wrong ?
an example please.

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