Go Down

Topic: How to make certain LED in a LED strip to blink? (Read 7423 times) previous topic - next topic

CrossRoads

If you want them to blink, save the sequence that labview sends in.
Send that to the strip.
After your on-time, have the Arduino send the all-off sequence.
After your off-time, have the Arduino send the original sequence.
Repeat.
After every send to the LED strip, check to see if a new labview sequence was received.
Designing & building electrical circuits for over 25 years.  Screw Shield for Mega/Due/Uno,  Bobuino with ATMega1284P, & other '328P & '1284P creations & offerings at  my website.

Grumpy_Mike

#16
Feb 20, 2017, 08:43 pm Last Edit: Feb 20, 2017, 08:44 pm by Grumpy_Mike
But... but... they are individually addressable LEDs!!! Everyone says so!
Sure they are individually addressable but you have to send the all data for the whole chain all in one go. You can not send data to just one LED. If you think you can then you have misunderstood what "everyone" is saying.

negotxj

OK, let me summarise what you are now saying you want to do. The Arduino receives a string such as "RBOGB". It changes all leds in the strip to red. After a delay it changes all the leds to blue. After another delay, all leds off. After another delay, all leds green. After another delay, all leds blue. After another delay, all leds back to red as the seqience restarts and so on, until another string is received?

Hi PaulRB,

It wasn't like that.

When it receive RBOGB, first led turn red, second turn blue, third no on, forth turn green and last turn blue, all at the same time without any delay.

If u see my code, i control the color of every led in the strip individually.

Now i just want to let them blink but not on without blinking.

negotxj

I did not look at your code but how about making use of uppercase and lowercase?

Uppercase could e.g. indicate on and lowercase could indicate blink. The arduino will store the received command and next act accordingly on every iteration of loop. You only have to send the command once.

If you have a blink rate of e.g 1 Hz (500ms on, 500ms off) for all your leds, it should be easy to update all leds every 500ms using a millis() based timing. If you need one led to blink at 1 Hz and another one a 2 Hz or 3 Hz or not blink in sync, it will get a bit trickier.
Hi sterretje,

I am using UPPERCASE to control my leds. However, that doesn't matter.

My problem now is, i don't want my led on only. I want them blink. I am controlling each led in the strip by sending a string to Arduino.

Sending RGBW means first led is red, second is green, third is blue and last is white color.
My code enable them to on with those color, but i want them blinks not on only. However i do not have any idea on making them blink. I do not want them to blink at different Hz. I want them to blink at the same frequency. I just have no idea on how to modified my sketch to make them work.

sterretje

#19
Feb 21, 2017, 12:31 pm Last Edit: Feb 21, 2017, 12:32 pm by sterretje
How do you tell the Arduino to blink a specific led? My suggestion was to use e.g. 'R' to switch red on and 'r' to blink red.

You can blink by remembering the current state of each led.
Code: [Select]
void loop()
{
  // received data
  static char rxData[11];
  // index where to store received character
  static byte index = 0;

 
  // workcopy of received data
  static char workData[11];
  // remember current on/off state for flashing
  static char states[11];

  // timing related (flash)
  static unsigned long startTime = 0;
  unsigned long currentTime = millis();

  if (Serial.available() > 0)
  {
    if (index == 10)
    {
      index = 0;
    }
    rxData[index++] = Serial.read();
  }

  if (rxData == 10)
  {
    // work copy
    memcpy(workData, rx_Data);
    // initial state of leds equals received pattern
    memcpy(states, rxData);

    // reset index for next receive
    index = 0;
  }


  if (currentTime - startTime >= 500)
  {
    startTime = currentTime;

    for (int cnt = 0; cnt < 10; cnt++)
    {
      switch (workData[cnt])
      {
        case 'R':
          pixels.setPixelColor(j, pixels.Color(50, 0, 0));
          break;
        case 'r':
          // if on, switch off
          if (states[cnt] == 'r')
          {
            states[cnt] = 'O';
            pixels.setPixelColor(j, pixels.Color(0, 0, 0));
          }
          // if off, switch on
          else
          {
            states[cnt] = 'r';
            pixels.setPixelColor(j, pixels.Color(50, 0, 0));
          }
          break;
        case 'G':
          ...
          break;
        case 'g':
          ...
          break;
        case 'B':
          ...
          break;
        case 'b':
          ...
          break;
        case 'W':
          ...
          break;
        case 'w':
          ...
          break;
        case 'O':
          ...
          break;
      } // end_of_switch
    } // end_of_for
  } // end_of_if
}

