Creating leds appear purple

thanks, the analog leds will probably end up being swapped out for digital strips as well once i get this worked out. but they may stay analog as well. havent really settled on that as yet, focusing on one bit at a time.

also for the use i have they are just 2 leds within a small tail but this is a slightly bigger project but increasing the led size compensates for that.

ok, so i've removed all the analog stuff for now to simplify things. i'll either add it back in or use the fastled for the blue as well.

how is this looking?


// LED Fire Effect
#include <FastLED.h>
#define NUM_LEDS 5
#define DATA_PIN 4
#define CLOCK_PIN 13
#define BRIGHTNESS 255

CRGB leds[NUM_LEDS];

void setup()
{
FastLED.addLeds<NEOPIXEL, DATA_PIN>(leds, NUM_LEDS);  // GRB ordering is assumed
}

void loop() {

leds[0] = CRGB::purple;
  BRIGHTNESS (leds[0] random(120)+135);
  FastLED.show();
delay(random(100));
leds[0] = CRGB::Black;
  FastLED.show();
delay(10);
}

getting closer by any chance?

If you have a Neo-Pixel strip, what do you see happening ?

haven hooked it up yet. i dont want to damage the led strip with bad code as has happened in the past.

also, in leds[0] what is the 0?

There is no reasonable reason this would happen.


The 0 says element 0 of the LED array (i.e. first pixel in the strip).


Wire your strip similar to D5 in the image below.

So you said you only had one pin spare? Has this now changed?

nah still only 1

So you need to show us how you propose to hook it up, and what software you propose to use so we can check this. This involves you drawing a circuit diagram of some sorts. Hand drawn is fine, no need to use any software to produce it. Just post a photograph of it.

i'll post the actual circuit soon but before than even matters, this code


// LED Fire Effect
#include <FastLED.h>
#define NUM_LEDS 5
#define DATA_PIN 1
#define CLOCK_PIN 13
#define BRIGHTNESS 255

CRGB leds[NUM_LEDS];

void setup()
{
FastLED.addLeds<NEOPIXEL, DATA_PIN>(leds, NUM_LEDS);  // GRB ordering is assumed
}

void loop() {

leds[0] = CRGB::BlueViolet;
  BRIGHTNESS (leds[0], random(120)+135);
  FastLED.show();
delay(random(100));
leds[0] = CRGB::Black;
  FastLED.show();
delay(10);
}

returns this:

exit status 1
expression cannot be used as a function

with this line highlighted

  BRIGHTNESS (leds[0], random(120)+135);

so it would seem i would have to create brightness as a function. i have found this page, which does explain it pretty well, however i am having trouble understanding it and how to construct the function i require. would it be possible for someone to step in and help with this section? or should i not bother with that as it wouldnt work anyway?

here is what im using to test the code on, its a digispark board. cheap and quick and simple. the code will translate to an uno without a problem or modification (other than pin assignments) as im sure you all know.


// LED Fire Effect
#include <FastLED.h>
#define NUM_LEDS 5
#define DATA_PIN 0
#define CLOCK_PIN 13
#define brightness

CRGB leds[NUM_LEDS];

void setup()
{
FastLED.addLeds<NEOPIXEL, DATA_PIN>(leds, NUM_LEDS);  // GRB ordering is assumed
}

