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: 41
Joined: Wed May 28, 2014 4:28 pm

Please be positive and constructive with your questions and comments.