It will receive up to 10 characters (representing what needs to happen); once the 10 are received, it will make a copy to two variables. The 'workData' variable is used to allow you to receive new data while the rest of your process is in progress. The 'states' variable is used to remember the state of leds that are flashing.

The code uses a non-blocking timing for the blinking so you can receive data in the mean time.

The code is not compiled nor tested but it can give you the idea how to approach. You'll have to fill in the dots ;)
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.

Grumpy_Mike

What I would do is to have a second instance of the libiary on the same pin with the same number of LEDs. Then set this second instance to all off.
Then simply alternate between sending the original instance and the new one.

This will blink all the on LEDs between on and off.

It will not blink selected LEDs on and off leaving other LEDs off, that is a touch more complex, but not much using two instances of the libiary.

boolrules

Quote
If you think you can then you have misunderstood what "everyone" is saying.
Apparently I have misunderstood. So what does "individually addressable" mean?

To me it means one LED (individual) can be "addressed". But you are right, there is no address associated with these LEDs. There is no way to individually address one. But the name persists.

The confusion is that the LED data has an associated address in the MCU's memory (usually an index to a data array). But it's not the address of any LED. This is what has led to the OP's confusion. He expects to be able to select an individual LED and blink it independently of all the others because he has heard the term "individually addressable". But you can't do that 'cause they aren't..

I can't think of any other electronic component that has a descriptive name that comes from a software data structure that is used in its driver.

Grumpy_Mike

Well they are called individually addressable because each individual LED can be set individually of the state of the others. You have to understand that the name came to distinguish them from the LED strips that already existed before these came in. In these strips, while you could have any colour by controlling the RGB brightness, you could only have all the LEDs in the strip at the same colour.

boolrules

OK. Thanks. I guess that will serve in Arduino Land.

negotxj

OK, let me summarise what you are now saying you want to do. The Arduino receives a string such as "RBOGB". It changes all leds in the strip to red. After a delay it changes all the leds to blue. After another delay, all leds off. After another delay, all leds green. After another delay, all leds blue. After another delay, all leds back to red as the seqience restarts and so on, until another string is received?

Hi Paul,

I am sorry but it's totally wrong.

In "RBOGB", first char "R" represent red color for first led in the cascading led strip, second char "B" represents blue color for second led in the cascading strip, third char "O" represents no color for the third led in the cascading strip and so on..

All LEDs from the first to the last will on at the same time when arduino receive a control string.
10 LEDs means Arduino will receive 10 char control string i.e. "RGBWRGBWRG". Red for first LED, Green for second, White for third, Red for forth and so on..

negotxj

Sure they are individually addressable but you have to send the all data for the whole chain all in one go. You can not send data to just one LED. If you think you can then you have misunderstood what "everyone" is saying.
Hi Mike,

Yes, i was sending all data for whole chain to make all leds to on with any color (not same color for all leds in one strip) that i have assigned to them.

However, now i don't want them on. I want them blink. I know i need some algorithm in the sketch but i need help since i don't know how to do.

Grumpy_Mike

I thought I told you the algorithm for doing this in reply #20?

boolrules

#27
Feb 28, 2017, 12:06 pm Last Edit: Feb 28, 2017, 01:20 pm by boolrules
To blink the fifth LED, you would send:

RGBWRGBWRG   5th LED on
RGBW0GBWRG   5th LED off
RGBWRGBWRG   5th LED on
RGBW0GBWRG   5th LED off
     .
The '0' represents the LED receiving all zeros for its 24 bits.
The rate at which you send each data set is how fast the LED blinks.

You have to provide the blink functionality on the Arduino.
Your code could run on some fixed timebase where data is repeatedly sent to the LEDs.
When you get a value that indicates "blink" from Labview, the code on the Arduino would
then alter the data to the LED at the timebase rate.
It would continue to do this until a different value was received from Labview.

Grumpy_Mike

I thought he said he wanted to blink all the LEDs that are in, not just a few of them.

My method stops you having to send lots and lots and lots of data from LabView.

boolrules

Maybe I did not read closely enough.

Anyway, if you set up a function to continuously send data, you can let it run and you
don't really have to think about it any more. It could also support an On/Off flag to
halt continuous running if necessary.

When you want to blink any LED, you just have to mod the color-data array at appropriate
times. You don't even have to think about the data being transmitted to the LEDs. It breaks
the problem down into smaller chunks.

It may take up more CPU time, but if that's a problem, then you have that problem whenever
you want to blink the LED(s) anyway. And 10 WS812Bs don't take much time at all to refresh.

Go Up