NeoPixel Flicker

EL Wire/Tape/Panels, LEDs, pixels and strips, LCDs and TFTs, etc products from Adafruit

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
Barry914
 
Posts: 448
Joined: Sun Dec 08, 2013 1:26 pm

NeoPixel Flicker

Post by Barry914 »

I wrote some test code for a Flora to light up varying numbers of pixels on a NeoPixel ring. The code works, but the pixels flicker. Is there an optimum refresh rate that minimizes flicker and still has reasonable response time?

Code: Select all

#include <Adafruit_NeoPixel.h>

#define pixelPin 12
#define STRIPLEN 16
#define sensorPin 9

Adafruit_NeoPixel ring = Adafruit_NeoPixel(STRIPLEN, pixelPin, NEO_GRB + NEO_KHZ800);

void setup() 
{
  ring.begin();
  ring.show(); // Initialize all pixels to 'off'
  pinMode(pixelPin, OUTPUT);
  ring.setBrightness(60);
}

void loop()
{
  uint32_t color  = 0xfd9100;  // yellow
  int i;

  int sensorValue = analogRead(sensorPin);
  int ledValue = map(sensorValue, 0, 1023, 0, 15);
  for (i = 0; i < ledValue + 1; i++)
  {
    ring.setPixelColor(i, color);
  }
  ring.show();
  delay(20);
  for (i = 0; i < ledValue + 1; i++)
  {
    ring.setPixelColor(i, 0);
  }
  ring.show();
}
  

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

Re: NeoPixel Flicker

Post by adafruit_support_mike »

In general, you want a refresh rate close to 50Hz. Below 50Hz you can start to see flicker. Above 50Hz you don't see much change, so you need some other reason to justify a higher refresh rate.

User avatar
Barry914
 
Posts: 448
Joined: Sun Dec 08, 2013 1:26 pm

Re: NeoPixel Flicker

Post by Barry914 »

I cut the delay to 10 ms and it doesn't seem to make a bit of difference. Is there something wrong with my code?

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

Re: NeoPixel Flicker

Post by adafruit_support_mike »

The first for() loop turns the pixel on, then the second shuts it off again. Try this:

Code: Select all

for (i=0 ; i < STRIPLEN ; i++) {
	if ( i == ledvalue ) {
		ring.setPixelColor( i, color );
	} else {
		ring.setPixelColor( i, 0 );
	}
}
ring.show();

User avatar
Barry914
 
Posts: 448
Joined: Sun Dec 08, 2013 1:26 pm

Re: NeoPixel Flicker

Post by Barry914 »

The code turns on a number of LEDs, then waits a bit, turns them off and repeats with a possible change in the number of LEDs to be turned on. The code you suggested doesn't do that. Also, with no delay between turning them on and off the pixels are erratic. I could hold off turning them off if value of val has not changed since the last iteration, but I didn't think I needed to do that.

More importantly, what do I do about not being able to program my Gemmas? It's very frustrating to be just sitting on these things and not being able to use them. See http://forums.adafruit.com/viewtopic.php?f=24&t=47838

User avatar
pocketmoon
 
Posts: 78
Joined: Fri Dec 27, 2013 8:21 pm

Re: NeoPixel Flicker

Post by pocketmoon »

Hi,

I think you just need to remove the second ring.show. You want to set them to off but you don't need to actually 'flush' that through to the LED's.

Rob

User avatar
Barry914
 
Posts: 448
Joined: Sun Dec 08, 2013 1:26 pm

Re: NeoPixel Flicker

Post by Barry914 »

Ouch! (slaps himself in the head) Yeah, why am I actually turning them off? Thanks pocketmoon.

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

Return to “Glowy things (LCD, LED, TFT, EL) purchased at Adafruit”