void loop() {

leds[0] = CRGB::Indigo;
  brightness (leds[0], random(120)+135);
  FastLED.show();
delay(random(200));
leds[0] = CRGB::Black;
  FastLED.show();
delay(20);

ok so this makes the first led turn on however the flickering on it appears to be the same brightness. also the other 4 leds arent turning on. i get its only controlling the first pixel so how would i go about getting all 5 to light up with this current code? (will figure out the brightness next)

im a numpty, wrong command.

// LED Fire Effect
#include <FastLED.h>
#define NUM_LEDS 5
#define DATA_PIN 0
#define CLOCK_PIN 13
#define brightness

CRGB leds[NUM_LEDS];

void setup()
{
FastLED.addLeds<NEOPIXEL, DATA_PIN>(leds, NUM_LEDS);  // GRB ordering is assumed
}

void loop() {
fill_solid( leds, NUM_LEDS, CRGB::Indigo);
  brightness (leds[0], random(120)+135);
  FastLED.show();
delay(random(200));
fill_solid( leds, NUM_LEDS, CRGB::Black);
  FastLED.show();
delay(20);

}

fills the strip together. making progress. im posting updates so as i ask questions but work it out solo (with googles help lol) you can see how its coming.

so, with the fill solid, how do i go about variying the brightness? this is the point im really stuck on and need your help to be fair.

i have found the setbrightness command however they all stay the same brightness.


// LED Fire Effect
#include <FastLED.h>
#define NUM_LEDS 5
#define DATA_PIN 0
#define CLOCK_PIN 13
#define brightness

CRGB leds[NUM_LEDS];

void setup()
{
FastLED.addLeds<NEOPIXEL, DATA_PIN>(leds, NUM_LEDS);  // GRB ordering is assumed
}

void loop() {
fill_solid( leds, NUM_LEDS, CRGB::Indigo);
  FastLED.setBrightness(random(120)+135);
  FastLED.show();
delay(random(200));
fill_solid( leds, NUM_LEDS, CRGB::Black);
  FastLED.show();
delay(20);

}

im thinking maybe a HSV based code would be better for this. apparently set.brightness wasnt intended for repeated use in a code and more to be used in setup as a one time command.

Yes, set brightness affects all future uses of the set LEDs colours. Once a colour is in the buffer, set brightness has no effect.

So if you want to change the brightness of an individual LED, then set the brightness, then set the colour. You can't use fill_solid because that fills all the LEDs with the same brightness. You have to set the individual LED.

So set the brightness, set the colour of leds[0]. Then set the brightness and then set the colour of leds[1], repeat this for all leds index up to 4, which represents your 5 LEDs.

Of course this is a very clack handed way of going about things, and there are much better ways of doing this. But at the moment I don't think you understand how to set the RGB value of an individual LED.

hey it might be clack handed but it works.


// LED Fire Effect
#include <FastLED.h>
#define NUM_LEDS 5
#define DATA_PIN 0
#define CLOCK_PIN 13
#define brightness

CRGB leds[NUM_LEDS];

void setup()
{
FastLED.addLeds<NEOPIXEL, DATA_PIN>(leds, NUM_LEDS);  // GRB ordering is assumed
}

void loop() {
FastLED.setBrightness(random(120)+135);
leds[0] = CRGB::Indigo;
FastLED.setBrightness(random(120)+135);
leds[1] = CRGB::Indigo;
FastLED.setBrightness(random(120)+135);
leds[2] = CRGB::Indigo;
FastLED.setBrightness(random(120)+135);
leds[3] = CRGB::Indigo;
FastLED.setBrightness(random(120)+135);
leds[4] = CRGB::Indigo;
    FastLED.show();
delay(random(200));
fill_solid( leds, NUM_LEDS, CRGB::Black);
  FastLED.show();
delay(20);

}

they are all doing different things. albeit very similar things but still different, and with this i can increase the strip to 10 and use more of these for the blue as well, this will also allow me to set the blue to a lower brightness value as not to overpower the purple.

I would suggest that you need to at least use a for loop and cut this down to just two lines in that for loop.

Hint, use the loop index as the address, that is the number in the square brackets,

well i kind of hit a snag, the projects been assembled with the wires in place that was based on the assumption of 2 standard leds per flame. soooooo theres only 3 wires in each arm that has a flame on. that makes using these ws2812bs a little harder.

so i considered a solution to that issue in which i can use an uno with its 5 required pwm pins (out of the 6) and simply create arrays and one array on each pin.

so i gotta work on creating the arrays and pin assignments to that blah blah blah before i worry about a for statement.

reason being, i kind of want to get the code functional, then clean it up. i know, its backwards, and more time consuming. but thats just the way this has to go as got a deadline on this project and switching from standard leds to digital is a bit of a set back in itself.

hows this looking? im waiting for an uno to arrive to actually load it onto and test but im not convinced the function will be correct.


// LED Fire Effect
#include <FastLED.h>

#define NUM_STRIPS 5
#define NUM_LEDS_PER_STRIP 2
#define brightness

CRGB leds[NUM_STRIPS] [NUM_LEDS_PER_STRIP];

void setup()
{
FastLED.addLeds<NEOPIXEL, 3>(leds[0], NUM_LEDS_PER_STRIP);
FastLED.addLeds<NEOPIXEL, 5>(leds[1], NUM_LEDS_PER_STRIP);
FastLED.addLeds<NEOPIXEL, 6>(leds[2], NUM_LEDS_PER_STRIP);
FastLED.addLeds<NEOPIXEL, 9>(leds[3], NUM_LEDS_PER_STRIP);
FastLED.addLeds<NEOPIXEL, 10>(leds[4], NUM_LEDS_PER_STRIP);
}

void loop() {
  for(int x = 0; x < NUM_STRIPS; x++) {
    for(int i = 0; i < NUM_LEDS_PER_STRIP; i++) {
FastLED.setBrightness(random(120)+135);
leds[x][i] = CRGB::Indigo;
FastLED.setBrightness(random(120)+135);
leds[x][i] = CRGB::Blue;

    FastLED.show();
    
delay(random(200));

leds[x][i] = CRGB::Black;
  FastLED.show();
delay(20);
  }
 }
}

reason i say im not sure it will function correctly is because i cannot work out how to tell the code the BLUE color is for the second pixel? or is that assumed by the code? also im back to trying to work out how to get the 5 strips to have different brightnesses for the 2 colors from each other.

so, can someone point me in the right direction for those 2 questionable points please?

I am a bit confused about that, can you draw a schematic of it please?

Me too.
You can't do things like

because you have not set up the variable leds to be a two dimensional array, it is only a one dimensional array.

hey mike, your last comment, the array code was taken from the array example.

// ArrayOfLedArrays - see https://github.com/FastLED/FastLED/wiki/Multiple-Controller-Examples for more info on
// using multiple controllers.  In this example, we're going to set up three NEOPIXEL strips on three
// different pins, each strip getting its own CRGB array to be played with, only this time they're going
// to be all parts of an array of arrays.

#include <FastLED.h>

#define NUM_STRIPS 3
#define NUM_LEDS_PER_STRIP 60
CRGB leds[NUM_STRIPS][NUM_LEDS_PER_STRIP];

// For mirroring strips, all the "special" stuff happens just in setup.  We
// just addLeds multiple times, once for each strip
void setup() {
  // tell FastLED there's 60 NEOPIXEL leds on pin 2
  FastLED.addLeds<NEOPIXEL, 2>(leds[0], NUM_LEDS_PER_STRIP);

  // tell FastLED there's 60 NEOPIXEL leds on pin 3
  FastLED.addLeds<NEOPIXEL, 3>(leds[1], NUM_LEDS_PER_STRIP);

  // tell FastLED there's 60 NEOPIXEL leds on pin 4
  FastLED.addLeds<NEOPIXEL, 4>(leds[2], NUM_LEDS_PER_STRIP);

}

void loop() {
  // This outer loop will go over each strip, one at a time
  for(int x = 0; x < NUM_STRIPS; x++) {
    // This inner loop will go over each led in the current strip, one at a time
    for(int i = 0; i < NUM_LEDS_PER_STRIP; i++) {
      leds[x][i] = CRGB::Red;
      FastLED.show();
      leds[x][i] = CRGB::Black;
      delay(100);
    }
  }
}

which is essentially the same thing.