0

LED Strip Not Showing Defined # of LEDs
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

LED Strip Not Showing Defined # of LEDs

by joshstern on Tue Feb 19, 2019 6:21 pm

Hi all,

I'm working with John Ericksen's "Plasma" effect, here:

Code: Select all | TOGGLE FULL SIZE
/*
    Multicolored Plasma for the Arduino Micro-Controller and NeoPixel Shield
    Copyright (C) 2013 John Ericksen

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or F ITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see http://www.gnu.org/licenses/.
*/

#include <Adafruit_NeoPixel.h>

// Parameter 1 = number of pixels in strip
// Parameter 2 = pin number (most are valid)
// Parameter 3 = pixel type flags, add together as needed:
//   NEO_RGB     Pixels are wired for RGB bitstream
//   NEO_GRB     Pixels are wired for GRB bitstream
//   NEO_KHZ400  400 KHz bitstream (e.g. FLORA pixels)
//   NEO_KHZ800  800 KHz bitstream (e.g. High Density LED strip)
const int NUM_LEDS = 85;
const int LED_PIN = 8;
Adafruit_NeoPixel strip = Adafruit_NeoPixel(NUM_LEDS, LED_PIN, NEO_GRB + NEO_KHZ800);

// Convenient 2D point structure
struct Point {
  float x;
  float y;
};


float phase = 0.0;
float phaseIncrement = 0.015;  // Controls the speed of the moving points. Higher == faster. I like 0.08 .
float colorStretch = 0.3;    // Higher numbers will produce tighter color bands. I like 0.11 .

void setup() {
  strip.begin();
  strip.show(); // Initialize all pixels to 'off'
}

// This function is called every frame.
void loop() {
  phase += phaseIncrement;
 
  // The two points move along Lissajious curves, see: http://en.wikipedia.org/wiki/Lissajous_curve
  // We want values that fit the LED grid: x values between 0..13, y values between 0..8 .
  // The sin() function returns values in the range of -1.0..1.0, so scale these to our desired ranges.
  // The phase value is multiplied by various constants; I chose these semi-randomly, to produce a nice motion.
  Point p1 = { (sin(phase*1.000)+1.0) * 4.5, (sin(phase*1.310)+1.0) * 4.0 };
  Point p2 = { (sin(phase*1.770)+1.0) * 4.5, (sin(phase*2.865)+1.0) * 4.0 };
  Point p3 = { (sin(phase*0.250)+1.0) * 4.5, (sin(phase*0.750)+1.0) * 4.0 };
 
  byte row, col;
 
  // For each row...
  for( row=0; row<5; row++ ) {
    float row_f = float(row);  // Optimization: Keep a floating point value of the row number, instead of recasting it repeatedly.
   
    // For each column...
    for( col=0; col<8; col++ ) {
      float col_f = float(col);  // Optimization.
     
      // Calculate the distance between this LED, and p1.
      Point dist1 = { col_f - p1.x, row_f - p1.y };  // The vector from p1 to this LED.
      float distance1 = sqrt( dist1.x*dist1.x + dist1.y*dist1.y );
     
      // Calculate the distance between this LED, and p2.
      Point dist2 = { col_f - p2.x, row_f - p2.y };  // The vector from p2 to this LED.
      float distance2 = sqrt( dist2.x*dist2.x + dist2.y*dist2.y );
     
      // Calculate the distance between this LED, and p3.
      Point dist3 = { col_f - p3.x, row_f - p3.y };  // The vector from p3 to this LED.
      float distance3 = sqrt( dist3.x*dist3.x + dist3.y*dist3.y );
     
      // Warp the distance with a sin() function. As the distance value increases, the LEDs will get light,dark,light,dark,etc...
      // You can use a cos() for slightly different shading, or experiment with other functions. Go crazy!
      float color_1 = distance1;  // range: 0.0...1.0
      float color_2 = distance2;
      float color_3 = distance3;
      float color_4 = (sin( distance1 * distance2 * colorStretch )) + 2.0 * 0.5;
     
      // Square the color_f value to weight it towards 0. The image will be darker and have higher contrast.
      color_1 *= color_1 * color_4;
      color_2 *= color_2 * color_4;
      color_3 *= color_3 * color_4;
      color_4 *= color_4;
 
      // Scale the color up to 0..7 . Max brightness is 7.
      //strip.setPixelColor(col + (8 * row), strip.Color(color_4, 0, 0) );
      strip.setPixelColor(col + (8 * row), strip.Color(color_1, color_2, color_3));
    }
  }
  strip.show();
}


My trouble is even though I have 85 LEDs listed as the NUM_LEDS string, I only get 40 LEDs illuminated. Regardless of the number I put in (above 40), I only get 40. Any number below that responds properly.

I'm not sure if it's a power issue, but I have a 5v 10a power supply driving these LEDs separately from the Uno.

Any assistance is greatly appreciated!
Josh

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

Re: LED Strip Not Showing Defined # of LEDs

by franklin97355 on Tue Feb 19, 2019 6:30 pm

What are you trying to drive with this code? Can you post a link to the pixels or display?

franklin97355
 
Posts: 20126
Joined: Mon Apr 21, 2008 2:33 pm
Location: Lacomb, OR.

Re: LED Strip Not Showing Defined # of LEDs

by joshstern on Tue Feb 19, 2019 6:34 pm

franklin97355 wrote:What are you trying to drive with this code? Can you post a link to the pixels or display?


I have a 2 meter strip of Adafruit's NeoPixels, specifically, these: https://www.adafruit.com/product/1138?length=4

A strandtest run on them works fine through LED #85 and beyond.

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

Re: LED Strip Not Showing Defined # of LEDs

by millercommamatt on Tue Feb 19, 2019 6:47 pm

Your code has 5 rows and 8 columns. 8 x 5 = 40. You need to change those values in your for loops.

millercommamatt
 
Posts: 249
Joined: Tue Jul 31, 2018 4:57 pm

Re: LED Strip Not Showing Defined # of LEDs

by joshstern on Tue Feb 19, 2019 6:50 pm

millercommamatt wrote:Your code has 5 rows and 8 columns. 8 x 5 = 40. You need to change those values in your for loops.


Hi Matt,

Thanks for the reply! This totally worked!!

Josh

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

Re: LED Strip Not Showing Defined # of LEDs

by millercommamatt on Tue Feb 19, 2019 6:52 pm

Glad things worked out for you.

millercommamatt
 
Posts: 249
Joined: Tue Jul 31, 2018 4:57 pm

Please be positive and constructive with your questions and comments.