Go Down

Topic: LED array coding help (Read 167 times) previous topic - next topic

mikeinreno

I have an array of WB2812B leds. 10x6=60leds. These are 6 cut led strips 10 leds each wired in series. I would like to animate 0-10 leds light then dim and the next set 11-20 would light up and dim creating a sequential light down the array.

I am new to arduino sketch coding any help would be appreciated. Thank you for your time.

lesept

I first suppose you already know how to program an Arduino. You should then get familiar with one of the LED control libraries available. FastLED is one of them. Install it and try the examples for only one of your strips.

Then find the way to dim the leds as you want.

When you feel confortable with one led strip, try to run a sketch with 2 strips. The different ways to do it is explained here.
A force d'essayer on finit par réussir... Donc, plus ça rate, plus on a de chances que ça marche (proverbe Sharduinok).

mikeinreno

Thank you for the reply and link to the examples. My project has in essence is 1 led strip on 1 pin but is soldiered together to look like an array. I am looking to animate each set of leds in a blinking on and off down the strips in a sequential fashion. I am still learning the programming code but understand quite a bit, just looking for the most efficient way to code this project as I am using ATTiny85. 

lesept

I never tried the ATTiny85. Do you mean your strips are all connected in series ? Like a single strip of 60 leds?
A force d'essayer on finit par réussir... Donc, plus ça rate, plus on a de chances que ça marche (proverbe Sharduinok).

mikeinreno

Yes 60 leds in series but soldered in an array of 10x6 on going in 1 pin on ATtiny85. I use an Arduino Uno to program the ATiny85 from a breadboard. Works great for small projects. I have a 1972 VW Super Beetle that I am outfitting with sequential tail lights and animated turn signals with white driving lights. I currently have the turn signal animation just running down the 60 leds like a snaking light effect. I would like to light up 10 led at a time and down the array like you see in more and more modern vehicles. 

Delta_G

#5
Jul 17, 2019, 07:20 pm Last Edit: Jul 17, 2019, 07:21 pm by Delta_G
Don't know how it is in your state, but if the police see you on the road here with modified lights like that you'll be ticketed and the car goes to the pound.  The fine is a little over $100 I think.  The impound fees are where they get ya.  It keeps going up if you don't have the money to pay right away.  Pretty soon it's more than the car is worth and then they'll just auction it. 
|| | ||| | || | ||  ~Woodstock

Please do not PM with technical questions or comments.  Keep Arduino stuff out on the boards where it belongs.

mikeinreno

Almost every car manufacture is turning to LED lights with animation. I guess the local police will be doing nothing but handing out those illegal tail light tickets. The lights I am designing will be no different than what is in modern cars today. I do see on Youtube more and more aftermarket car light kits that do fancy animations that flash show patterns marketed towards car shows and car clubs. I'm sure if you drove down the road with all your light beating to music in crazy animations you deserve a fine $$. 

Delta_G

Quote
Almost every car manufacture is turning to LED lights with animation. I guess the local police will be doing nothing but handing out those illegal tail light tickets.
If the manufacturer does it then you're fine.  It's not the animation that's illegal.  It's modifying the lights that draws the fine.  It's an easy ticket and makes the department money.  So yeah, they write them all the time.

If you look carefully at those aftermarket kits, most of them say for show cars and not for street legal. 

I'm not admonishing you.  Just a warning before you're stuck on the side of the road watching your car go to the pound.  You can make all the good arguments you want.  But that won't stop the guy with the badge and the authority complex. 
|| | ||| | || | ||  ~Woodstock

Please do not PM with technical questions or comments.  Keep Arduino stuff out on the boards where it belongs.

lesept

#8
Jul 17, 2019, 07:51 pm Last Edit: Jul 18, 2019, 10:57 am by lesept
So if I understand well, from the point of view of the Arduino, you have a 60 led strip, numbered 0 to 59. For your animations, you just need to visualise the strip like this:
  • First line, leds number 0 to 9,
  • Second line, leds number 10 to 19
  • ...
  • Last line, leds number 50 to 59
I can't help you more for now, until you have a code doing the led strip declaration and lighting the 60 leds at the same time.

Making this first code will help you handle the library and see how it works. Then I can help you customize your code, play with the delays or whatever you need, but I first need to see if the Attiny can handle the 60 leds and if you can declare the strip. There is help on the FastLED wiki.

To conect your leds, refer to this site, and the following pages (scroll down to see the blue rectangles to go the other pages).

Do not hesitate to PM me if you don't see me around, I'm not usually in this part of the forum...
A force d'essayer on finit par réussir... Donc, plus ça rate, plus on a de chances que ça marche (proverbe Sharduinok).

lesept

This example shows how to control 8 leds using an Attiny85. I doubt the Attiny can provide enough current to feed 60 leds.
When all lit, and all white, 60 leds would require 60 x 0.06 = 3.6 A

