🎄⛄❄️🎁 It's beginning to look a lot like ADABOX-mas! The next ADABOX from Adafruit ships soon! Get yours now, or give as a gift! 🎄⛄❄️🎁
0

Speed of LEDs not fast enough
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Speed of LEDs not fast enough

by joshstern on Fri Sep 13, 2019 5:40 pm

Hi all,

I have some 30 leds/m and 60 leds/m NeoPixel strips and I'm trying to a laser blast effect on a 7 foot long length of the tape. I have my animation code working almost perfectly, except it just isn't fast enough of an animation. Instead of looking like a laser blast, it looks like runway lights.

I actually started with the 60/m tape, but since I couldn't get the animation working, I thought of going the physical route and using 30/m tape. Now my issue is the LED's are too far apart so they don't diffuse well enough, so I'd like to go back to the 60/m tape, but speed up the animation somehow.

The code below uses FastLED.

Code: Select all | TOGGLE FULL SIZE
#include <noise.h>
#include <bitswap.h>
#include <fastspi_types.h>
#include <pixelset.h>
#include <fastled_progmem.h>
#include <led_sysdefs.h>
#include <hsv2rgb.h>
#include <fastled_delay.h>
#include <colorpalettes.h>
#include <color.h>
#include <fastspi_ref.h>
#include <fastspi_bitbang.h>
#include <controller.h>
#include <fastled_config.h>
#include <colorutils.h>
#include <chipsets.h>
#include <pixeltypes.h>
#include <fastspi_dma.h>
#include <fastpin.h>
#include <fastspi_nop.h>
#include <platforms.h>
#include <lib8tion.h>
#include <cpp_compat.h>
#include <fastspi.h>
#include <FastLED.h>
#include <dmx.h>
#include <power_mgt.h>

//Comet Effect Written for Jason Brown
//Author: Scott C
//Date: 17th March 2017
//Arduino IDE version 1.8.1
//======================================================================

#include "FastLED.h"   //Make sure to install the FastLED library into your Arduino IDE

//The total number of LEDs being used is 144
#define NUM_LEDS 126

// The data pin for the NeoPixel strip is connected to digital Pin 6 on the Arduino
#define DATA_PIN 8

// The button will be connected to digital pin 9 on the Arduino. Uses Internal pullup resistor.
#define BUTTON 9

//Initialise the LED array, the LED Hue (ledh) array, and the LED Brightness (ledb) array.
CRGB leds[NUM_LEDS];
byte ledh[NUM_LEDS];
byte ledb[NUM_LEDS];

const int LEDSpeed = 99; //Speed of the LED animation effect. Make sure not to exceed the maxLEDSpeed value.
int maxLEDSpeed = 100;    //Identifies the maximum speed of the LED animation sequence
int LEDposition=0;       //Identifies the LED position in the strip that the comet is currently at. The maximum position is NUM_LEDS-1  (eg. 143)
int oldPosition=0;       //Holds the previous position of the comet.

byte hue = 0;            //Stores the Leading LED's hue value (colour)
byte sat = 255;          //Stores the Leading LED's saturation value
byte tailHue = 0;        //Stores the Comet tail hue value
int tailLength = 25;      //determines the length of the tail.
byte hueRange = 20;      //Colour variation of the tail (greater values have greater variation
byte intensity = 192;    //The default brightness of the leading LED
byte tailbrightness= intensity / 2;  //Affects the brightness and length of the tail
int animationDelay = 1;  //The greater the animation delay, the slower the LED sequence. Calculated from LEDSpeed and MaxSpeed.

unsigned long waitTime = 6;  //The wait time for each comet is currently set for 1 minute (or 60000 milliseconds).
unsigned long endTime;   //The time when we no longer have to wait for the next comet

int cometNumber = 1;     //Used to choose which comet colour to show (***Don't change this variable***)


//===================================================================================================================================================
// setup() : Is used to initialise the LED strip
//===================================================================================================================================================
void setup() {
    delay(0);          //Delay for two seconds to power the LEDS before starting the data signal on the Arduino
    FastLED.addLeds<WS2812B, DATA_PIN, GRB>(leds, NUM_LEDS);                            //initialise the LED strip     
    pinMode(BUTTON, INPUT_PULLUP);                                                      //Connect button to digital pin 9, and use the internal pullup resistor
    selectNextComet();                                                                  //Select the next comet colour
}


