I am in search of some guidance,

fastled-support
gplus
(Kyle bostick) #1

I am in search of some guidance, I have a program that will loop through several pallets and is working as expected. I have a different program that I can select an effect, I would like to know how to make an effect just fill the LEDs a solid color based on a pallet, I can not find a way to do this, without looping pallets, or without adding some type of effect, like “glitter” This should be simple, but I am not sure how to do it. I can post my code if needed. Thanks everyone!

(Andrew Tuline) #2

I haven’t tried it, but would something like this work:

CHSV color = ColorFromPalette(currentPalette, index);
fill_solid(leds, NumLeds, color);

(Kyle bostick) #3

@Andrew_Tuline Where would i put that in my code? Right now my code has the colors i want moving down the strip in a group of 5.

(Kyle bostick) #4

#include <FastLED.h>

#define LED_PIN 7
#define NUM_LEDS 100
#define BRIGHTNESS 150
#define LED_TYPE WS2812B
#define COLOR_ORDER GRB
CRGB leds[NUM_LEDS];

#define UPDATES_PER_SECOND 100

CRGBPalette16 currentPalette;
TBlendType currentBlending;

extern CRGBPalette16 myRedWhiteBluePalette;
extern const TProgmemPalette16 myRedWhiteBluePalette_p PROGMEM;

void setup() {
delay( 3000 ); // power-up safety delay
FastLED.addLeds<LED_TYPE, LED_PIN, COLOR_ORDER>(leds, NUM_LEDS).setCorrection( TypicalLEDStrip );
FastLED.setBrightness( BRIGHTNESS );

currentPalette = myRedWhiteBluePalette_p;
currentBlending = NOBLEND;
}

void loop()
{

static uint8_t startIndex = 0;
startIndex = startIndex + 1; /* motion speed */

FillLEDsFromPaletteColors( startIndex);

FastLED.show();
FastLED.delay(1000 / UPDATES_PER_SECOND);
}

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;
}
}

const TProgmemPalette16 myRedWhiteBluePalette_p PROGMEM =
{
CRGB::White,
CRGB::Red, // ‘white’ is too bright compared to red and blue
CRGB::Green,
CRGB::Yellow,
CRGB::Blue,
CRGB::Orange

};

(Andrew Tuline) #5

It seems to me that your question was to fill the LED’s with a single colour from a palette, as in (sic) “fill the LEDs a solid color based on a pallet”. The code you have provided, however, is not a fill, but rather an assignment to a single LED at a time. This is a completely different thing.

Then you mention in the follow up that “i want moving down the strip in a group of 5”, which, again is not ‘fill the LEDs a solid color’. That could be fill a group of LED’s a solid colour.

I’m sorry, but I’m now really confused as to what you’re trying to do because it seems to me like you’re trying to create a palette defined rainbow, which is fine and is working on my test strip, and in groups of 5.333. With 256 values for the index and an increment of 3 and 16 colours in the palette, your current animation will have 256/3/16 = 5.333 pixels per colour. Some will be 6, some will be 5.

That being said, you’ve only defined 6 of the 16 colours in the palette, so most of it’s black.

As an aside, I recommend not using delay statements at all in your sketches. Try using millis() or EVERY_N_MILLIS() for timing. Delays are the work of the devil.

(Kyle bostick) #6

@Andrew_Tuline I am sorry for the confusion, I want to fill the Strip of LEDs from the colors in the palette. I do not want them to move. Just fill the strip with the 6 colors from the palette. I was trying to explain that the code I have right now is moving the colors down the strip, in a group of about 5. That is not the effect I want. I just want it to fill the LEDs without moving the 6 colors in the palette

(Andrew Tuline) #7

@Kyle_bostick Try this:

I’ll leave it to you as an exercise to repeat that pattern down the strip if you wish.

(Kyle bostick) #8

@Andrew_Tuline Thank you so much for trying to help me figure this out. I reviewed the code you posted, I noticed I had to make a few changes for my set up, I have no clk pin, my data pin is different and i have different LED types, but once I got the few settings changed and tried to run it, i do not get any errors but only 25 LEDs light up. They are in a section of 5 LEDs per color. If possible I would like the whole strip to light up, and have the pattern be 1 color sections instead of 5. so the LEDs would be Orange, Blue, Yellow,Green,Red and white, but 1 at a time, instead of groups of 5. If i run the sketch i made, they all light up. So everything is hooked up right, but im not sure why the rest
don’t light up

#include <FastLED.h>

#define LED_PIN 7
#define NUM_LEDS 99
#define BRIGHTNESS 150
#define LED_TYPE WS2812B
#define COLOR_ORDER GRB
CRGB leds[NUM_LEDS];

CRGBPalette16 currentPalette;
TBlendType currentBlending;

extern CRGBPalette16 myRedWhiteBluePalette;
extern const TProgmemPalette16 myRedWhiteBluePalette_p PROGMEM;

void setup() {

Serial.begin(57600);
// delay( 3000 ); // power-up safety delay
FastLED.addLeds<LED_TYPE, LED_PIN, COLOR_ORDER>(leds, NUM_LEDS+1).setCorrection( TypicalLEDStrip );
//FastLED.addLeds<LED_TYPE, LED_PIN, CLK_PIN, COLOR_ORDER>(leds, NUM_LEDS+1).setCorrection( TypicalLEDStrip );
FastLED.setBrightness( BRIGHTNESS );

currentPalette = myRedWhiteBluePalette_p;
currentBlending = NOBLEND;
}

