Go Down

Topic: 2 leds diffirend speed in one ledstrip  (Read 1 time) previous topic - next topic

alexander44

Can i run 2 leds in one ledstrip at a diffirend speed and color?

all what i have is 2 leds at the same speed but cant make them slow and fast.

can somebody help me please?


septillion

So, where is the code? What type of ledstrip?

My crystal ball is broken, sorry :/
Use fricking code tags!!!!
I want x => I would like x, I need help => I would like help, Need fast => Go and pay someone to do the job...

NEW Library to make fading leds a piece of cake
https://github.com/septillion-git/FadeLed

alexander44

#2
Nov 16, 2016, 12:41 pm Last Edit: Nov 16, 2016, 12:54 pm by alexander44
Need some help please=>

hey.

made the ledstrip myself with de ws2812B leds. one strip with 148 leds. i use the adruno uno.
if you would look into this, please. tank you.


Code: [Select]


#include "FastLED.h"

///////////////////////////////////////////////////////////////////////////////////////////



#define NUM_LEDS 10     // How many leds are in the strip?
#define SPEED       10   // How fast the colors move.  Higher numbers = faster motion
#define STEPS        2   // How wide the bands of color are.  1 = more like a gradient, 10 = more like stripes
#define DATA_PIN 6       // Data pin that led data will be written out over
//#define CLOCK_PIN 8      // Clock pin only needed for SPI based chipsets when not using hardware SPI
CRGB leds[NUM_LEDS];     // This is an array of leds.  One item for each led in your strip.

// This function sets up the ledsand tells the controller about them
void setup() {
  // sanity check delay - allows reprogramming if accidently blowing power w/leds
    delay(2000);

     
      FastLED.addLeds<WS2812B, DATA_PIN, GRB>(leds, NUM_LEDS);
     
}

// This function runs over and over, and is where you do the magic to light
// your leds.
void setLEDcolors(unsigned long time)
{
  memset(leds,0,sizeof(leds));
  int Mercedes1=((time+4)%NUM_LEDS);
  leds[Mercedes1]=CRGB(0,127, 27),(50 /SPEED);
  int RedBull2=((time+2)%NUM_LEDS);
  leds[RedBull2]=CRGB(64, 0, 64);
 
  FastLED.show();
}


#define STEPDURATION 200
unsigned long stepTime;
unsigned long lastLEDupdate;

void loop(){
 
  if (millis()-lastLEDupdate>=STEPDURATION)
  {
    lastLEDupdate+=STEPDURATION;
    stepTime++;
    setLEDcolors(stepTime);
  }
}


septillion

That's more like it :)

Simple, you already have timing with millis. You can do that more then once. ;)
Use fricking code tags!!!!
I want x => I would like x, I need help => I would like help, Need fast => Go and pay someone to do the job...

NEW Library to make fading leds a piece of cake
https://github.com/septillion-git/FadeLed

alexander44

the (50 /SPEED) after the leds[Mercedes1]=CRGB(0,127, 27) does notting?
he looks only at de milis?

but how can i make them a diddirent speed?

sorry, i'm new in this prograaming. i have to learn much more but i can't understand a lot of it.

kind regard alexander

septillion

What do you think it does?

I'm even surprised it compiles... CRGB only takes colors as parameter. All the timing is done in the loop with millis() Every STEPDURATION (in ms) the setLedColors() is called which uses stepTime (which is a terrible name because it's not time...) to determined which led should be on.
Use fricking code tags!!!!
I want x => I would like x, I need help => I would like help, Need fast => Go and pay someone to do the job...

NEW Library to make fading leds a piece of cake
https://github.com/septillion-git/FadeLed

alexander44

sorry but that i don't understand.

i understand i make one Mercedes led going but i can't make the redbull led go faster ;)
maybe its something simple but i can't get it done.


the SPEED i put behind the color doesnt do the trick.

Thanks so far ;)

septillion

No, of course not! That's just playing code monkey (aka, just type whatever and hope you get a banana. And stop if you get bored after a couple of times.)

I suggest you read up on millis() (see Blink without delay) and then reread my post. ;)
Use fricking code tags!!!!
I want x => I would like x, I need help => I would like help, Need fast => Go and pay someone to do the job...

NEW Library to make fading leds a piece of cake
https://github.com/septillion-git/FadeLed

alexander44

i look into that. thanks.
and no, i don"t say stop ;) ;) ;)


alexander44

good morning.

i have looked into the millis but still don't understand it.
also i looked into the steptime but notting in there to.

this is very hard to learn. i don't know why i can't learn something of this program.
can you give me one more tip please?

kind regards.

ps: am i much of this skets or am i close?

sterretje

You have a nice project ( in the Dutch section).

Split your setLEDcolors into two functions; one will handle the mercedes and the other one the redbull.

Duplicate the code inside loop.
Code: [Select]

void loop(){
 
  if (millis() - lastMERCEDESupdate >= STEPDURATION)
  {
    lastMERCEDESupdate+=STEPDURATION;
    stepTime++;
    setMERCEDEScolors(stepTime);
  }
  if (millis() - lastREDBULLupdate >= STEPDURATION)
  {
    lastREDBULLupdate+=STEPDURATION;
    stepTime++;
    setREDBULLcolors(stepTime);
  }

}

I do not quite understand how it must work, but this can give you the idea. You probably need two stepTime variables and two STEPDURATION constants, one for each of the cars so name them accordingly.

Hope it helps

If you understand an example, use it.
If you don't understand an example, don't use it.

Electronics engineer by trade, software engineer by profession. Trying to get back into electronics after 15 years absence.

MAS3

Hi.

You have the same questions and the same answers running in the Dutch section.
I'd suggest you to keep it to the Dutch thread, where you can ask your questions and will get answers in your native language, so you will have a less hard time to understand the explanations.
Up until now you seem to ignore advice you don't like or disagree with.
You've been told multiple times to slow down and tackle 1 problem at a time, and that it isn't smart to do a project like this as your first programming experience.

There's no problem for you to want to do this, just don't expect the project to be done by Sinterklaas or Christmas this year.
There's a lot to learn before you can do something like this and understand most of what you are doing.
Have a look at "blink without delay".
Did you connect the grounds ?
Je kunt hier ook in het Nederlands terecht: http://arduino.cc/forum/index.php/board,77.0.html

Go Up