Hi,
So I'm making an RGB LED Strip (5m) that has two mode: music reactive and knob-controlled colour. However my issue is with the knobs.
I have four knobs (10k potentiometers), one for Red, Green, Blue and brightness. The code works fine with when I use half of the LED strip, the colours are accurate and the brightness control works. However, when I see the full length of the strip, I start getting strange discolourations on the pixels on the end-side of the strip. This discolouration disappears if I either turn down the brightness, use only one colour at a time or use less pixels on the strip.
My PSU is rated at 12V and 10A. I am using an Arduino Mega 2560.
Below is a cleaned up version of my code used to control the colours with potentiometers (I'm using the Adafruit Neopixel library):
#include <Adafruit_NeoPixel.h>
#ifdef __AVR__
#include <avr/power.h>
#endif
#define LED_PIN A4
#define LED_TOTAL 43
#define KNOB_PIN A5 //Potentiometer for brightness control
float knob = 1023.0; //Holds the percentage of how twisted the trimpot is. Used for adjusting the max brightness.
int pot1 = A0;
int pot2 = A1;
int pot3 = A2;
int red;
int green;
int blue;
Adafruit_NeoPixel strip(LED_TOTAL, LED_PIN, NEO_BRG + NEO_KHZ800);
Adafruit_NeoPixel strand = Adafruit_NeoPixel(LED_TOTAL, LED_PIN, NEO_GRB + NEO_KHZ800); //LED strand objetcs
void setup() {
strip.clear(); //Clear any previous patterns on strip
strand.begin(); //Initialize the LED strand object.
strand.show(); //Show a blank strand, just to get the LEDs ready for use.
}
void loop() {
knob = analogRead(KNOB_PIN) / 1023.0; //Record how far the trimpot is twisted as a fraction of 1023
red = analogRead(pot1);
green = analogRead(pot2);
blue = analogRead(pot3);
int potVal1 = (red / 4) * knob; //Potentiometer LED strip take colour values from 0 to 255
int potVal2 = (green / 4) * knob; //so divide 1023 from the pot. by 4 to get approximately 255
int potVal3 = (blue / 4) * knob;
strip.setPixelColor(0, potVal1, potVal2, potVal3); //make LED #0 the colour created by potentiometers
uint32_t color = strip.getPixelColor(0); //assigned this colour to the variable 'color'
strip.fill(color, 0, LED_TOTAL); //fill in entire LED strip with this colour
strip.show(); //execute fill across all pixels
}