void loop()
{

EVERY_N_MILLIS(50) // Use this instead of delays. In this case, we really don’t need it.
{
myfiller();
}

FastLED.show();

}

void myfiller()
{

for (int i = 0; i<6;i++) {
CRGB color = ColorFromPalette(currentPalette, i16);
fill_solid(leds+i
5, 5, color);
}

} // myfiller()

const TProgmemPalette16 myRedWhiteBluePalette_p PROGMEM =
{
CRGB::White,
CRGB::Red, // ‘white’ is too bright compared to red and blue
CRGB::Green,
CRGB::Yellow,
CRGB::Blue,
CRGB::Orange

};

(Andrew Tuline) #9

Hi Kyle,

I think your best bet may be to draw a picture of what you want because it sounded like you wanted a fill of 5 led’s per defined colour in your palette down the strip.

As you can see, describing an effect clearly, accurately and concisely can be a very challenging task.

If I understand correctly, it appears that you want a repeating pattern of (1 led per color):

white, red, green, yellow, blue, orange

all the way down the strip. There would be no ‘fill’ involved here and to me is completely different than your original request to ‘fill the LEDs a solid color based on a pallet’.

Oh, and please post any code you want to display on http://gist.github.com and provide a link to it.

(Kyle bostick) #10

@Andrew_Tuline Ideally i’d like the pattern to go like this LED 1 White, LED 2 RED, LED 3 Green, LED 4 Yellow, LED 5 Blue, LED 6 Orange, LED 7 pattern starts over (White)

I would like it to fill all LEDs in the above pattern, not have them change, or move colors at all.

If your willing to help me out i have a few more things I want to have a few patterns or effects that i can add in a different file i have been working on. I would throw you some money or a donation if you’re willing to help me out.

I would like to have a second program that cycles through that pattern, but only 1 LED at a time instead of 5.

(Andrew Tuline) #11

Hi Kyle, I’ve now updated my gist with your updated requirements:

As for further patterns, I’d like to suggest that you look at the multiple ones available online, download and study them and then modify to your liking. My greatest enjoyment with using LED’s has been to come up with some funky routines and to make them public. I try to focus on routines:

  • with minimal code
  • without using delay statements
  • using 8 or 16 bit math

For instance this one uses very little code and yet is really cool:

(Kyle bostick) #12

That was exactly what I was looking for, thank you so much. As far as the other ones go, I have downloaded a ton of demos, and am trying to learn. I would love for someone that understands to teach me or explain so of the questions i have. I have made a few programs, but still don’t really know what i’m doing. Would you be willing to help me understand a few things? or like i said if your willing to tweak the program i’m working on i can throw ya some money for your time

(Andrew Tuline) #13

I’m not up for tutoring anyone, however feel free to research and post well thought out FastLED questions on this G+ forum. Try the Arduino forums for general Arduino programming.

Make sure you’ve put some good effort into your code and your questions before posting and be sure to post your code on http://gist.github.com.

When I started out, pretty well the only examples I had to go on were the ones included with the FastLED library and one called Funkboxing. After that, I just hoarded examples, dissected them and shared a lot of what I’d found and created.

(Kyle bostick) #14

@Andrew_Tuline Thank you for helping me with that sketch, it is exactly what I was trying to do. I understand you are not up for tutoring, but if i have a few specific questions can you answer them? If i understand these few things i feel like i would be able to make the sketches I mentioned earlier.

(Andrew Tuline) #15

I see you’ve already asked one of this group. Was a good question with some very good answers. Keep it up!

(Kyle bostick) #16

@Andrew_Tuline Can you explain what all this means? if i understand how or why you wrote this code i think i will be able to make my other projects work.

Why there are 2 void sections?
I would like to know what the int i= part is for?
What the i*16 parts do?

void singlepal()
{
for (int i = 0; i<NUM_LEDS; i++) {
leds[i] = ColorFromPalette(currentPalette, (i16)%(166));
}
}

void myfiller()
{

for (int i = 0; i<7;i++) {
CRGB color = ColorFromPalette(currentPalette, i16);
fill_solid(leds+i
6, 6, color);
}

(Andrew Tuline) #17

@Kyle_bostick It’s a very good idea to separate your display routine from your loop, which is why we have those void sections. They’re called from the main loop. Referring to:

On line 38, we’re calling singlepal();

You can comment out that line and replace it with myfiller();

They just keep the loop free from extra code.

The ‘int i’ part is a for loop, that allows me to do something to each LED on the strip.

The trick to get 1 color from your palette of 6 colours for each LED is THIS line

ColorFromPalette(currentPalette, (i16)%(166));

You have defined a 16 colour palette. The range of the palette is colours 0 through 255, and each colour is 16 in length. For i16 where i=0 that’ll grab the colour at location 0 in the palette, or the first colour and assign that colour to leds[0]. For i=1, that’ll grab location 16 from your palette, or the 2nd colour and assign that to leds[1], and so on. The problem is that you’ve only defined 6 colours in your palette, so we need to cycle back to 0 once we’ve hit the 6th colour. That’s where %(166) comes in. That’s a modulus operator.

My recommendation, again, is to study the http://arduino.cc reference along with simpler FastLED examples. Find something that works, change it and go onto the next. It’ll be difficult creating your own designs if you don’t understand some of these basics.

And as you can see, the palette routine you wanted required some understanding of C as well as FastLED and took a little bit of thinking to come up with a way to implement it concisely.

(Kyle bostick) #18

@Andrew_Tuline Thank you for the explanation and the advice.