//===================================================================================================================================================
// loop() :
//===================================================================================================================================================
void loop(){
    showLED(LEDposition, hue, sat, intensity);

    //Adjust the hue of the tail so that it is a different colour from the leading LED. To reduce variation in tail colour, reduce the hueRange.
    if(hue>(254-hueRange)){
      tailHue = random((hue-hueRange),hue);
    } else {
      tailHue = random(hue, (hue+hueRange));
    }
   
    tailbrightness = random(50, 100);                      //Randomly select the brightness of the trailing LED (provides sparkling tail)

   
    leds[LEDposition]=CHSV((tailHue),sat,tailbrightness);  //Set the colour, saturation and brightness of the trailing LED
    fadeLEDs(tailLength);                                  //Fade the tail so that the tail brightness dwindles down to nothingness.
    setDelay(LEDSpeed);                                    //

    LEDposition++;
    if(LEDposition>(NUM_LEDS-1)){
     
      for(int i=0; i<50; i++){
        showLED(LEDposition, hue, sat, intensity);
        fadeLEDs(tailLength);
        setDelay(LEDSpeed);
      }
      LEDposition=0;
      selectNextComet();                                  //Select the next comet colour
      waitForNextComet();                                 //wait for the next comet (either 60 seconds or button press)
    }
 
}


//===================================================================================================================================================
// showLED() : is used to illuminate the LEDs
//===================================================================================================================================================
void showLED(int pos, byte LEDhue, byte LEDsat, byte LEDbright){
  leds[pos] = CHSV(LEDhue,LEDsat,LEDbright);
  FastLED.show();
}


//===================================================================================================================================================
// fadeLEDs(): This function is used to fade the LEDs back to black (OFF)
//===================================================================================================================================================
void fadeLEDs(int fadeVal){
  for (int i = 0; i<NUM_LEDS; i++){
    leds[i].fadeToBlackBy( fadeVal );
  }
}


//===================================================================================================================================================
// setDelay() : is where the speed of the LED animation sequence is controlled. The speed of the animation is controlled by the LEDSpeed variable.
//              and cannot go faster than the maxLEDSpeed variable.
//===================================================================================================================================================
void setDelay(int LSpeed){
  animationDelay = maxLEDSpeed - abs(LSpeed);
  delay(animationDelay);
}


//===================================================================================================================================================
//selectNextComet() : This is where we select either the Blue, the Pink or the White comet         
//===================================================================================================================================================
void selectNextComet(){
  cometNumber++;
  if(cometNumber>3){
    cometNumber=1;
  }

  switch(cometNumber){
    case 1:  {    //Blue Comet
      hue = 255;
      sat = 255;
      hueRange=10;
      break;
    }
 
    case 2:  {   //Pink Comet
      hue = 255;
      sat = 255;
      hueRange=10;
      break;
    }
   
    default: {   //White Comet
      hue = 255;
      sat = 255;
      hueRange =10;
      break;
    } 
  }
}


//===================================================================================================================================================
// waitForNextComet() : Is where we either wait for 60 seconds for another comet to come, or initiate another comet with a button press.
//                      The button will only be "ACTIVE" while we are waiting for the next comet. It has no effect while a comet is currently running         
//===================================================================================================================================================
void waitForNextComet(){
    endTime = millis() + waitTime;

    while(millis()<endTime){
      if(digitalRead(BUTTON)==LOW){
         break;
      }
    }
}


Any help would be greatly appreciated!
Josh

joshstern
 
Posts: 42
Joined: Wed May 28, 2014 4:28 pm

Re: Speed of LEDs not fast enough

by mikeysklar on Mon Sep 16, 2019 8:16 pm

Hello joshstern,

What Arduino based board are you driving these with?

mikeysklar
 
Posts: 376
Joined: Mon Aug 01, 2016 8:10 pm

Re: Speed of LEDs not fast enough

by chemdoc77 on Thu Sep 19, 2019 10:41 am

Hi Josh:

Based on your sketch, I created the following sketch which would move a dot along a strip at the fastest possible rate:

Code: Select all | TOGGLE FULL SIZE
// Fastest way to move a dot - Chemdoc77

#include <FastLED.h>

#define DATA_PIN     6
#define LED_TYPE     NEOPIXEL
#define NUM_LEDS     64
CRGB leds[NUM_LEDS];
int brightness = 100;

