Creating leds appear purple

hey guys and girls.

i have a project going on that requires dark flame effects, now i have the code suitable for what i need however, i wanted to use blue and purple leds.

theres 5 flames in total with 2 leds per flame, that randomly flicker in timing and brightness. im using an arduino nano for this and as a result only 6 pwm pins.

what i wanted to ask is this: u.v leds are too dimm, i dont have the PWM pin quantity to use digital leds, that would require 10 pwm pins. so is there a way i can physically make the led itself appear to emit purple light in order for that light to illuminate a 3d printed follow flame shape?

the code im using for it (may need slight adjustment, ledpin 2 needs removing)

// LED Fire Effect

int ledPin1 = 3;
int ledPin2 = 4;
int ledPin3 = 5;
int ledPin4 = 9;
int ledPin5 = 10;
int ledPin6 = 11;


void setup()
{
pinMode(ledPin1, OUTPUT);
pinMode(ledPin2, OUTPUT);
pinMode(ledPin3, OUTPUT);
pinMode(ledPin4, OUTPUT);
pinMode(ledPin5, OUTPUT);
pinMode(ledPin6, OUTPUT);

}

void loop() {
analogWrite(ledPin1, random(120)+135);
analogWrite(ledPin2, random(120)+135);
analogWrite(ledPin3, random(120)+135);
analogWrite(ledPin4, random(120)+135);
analogWrite(ledPin5, random(120)+135);
analogWrite(ledPin6, random(120)+135);
delay(random(100));
}

as a thought, would it be possible to use ws2812 leds and use ledpin 2 to randomly flicker each one in the line differently to the others in the line?

edit, i did google the final thought but it just shows search results where the strip flickers unintentionally.

It should be

but not like that.

You would write the "flicker" digitally

EDIT

Some pretty fast "flickering" here: https://youtu.be/aNlaj1r7NKc?t=738

I would go for a dual colour LED, of blue and red. One led in the package gives you the blue and both give you the purple you are after. The diodes being in the same package mix so much better. And you can lightly sandpaper the plastic for even better diffusion.

1 Like

i didnt know you could get red and blue leds as a single piece to be fair. i know you can get RGB with 4 legs. which could work as i do have some already and still in the same unit.

however that would require the use of further pins which i only have one spare and i need to get all 5 flames as independent as possible. the reason for wiring that way was to give it the apperence they all doing different things.

The big advantage of the ws2812 type things is that you can drive loads of them independently from just one pin.

this is why i was thinking of that for the purple, plus being able to set the color (which i assume, with my code, the color would be set below the pin setup and change the analog to digital for that pin leaving the random section of the code alone?

though i may be thinking entirely wrong here and have a different solution, if the above questions along the correct lines, i could use the ws2812b for the blues as well further reducing the required pins.

Be aware that using a WS2812 involves turning off the interrupts while it refreshes so it could affect things like servos, and serial reads.

oh this is just pure led control, absolutely no other hardware involved. but its good to have it noted on the thread for anyone else who comes across this looking for help. (interrupts aka delay in this instance.)

so i need to look for a flickering effect within the fast led library i guess.

i also now need to work out where to go from there.

im googling around for information on randomly adjusting brightness of sw2812b and making them flicker randomly but only getting results about it being a problem.

ok so i got this far but im unsure how i would set the color of the strips required in the noted line


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

CRGB leds[NUM_LEDS];

int ledPin1 = 3;
int ledPin3 = 5;
int ledPin4 = 9;
int ledPin5 = 10;
int ledPin6 = 11;


void setup()
{
pinMode(ledPin1, OUTPUT);
pinMode(ledPin3, OUTPUT);
pinMode(ledPin4, OUTPUT);
pinMode(ledPin5, OUTPUT);
pinMode)ledPin6, OUTPUT);
FastLED.addLeds<NEOPIXEL, DATA_PIN>(leds, NUM_LEDS);  // GRB ordering is assumed
FastLED.  //define led color here

}

void loop() {
analogWrite(ledPin1, random(120)+135);    //standard led
analogWrite(ledPin3, random(120)+135);    //standard led
analogWrite(ledPin4, random(120)+135);    //standard led
analogWrite(ledPin5, random(120)+135);    //standard led
analogWrite(ledPin6, random(120)+135);    //standard led

digitalWrite(ledPin2, random(120)+135);    //ws2812b leds

delay(random(100));
}

i feel like im not even close to the ball park

Correct you are miles off.

You do not use analogWrite to set the pixels in a WS2812. Look at the examples that come with the Fast Led library. There are lots of ways to define colours as well.

For more information see:-
FastLED documentation

ive seperated the ws2812 lines, the analogwrite are for standard leds only.

the line on its own with digitalwrite is for the ws2812b. (edited the code above to save confusion for anyone else)

ive looked around but cannot see any examples where the color is simply defined within the setup instead of the loop

No way.

Please read the documentation I posted and look at the examples you get with the Fast LED library.

They are in the Arduino File menu and you scroll down until you get to the fast LED folder, then open that folder and open the examples folder.

then it would have to be changed to fastled.show but would

fastled.show, random(120)+135); //ws2812b leds

would that function?

ive looked through it and the code examples used on the site look way different to those in the example.

sorry if it seems rude, its just these "documentations" just confuse me and seem far more complicated.

They are complicated because it is a complex system with many options you can take.

Why not take a look at the AdaFruit Library it is much easer to understand.

Start here:-

1 Like

there is this in the examples

void loop() { 
  // Turn the LED on, then pause
  leds[0] = CRGB::Red;
  FastLED.show();
  delay(500);
  // Now turn the LED off, then pause
  leds[0] = CRGB::Black;
  FastLED.show();
  delay(500);

that makes sense in my head, its simple, to the point and again, simple. maybe im trying to do something that isnt possible but im trying to keep it to the single delay. although another delay of 20 to clear the leds wouldnt hurt(?). this could be used i guess.

i'll take a look at the adafruit now though.

This is just one way of defining a colour, there are lots more.

thats fine, i guess i only need one way, the question is, if using that option, how would i then make each of the 5 in the strip be a different brightness to each other?

For regular LEDs this might be interesting:

Jack Christensen has this offering.

These might be of interest:

1 Like