Due to high demand expect some shipping delays at this time, orders may not ship for 1-2 business days.
0

Neopixel LED strip modified code from zelda sword project
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Neopixel LED strip modified code from zelda sword project

by dre_force on Thu Oct 14, 2021 9:17 pm

trying to modify some code for the zelda sword project to suit the led strip i have.

the original project calls for 2m led strip, i only have a meter which has 144 leds.

when i use the original code a bunch of leds on the end of the strip dont light up i get the first 14 show as orange the next lot show blue and then some more on the end show as orange and a bunch of strips are on the end dont light up at all.

i modified the code so that the first 21 show up as orange and the rest as blue but again it wont activate a bunch of leds at the end of the strip.

any suggestion. i have included the original code below. would also be great to reduce the time delay from sliding the switch to the leds lighting up.

Code: Select all | TOGGLE FULL SIZE
// SPDX-FileCopyrightText: 2018 Mikey Sklar for Adafruit Industries
//
// SPDX-License-Identifier: MIT

#include <Adafruit_NeoPixel.h>
#ifdef __AVR__
  #include <avr/power.h>
#endif

// Which pin on the Arduino is connected to the NeoPixels?
// On a Trinket or Gemma we suggest changing this to 1
#define PIN            4

// Color Segments
#define APIXELS      14 // number of first orange pixels
#define BPIXELS      84 // number of blue pixels
#define CPIXELS      93 // second orange pixels

// When we setup the NeoPixel library, we tell it how many pixels, and which pin to use to send signals.
// Note that for older NeoPixel strips you might need to change the third parameter--see the strandtest
// example for more information on possible values.
Adafruit_NeoPixel pixels = Adafruit_NeoPixel(93, PIN, NEO_GRB + NEO_KHZ800);

int delayval = 10; // delay for half a second

void setup() {
  // This is for Trinket 5V 16MHz, you can remove these three lines if you are not using a Trinket
#if defined (__AVR_ATtiny85__)
  if (F_CPU == 16000000) clock_prescale_set(clock_div_1);
#endif
  // End of trinket special code

  pixels.begin(); // This initializes the NeoPixel library.
}

void loop() {

  // For the first 14 pixels, make them orange, starting from pixel number 0.
  for(int i=0;i<APIXELS;i++){
    pixels.setPixelColor(i, pixels.Color(255,50,0)); // Set Pixels to Orange Color
    pixels.show(); // This sends the updated pixel color to the hardware.
    delay(delayval); // Delay for a period of time (in milliseconds).
  }

  // Fill up 84 pixels with blue, starting with pixel number 14.
  for(int i=14;i<BPIXELS;i++){
    pixels.setPixelColor(i, pixels.Color(0,250,200)); // Set Pixels to Blue Color
    pixels.show(); // This sends the updated pixel color to the hardware.
    delay(delayval); // Delay for a period of time (in milliseconds).

  }
 
  // Fill up 9 pixels with orange, starting from pixel number 84.
  for(int i=84;i<CPIXELS;i++){
    pixels.setPixelColor(i, pixels.Color(250,50,0)); //Set Pixels to Orange Color
    pixels.show(); // This sends the updated pixel color to the hardware.
    delay(delayval); // Delay for a period of time (in milliseconds).
  }
}
Last edited by adafruit_support_carter on Mon Oct 18, 2021 1:24 pm, edited 1 time in total.
Reason: added [code] tags

dre_force
 
Posts: 16
Joined: Thu Oct 14, 2021 9:08 pm

Re: Neopixel LED strip modified code from zelda sword projec

by dastels on Fri Oct 15, 2021 10:39 am

To use all 144 pixels you need to instantiate the NeoPixel object for 144 pixels.
Code: Select all | TOGGLE FULL SIZE
Adafruit_NeoPixel pixels = Adafruit_NeoPixel(93, PIN, NEO_GRB + NEO_KHZ800);

is instantiating it for 93 pixels. It is ignoring any beyond that number. Change that 93 to 144 to have it use all the pixels.

Dave

dastels
 
Posts: 7906
Joined: Tue Oct 20, 2015 3:22 pm

Re: Neopixel LED strip modified code from zelda sword projec

by dre_force on Sat Oct 16, 2021 6:48 pm