void setup() {
  delay(1000);
  FastLED.addLeds<LED_TYPE, DATA_PIN>(leds, NUM_LEDS);         
  FastLED.setDither(false);
  FastLED.setCorrection(TypicalLEDStrip);
  FastLED.setBrightness(brightness);
  FastLED.setMaxPowerInVoltsAndMilliamps(5, 1500);
   set_max_power_indicator_LED(13);
  fill_solid(leds, NUM_LEDS, CRGB::Black);
  FastLED.show();
 }
 
void loop() { 
     
  cd77_colorwipe_dot_fast(CRGB::Red);
  delay(1000);
}

//==================== Functions ===============================

void cd77_colorwipe_dot_fast(CRGB color) {
  for (uint16_t i = 0; i <NUM_LEDS; i++) {
    leds[i] = color;
    FastLED.show();   
    leds[i] = CRGB::Black;
    FastLED.show();
 
  }
}


It still looks like runway lights.

What do you mean by “laser blast effect”? Can you describe it or can you post a link to a video that shows the effect that you are trying to get?

Best Regards,
Chemdoc77

chemdoc77
 
Posts: 142
Joined: Mon Jan 28, 2013 9:32 am

Re: Speed of LEDs not fast enough

by joshstern on Wed Oct 02, 2019 5:44 pm

mikeysklar wrote:Hello joshstern,

What Arduino based board are you driving these with?


Hi Mikey,

Using an Arduino Uno.

chemdoc77 wrote:Hi Josh:

Based on your sketch, I created the following sketch which would move a dot along a strip at the fastest possible rate:

Code: Select all | TOGGLE FULL SIZE
// Fastest way to move a dot - Chemdoc77

#include <FastLED.h>

#define DATA_PIN     6
#define LED_TYPE     NEOPIXEL
#define NUM_LEDS     64
CRGB leds[NUM_LEDS];
int brightness = 100;

void setup() {
  delay(1000);
  FastLED.addLeds<LED_TYPE, DATA_PIN>(leds, NUM_LEDS);         
  FastLED.setDither(false);
  FastLED.setCorrection(TypicalLEDStrip);
  FastLED.setBrightness(brightness);
  FastLED.setMaxPowerInVoltsAndMilliamps(5, 1500);
   set_max_power_indicator_LED(13);
  fill_solid(leds, NUM_LEDS, CRGB::Black);
  FastLED.show();
 }
 
void loop() { 
     
  cd77_colorwipe_dot_fast(CRGB::Red);
  delay(1000);
}

//==================== Functions ===============================

void cd77_colorwipe_dot_fast(CRGB color) {
  for (uint16_t i = 0; i <NUM_LEDS; i++) {
    leds[i] = color;
    FastLED.show();   
    leds[i] = CRGB::Black;
    FastLED.show();
 
  }
}


It still looks like runway lights.

What do you mean by “laser blast effect”? Can you describe it or can you post a link to a video that shows the effect that you are trying to get?

Best Regards,
Chemdoc77


Hi Chemdoc77,

Ultimately, I'm looking for a Star Wars-esque style beam of energy traveling in a linear direction, accompanied by a "trail" effect. Excuse the crudeness of this video that isn't mine, but it's a great example of what we're trying to accomplish:

https://www.youtube.com/watch?v=GXQu1xqVQL0

Your sketch does allow for faster moving LED's, however, the greater the number of LED's I add into the sketch, the slower the animation goes. I imagine there's some math determining that speed somewhere, but for this test, we have 176 LED's.

Josh

joshstern
 
Posts: 42
Joined: Wed May 28, 2014 4:28 pm

Re: Speed of LEDs not fast enough

by chemdoc77 on Sat Oct 05, 2019 6:44 pm

Hi Josh:

Thank you for the clarification on what you are trying to accomplish.

Look at the following arcade project from Evil Genius Labs - Jason Coon:

https://evilgeniuslabs.org/fastled-arcade-mfkc

Look at the video at 18 seconds and I think that this is the effect you are looking for.

Jason included the code for this at:

https://github.com/jasoncoon/fastled-arcade

Best Regards,
Chemdoc77

chemdoc77
 
Posts: 142
Joined: Mon Jan 28, 2013 9:32 am

Re: Speed of LEDs not fast enough

by devinganger on Sat Oct 05, 2019 7:10 pm

Have you thought of lighting multiple LEDs at once (say 4) and advancing them by a factor greater than 1?

devinganger
 
Posts: 68
Joined: Tue Aug 09, 2016 1:09 am

Please be positive and constructive with your questions and comments.