Neopixels don't turn off

Post here about your Arduino projects, get help - for Adafruit customers!

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
Paschke
 
Posts: 2
Joined: Wed Jul 02, 2014 9:23 pm

Neopixels don't turn off

Post by Paschke »

Setup:
iMac (2006)
Arduino Leonardo (USB powered)
NeoPixel Sticks (x4) wired in series (Externally powered 5v @ 3A)

The principle of this sketch is that when a button if pushed, the LEDs light up for a specified amount of time and then simply turn off. (There is more to it, but this is the part that I can't seem to get to co-operate)
The issue that I am having is that most of the time, LEDs 12-31 will not turn off. They require the external power to be removed and the Arduino to be reset.
On other occations, LEDs 12-31 will not turn on when triggered, but every time LEDs 0-12 behave the way one would expect.
It does work correctly occasionally, which is what does not make any sense to me.

I am extremely new to programming and building these types of apparatuses.
I would also assume that there is an easier way to assign all of the LEDs if they are all to show the same thing.

Unfortunately, I cannot take a picture of my setup as it is 100mi away at the moment, but I don't have internet access where it currently is.
Any ideas would be greatly appreciated.

Code: Select all

#include <Adafruit_NeoPixel.h>

#define LED 12
Adafruit_NeoPixel strip = Adafruit_NeoPixel(32, LED, NEO_GRB + NEO_KHZ800);

void setup(){
  
  // initialize led strips:
  strip.begin();
  // initialize all pixels to 'off':
  strip.show();
}
void loop(){
  // if the button has been pushed:
  while (digitalRead(BUTTON) ==HIGH){
    // do nothing until "BUTTON" goes low:
    delay(50);
  }
  delay(50);

   // turn on leds:
  strip.setPixelColor(0, 175, 175, 75);
  strip.setPixelColor(1, 175, 175, 75);
  strip.setPixelColor(2, 175, 175, 75);
  strip.setPixelColor(3, 175, 175, 75);
  strip.setPixelColor(4, 175, 175, 75);
  strip.setPixelColor(5, 175, 175, 75);
  strip.setPixelColor(6, 175, 175, 75);
  strip.setPixelColor(7, 175, 175, 75);
  strip.setPixelColor(8, 175, 175, 75);
  strip.setPixelColor(9, 175, 175, 75);
  strip.setPixelColor(10, 175, 175, 75);
  strip.setPixelColor(11, 175, 175, 75);
  strip.setPixelColor(12, 175, 175, 75);
  strip.setPixelColor(13, 175, 175, 75);
  strip.setPixelColor(14, 175, 175, 75);
  strip.setPixelColor(15, 175, 175, 75);
  strip.setPixelColor(16, 175, 175, 75);
  strip.setPixelColor(17, 175, 175, 75);
  strip.setPixelColor(18, 175, 175, 75);
  strip.setPixelColor(19, 175, 175, 75);
  strip.setPixelColor(20, 175, 175, 75);
  strip.setPixelColor(21, 175, 175, 75);
  strip.setPixelColor(22, 175, 175, 75);
  strip.setPixelColor(23, 175, 175, 75);
  strip.setPixelColor(24, 175, 175, 75);
  strip.setPixelColor(25, 175, 175, 75);
  strip.setPixelColor(26, 175, 175, 75);
  strip.setPixelColor(27, 175, 175, 75);
  strip.setPixelColor(28, 175, 175, 75);
  strip.setPixelColor(29, 175, 175, 75);
  strip.setPixelColor(30, 175, 175, 75);
  strip.setPixelColor(31, 175, 175, 75);
  strip.show();
  delay(75);

  // wait
  delay(36000);

   // turn off leds:
  strip.setPixelColor(0, 0, 0, 0);
  strip.setPixelColor(1, 0, 0, 0);
  strip.setPixelColor(2, 0, 0, 0);
  strip.setPixelColor(3, 0, 0, 0);
  strip.setPixelColor(4, 0, 0, 0);
  strip.setPixelColor(5, 0, 0, 0);
  strip.setPixelColor(6, 0, 0, 0);
  strip.setPixelColor(7, 0, 0, 0);
  strip.setPixelColor(8, 0, 0, 0);
  strip.setPixelColor(9, 0, 0, 0);
  strip.setPixelColor(10, 0, 0, 0);
  strip.setPixelColor(11, 0, 0, 0);
  strip.setPixelColor(12, 0, 0, 0);
  strip.setPixelColor(13, 0, 0, 0);
  strip.setPixelColor(14, 0, 0, 0);
  strip.setPixelColor(15, 0, 0, 0);
  strip.setPixelColor(16, 0, 0, 0);
  strip.setPixelColor(17, 0, 0, 0);
  strip.setPixelColor(18, 0, 0, 0);
  strip.setPixelColor(19, 0, 0, 0);
  strip.setPixelColor(20, 0, 0, 0);
  strip.setPixelColor(21, 0, 0, 0);
  strip.setPixelColor(22, 0, 0, 0);
  strip.setPixelColor(23, 0, 0, 0);
  strip.setPixelColor(24, 0, 0, 0);
  strip.setPixelColor(25, 0, 0, 0);
  strip.setPixelColor(26, 0, 0, 0);
  strip.setPixelColor(27, 0, 0, 0);
  strip.setPixelColor(28, 0, 0, 0);
  strip.setPixelColor(29, 0, 0, 0);
  strip.setPixelColor(30, 0, 0, 0);
  strip.setPixelColor(31, 0, 0, 0);
  strip.show();
}

User avatar
adafruit_support_mike
 
Posts: 67485
Joined: Thu Feb 11, 2010 2:51 pm

Re: Neopixels don't turn off

Post by adafruit_support_mike »

The code to make things smaller looks like this:

Code: Select all

void setStripTo( uint8_t r, uint8_t g, uint8_t b ) {
    for ( int i=0 ; i < strip.numPixels() ; i++ ) {
        strip.setPixelColor( i, r, g, b );
    }
    strip.show();
}


void loop(){
  // if the button has been pushed:
  while (digitalRead(BUTTON) ==HIGH){
    // do nothing until "BUTTON" goes low:
    delay(50);
  }
  delay(50);

  setStripTo( 175, 175, 175 );
  delay( 36000 );
  setStripTo( 0, 0, 0 );
}
The 'for()' statement loops over the same piece of code many times, setting the value of 'i' to a different number every time.

If you're having problems with the display in the middle of a string, I'd be inclined to think there's some kind of hardware problem.

Try dropping the data rate from 800kHz to 400kHz. See if that makes the data transmission work better.

Paschke
 
Posts: 2
Joined: Wed Jul 02, 2014 9:23 pm

Re: Neopixels don't turn off

Post by Paschke »

Great! Thanks Mike.
I will try that this weekend.

Locked
Please be positive and constructive with your questions and comments.

Return to “Arduino”