Thanks for the reply Dave, Ive posted below the modified code i tried before posting this as you can see i tried changing this number but when i did this nothing happened as in no leds lit up at all. i will try again but am quite sure i tried it multiple times the other day.

modified code -

Code: Select all | TOGGLE FULL SIZE
// SPDX-FileCopyrightText: 2018 Mikey Sklar for Adafruit Industries

//

// SPDX-License-Identifier: MIT



#include <Adafruit_NeoPixel.h>

#ifdef __AVR__

  #include <avr/power.h>

#endif



// Which pin on the Arduino is connected to the NeoPixels?

// On a Trinket or Gemma we suggest changing this to 1

#define PIN            4



// Color Segments

#define APIXELS      21 // number of first orange pixels

#define BPIXELS      110 // number of blue pixels

#define CPIXELS      13 // second orange pixels



// When we setup the NeoPixel library, we tell it how many pixels, and which pin to use to send signals.

// Note that for older NeoPixel strips you might need to change the third parameter--see the strandtest

// example for more information on possible values.

Adafruit_NeoPixel pixels = Adafruit_NeoPixel(144, PIN, NEO_GRB + NEO_KHZ800);



int delayval = 10; // delay for half a second



void setup() {

  // This is for Trinket 5V 16MHz, you can remove these three lines if you are not using a Trinket

#if defined (__AVR_ATtiny85__)

  if (F_CPU == 16000000) clock_prescale_set(clock_div_1);

#endif

  // End of trinket special code



  pixels.begin(); // This initializes the NeoPixel library.

}



void loop() {



  // For the first 21 pixels, make them orange, starting from pixel number 0.

  for(int i=0;i<APIXELS;i++){

    pixels.setPixelColor(i, pixels.Color(255,50,0)); // Set Pixels to Orange Color

    pixels.show(); // This sends the updated pixel color to the hardware.

    delay(delayval); // Delay for a period of time (in milliseconds).

  }



  // Fill up 110 pixels with blue, starting with pixel number 21.

  for(int i=21;i<BPIXELS;i++){

    pixels.setPixelColor(i, pixels.Color(0,250,200)); // Set Pixels to Blue Color

    pixels.show(); // This sends the updated pixel color to the hardware.

    delay(delayval); // Delay for a period of time (in milliseconds).



  }

 

  // Fill up 13 pixels with orange, starting from pixel number 131.

  for(int i=131;i<CPIXELS;i++){

    pixels.setPixelColor(i, pixels.Color(250,50,0)); //Set Pixels to Orange Color

    pixels.show(); // This sends the updated pixel color to the hardware.

    delay(delayval); // Delay for a period of time (in milliseconds).

  }

}

dre_force
 
Posts: 16
Joined: Thu Oct 14, 2021 9:08 pm

Re: Neopixel LED strip modified code from zelda sword projec

by dastels on Sat Oct 16, 2021 11:13 pm

One problem I see is in your for loops. Here;s the orage (I believe the same problem is in the blue one):
Code: Select all | TOGGLE FULL SIZE
 for(int i=131;i<CPIXELS;i++)

I believe the limit should be 131 + CPIXELS As CPIXELS, BPIXELS, etc are the number of pixels, not the index of the last one in the group.

Dave

dastels
 
Posts: 7906
Joined: Tue Oct 20, 2015 3:22 pm

Re: Neopixel LED strip modified code from zelda sword projec

by dre_force on Sun Oct 17, 2021 5:51 am

Appreciate the response Dave, not having much luck. When i change the 93 number to anything 144 no LEDs light up. Even if i remove the B and C pixels and just try and fill the strip with the one colour. ive recharged the battery and will try again as i was getting some random results from the low battery. blue was turning green and such. also if you could clarify what you mean by the your statement "i belive the limit should be 131 + CPIXELS ... etc are the number of pixels, not the index of the last one in the group."

Also ive noted in the code it says - :Note that for older NeoPixel strips you might need to change the third parameter--see the strandtest
// example for more information on possible values."

do you know what this ment by this.

who would have thought getting leds to light up would be so hard.

Thanks again.
Attachments
zelda.jpg
zelda.jpg (220.56 KiB) Viewed 126 times

dre_force
 
Posts: 16
Joined: Thu Oct 14, 2021 9:08 pm

Re: Neopixel LED strip modified code from zelda sword projec

by dre_force on Sun Oct 17, 2021 5:56 am