So you will need another current source for your leds, connected like this :


So you also need a capacitor and a resistor.
A force d'essayer on finit par réussir... Donc, plus ça rate, plus on a de chances que ça marche (proverbe Sharduinok).

lesept

Your code is quite complex, can you simplify it by removing what is not being used?
A force d'essayer on finit par réussir... Donc, plus ça rate, plus on a de chances que ça marche (proverbe Sharduinok).

mikeinreno

Power is not an issue. I am using a step down converter to power the leds and an optocoupler to handle the signal input from the vehicle. I have this currently running from a power supply of 13.5volts simulating the vehicle voltage.

mikeinreno

This is the turn signal function. I believe I need to modify the code in the (int) to tell the strip to show 0-10 then delay then off and repeat for the next set 11-20 and so on...


int delayTurnLedAnim = 9;                                      //delay of each led in turn light animation
int delayTurnLedOff = 250;                                     //delay from animation to black (is used twice)

// turn signal function
if(stateTS != 0){
       
    for(int dot = 0; dot < NUM_LEDS_PER_STRIP; dot++) {

        leds[0][dot] = turnColor;
        FastLED.show();

        //delay(delayTurnLedAnim);
        currentMillis = previousMillis = millis();
        while(previousMillis + delayTurnLedAnim >= currentMillis){
          FastLED.show();
          currentMillis = millis();
        }

    }
   
    //delay(delayTurnLedOff);       
    currentMillis = previousMillis = millis();
    while(previousMillis + delayTurnLedOff >= currentMillis){
      FastLED.show();
      currentMillis = millis();
    }
   
    fill_solid(leds[0], NUM_LEDS_PER_STRIP, CRGB::Black);
    FastLED.show();
   
    //delay(delayTurnLedOff);       
    currentMillis = previousMillis = millis();
    while(previousMillis + delayTurnLedOff >= currentMillis){
      FastLED.show();
      currentMillis = millis();
    }

    buttonStateTS = digitalRead(buttonPinTS);
    stateTS++;
    if(stateTS >= nrAnimAfterOff && buttonStateTS != HIGH){
      stateTS = 0;
      gBrtL = 0;
      //delay(delayLedToDayLight);           
      currentMillis = previousMillis = millis();
      while(previousMillis + delayLedToDayLight >= currentMillis){
        FastLED.show();
        currentMillis = millis();
      }
    }

lesept

OK, this is only a part of the code. You should post your code using the CODE tags, it's easier to read. It will look like this :
Code: [Select]
int delayTurnLedAnim = 9;     //delay of each led in turn light animation
int delayTurnLedOff = 250;    //delay from animation to black (is used twice)

// turn signal function
if(stateTS != 0){
       
    for(int dot = 0; dot < NUM_LEDS_PER_STRIP; dot++) {

        leds[0][dot] = turnColor;
        FastLED.show();

        //delay(delayTurnLedAnim);
        currentMillis = previousMillis = millis();
...


If I understand well, you want to light the 6 strings one after the other, turning a strip off before passing to the next.
Your code has several mistakes, such as this, which, AFAIK is not permitted:
Code: [Select]
currentMillis = previousMillis = millis();

Here is an example of a function doing the animation for the turn signal:
Code: [Select]
const int delayTurnLedAnim = 9;      //delay of each led in turn light animation
const int delayTurnLedOff = 250;     //delay from animation to black (is used twice)
const byte numberOfStrips = 6;
const byte ledsPerStrip = 10;

void turnSignal(CRGB turnColor) {
  if (stateTS != 0) {
    for (byte strip = 0; strip < numberOfStrips; strip++) {
      for byte (dot = 0; dot < ledsPerStrip; dot++) {
        leds[strip * ledsPerStrip + dot] = turnColor;
        FastLED.show();
        delay(delayTurnLedAnim);
      }
      fill_solid(leds + strip * ledsPerStrip, ledsPerStrip, CRGB::Black);
      FastLED.show();
      delay(delayTurnLedOff);
    }
  }
}

I suppose that stateTS is a global variable, as well as the array leds. The function should be called using:
Code: [Select]
turnSignal(turnColor);
where turncolor is a CRGB struct you already defined elsewhere.

But you seem to do some button monitoring inside this function: can you explain what you want to do here, because I don't understand this part of the code?
A force d'essayer on finit par réussir... Donc, plus ça rate, plus on a de chances que ça marche (proverbe Sharduinok).

mikeinreno

Thank you very much for your help. I will work on this in the next few days. The button monitor is due to watching which pins get signal and prioritizing them. For example, the brake light would override the tail light function. I think I will simplify the code a little and separate into 2 different hardware setups. 1 Brake and Tail Light. 2 Turn Signal and Reverse Light. I really appreciate your help with this and I enjoy building my coding skills with fun projects such as this. 

Go Up