Hi there!
I'm using a potentiometer to turn on LEDs in sequence on a Neopixel Ring.
Everything is going well except when I try to assign individual colour values to the LEDs.
When I do this, they do change to the correct colour, but when the potentiometer is changed and the LEDs switch on or off one by one, all the 'off' LEDs flicker on for a millisecond.
Here's the set-up:
#include <Adafruit_NeoPixel.h>
#define PIN 3
Adafruit_NeoPixel strip = Adafruit_NeoPixel(12, PIN, NEO_GRB + NEO_KHZ800);
int potPin = 2;
int val = 0;
int colorVal = 0;
int reading = 0;
int x;
int prevVal = 0;
int switchPin = 6;
boolean lastBtn = LOW;
boolean NeopixelColor = false;
boolean lastButton = LOW;
void setup() {
// put your setup code here, to run once:
strip.begin();
strip.show();
pinMode(switchPin, INPUT);
}
void loop() {
// put your main code here, to run repeatedly:
reading = analogRead(potPin);
val = (reading/1024.0) * 13;
colorVal = (reading/1024.0) * 255;
if (digitalRead(switchPin) == HIGH && lastButton == LOW)
{
delay(250); // Account for contact debounce
NeopixelColor = !NeopixelColor;
}
if (NeopixelColor == true)
{
// Neopixel LED number code
strip.setBrightness(10);
if (val != prevVal)
{
for ( x = 0; x < val; x++)
{
strip.setPixelColor(x,255,0,255);
strip.setPixelColor(1,colorVal,0,255,255);
strip.setPixelColor(2,colorVal,0,0,255);
strip.setPixelColor(3,colorVal,255,0,255);
strip.setPixelColor(4,colorVal,0,255,255);
strip.setPixelColor(5,colorVal,0,255,255);
strip.setPixelColor(6,colorVal,0,255,255);
strip.setPixelColor(7,colorVal,0,0,255);
strip.setPixelColor(8,colorVal,0,255,255);
strip.setPixelColor(9,colorVal,0,255,255);
strip.setPixelColor(10,colorVal,0,0,0);
strip.setPixelColor(11,colorVal,0,0,0);
strip.setPixelColor(12,colorVal,0,0,0);
}
for (x=val; x<13; x++)
{
strip.setPixelColor(x,0,0,0);
strip.show();
}
prevVal = val;
}
else
{
strip.show();
}
}
else
{
// Neopixel Color code
for (x=255; x < prevVal; x++)
{
strip.setPixelColor(x,colorVal,0,0-colorVal);
strip.show();
}
}
}
I really hope someone can help- it's driving me mad!
(Ignore the switch nonsense, it's leftover from a previous project.)