results of original code
Attachments
IMG_20211017_205317.jpeg
IMG_20211017_205317.jpeg (232.48 KiB) Viewed 126 times

dre_force
 
Posts: 16
Joined: Thu Oct 14, 2021 9:08 pm

Re: Neopixel LED strip modified code from zelda sword projec

by dastels on Sun Oct 17, 2021 9:27 am

The original code specifies 93 pixels so it will never light up more than that.

The APIXELS, BPIXELS, and CPIXELS in the original code are the index of the last pixel in each group. In your code they are the number of pixels in each ground. For example, your second orang loop is equivalent to
Code: Select all | TOGGLE FULL SIZE
for (int i = 131; i < 13; i++)

So the loop never loops because i starts out greater than 13.

Since the original code worked, the erd argument to the NeoPixel constructor is correct. Some NeoPixels have R, G, and B is a different order. and expect a control signal a different frequency. That's hat the 3rd argument is for.

I find it useful to have the circuit attached to USB for power when working on the code. That will eliminate battery issues as a source of problems. Once you know everything works, then you can deal with battery powering it.

Dave

dastels
 
Posts: 7906
Joined: Tue Oct 20, 2015 3:22 pm

Re: Neopixel LED strip modified code from zelda sword projec

by dre_force on Sun Oct 17, 2021 7:05 pm

Code: Select all | TOGGLE FULL SIZE
// SPDX-FileCopyrightText: 2018 Mikey Sklar for Adafruit Industries
//
// SPDX-License-Identifier: MIT

#include <Adafruit_NeoPixel.h>
#ifdef __AVR__
  #include <avr/power.h>
#endif

// Which pin on the Arduino is connected to the NeoPixels?
// On a Trinket or Gemma we suggest changing this to 1
#define PIN            4

// Color Segments
#define APIXELS      21 // number of first orange pixels
#define BPIXELS      110 // number of blue pixels
#define CPIXELS      13 // second orange pixels

// When we setup the NeoPixel library, we tell it how many pixels, and which pin to use to send signals.
// Note that for older NeoPixel strips you might need to change the third parameter--see the strandtest
// example for more information on possible values.
Adafruit_NeoPixel pixels = Adafruit_NeoPixel(144, PIN, NEO_GRB + NEO_KHZ800);

int delayval = 10; // delay for half a second

void setup() {
  // This is for Trinket 5V 16MHz, you can remove these three lines if you are not using a Trinket
#if defined (__AVR_ATtiny85__)
  if (F_CPU == 16000000) clock_prescale_set(clock_div_1);
#endif
  // End of trinket special code

  pixels.begin(); // This initializes the NeoPixel library.
}

void loop() {

  // For the first 21 pixels, make them orange, starting from pixel number 0.
  for(int i=0;i<APIXELS;i++){
    pixels.setPixelColor(i, pixels.Color(255,50,0)); // Set Pixels to Orange Color
    pixels.show(); // This sends the updated pixel color to the hardware.
    delay(delayval); // Delay for a period of time (in milliseconds).
  }

  // Fill up 110 pixels with blue, starting with pixel number 21.
  for(int i=110;i<BPIXELS;i++){
    pixels.setPixelColor(i, pixels.Color(0,250,200)); // Set Pixels to Blue Color
    pixels.show(); // This sends the updated pixel color to the hardware.
    delay(delayval); // Delay for a period of time (in milliseconds).

  }
 
  // Fill up 13 pixels with orange, starting from pixel number 131.
  for(int i=13;i<CPIXELS;i++){
    pixels.setPixelColor(i, pixels.Color(250,50,0)); //Set Pixels to Orange Color
    pixels.show(); // This sends the updated pixel color to the hardware.
    delay(delayval); // Delay for a period of time (in milliseconds).
  }
}
Last edited by adafruit_support_carter on Mon Oct 18, 2021 1:23 pm, edited 1 time in total.
Reason: added [code] tags

dre_force
 
Posts: 16
Joined: Thu Oct 14, 2021 9:08 pm

Re: Neopixel LED strip modified code from zelda sword projec

by dre_force on Mon Oct 18, 2021 2:14 am

this is the error message i get when loading this modified code
Attachments
Screen Shot 2021-10-18 at 1.01.10 pm.png
Screen Shot 2021-10-18 at 1.01.10 pm.png (151.13 KiB) Viewed 108 times

dre_force
 
Posts: 16
Joined: Thu Oct 14, 2021 9:08 pm

Re: Neopixel LED strip modified code from zelda sword projec

by dastels on Mon Oct 18, 2021 8:12 am

I've never seen that one. I'll see what I can find out.

Dave

dastels
 
Posts: 7906
Joined: Tue Oct 20, 2015 3:22 pm

Re: Neopixel LED strip modified code from zelda sword projec

by adafruit2 on Mon Oct 18, 2021 11:29 am

what board are you using? a trinket 5V?

adafruit2
Site Admin
 
Posts: 20356
Joined: Fri Mar 11, 2005 7:36 pm

Re: Neopixel LED strip modified code from zelda sword projec

by dre_force on Mon Oct 18, 2021 4:58 pm

yes trinket 5v

dre_force
 
Posts: 16
Joined: Thu Oct 14, 2021 9:08 pm

Re: Neopixel LED strip modified code from zelda sword projec

by dre_force on Mon Oct 18, 2021 6:08 pm

// SPDX-FileCopyrightText: 2018 Mikey Sklar for Adafruit Industries
//
// SPDX-License-Identifier: MIT

#include <Adafruit_NeoPixel.h>
#ifdef __AVR__
#include <avr/power.h>
#endif

// Which pin on the Arduino is connected to the NeoPixels?
// On a Trinket or Gemma we suggest changing this to 1
#define PIN 4

// Color Segments
#define APIXELS 21 // number of first orange pixels
#define BPIXELS 110 // number of blue pixels
#define CPIXELS 13 // second orange pixels

// When we setup the NeoPixel library, we tell it how many pixels, and which pin to use to send signals.
// Note that for older NeoPixel strips you might need to change the third parameter--see the strandtest
// example for more information on possible values.
Adafruit_NeoPixel pixels = Adafruit_NeoPixel(144, PIN, NEO_GRB + NEO_KHZ800);

int delayval = 10; // delay for half a second

void setup() {
// This is for Trinket 5V 16MHz, you can remove these three lines if you are not using a Trinket
#if defined (__AVR_ATtiny85__)
if (F_CPU == 16000000) clock_prescale_set(clock_div_1);
#endif
// End of trinket special code

pixels.begin(); // This initializes the NeoPixel library.
}

void loop() {

// For the first 21 pixels, make them orange, starting from pixel number 0
for(int i=0;i<APIXELS;i++){
pixels.setPixelColor(i, pixels.Color(255,50,0)); // Set Pixels to Orange Color
pixels.show(); // This sends the updated pixel color to the hardware.
delay(delayval); // Delay for a period of time (in milliseconds).
}

// Fill up 110 pixels with blue, starting with pixel number 21.
for(int i=110;i<BPIXELS;i++){
pixels.setPixelColor(i, pixels.Color(0,250,200)); // Set Pixels to Blue Color
pixels.show(); // This sends the updated pixel color to the hardware.
delay(delayval); // Delay for a period of time (in milliseconds).

}

// Fill up 13 pixels with orange, starting from pixel number 131.
for(int i=13;i<CPIXELS;i++){
pixels.setPixelColor(i, pixels.Color(250,50,0)); //Set Pixels to Orange Color
pixels.show(); // This sends the updated pixel color to the hardware.
delay(delayval); // Delay for a period of time (in milliseconds).
}
}

dre_force
 
Posts: 16
Joined: Thu Oct 14, 2021 9:08 pm

Re: Neopixel LED strip modified code from zelda sword projec

by dre_force on Mon Oct 18, 2021 6:09 pm

Managed to load the code above with no error message but when i test no leds light up at all.

dre_force
 
Posts: 16
Joined: Thu Oct 14, 2021 9:08 pm

Re: Neopixel LED strip modified code from zelda sword projec

by dastels on Mon Oct 18, 2021 8:29 pm

First, consider upgrading to a Trinket M0. The older Trinket models are known to have problems with more modern USB implementations. There's a warning to that effect on the product page.

Secondly, your for loops are still incorrect. Please reread my previous responses regarding the code.

Dave

dastels
 
Posts: 7906
Joined: Tue Oct 20, 2015 3:22 pm

Please be positive and constructive with your questions and comments.