Can someone enlight me?
I'm working on a project of doing my own led bar for my setup.
The setup have been thought as follow:
56 leds RGB 2812B
Controlled by 4 potentiometer linear 1K Ohm one for the intensity and the 3 other respectively for Red Green and Blue.
The whole thing is connected to an arduino R3
An the leds are alimented by a 5v 3amps power supply.
On an electric plan all the thing works as intented, i've planned the whole thing on tinkercad : Login - Tinkercad
But i'm having a problem, the arduino seems to ignore the potentiometer and choose random color and brightness for the leds and the whole bar flicker as hell...
The code i use is this one:
``#include <Adafruit_NeoPixel.h>`
`#define PIN 2 // input pin Neopixel is attached to`
`#define NUMPIXELS` `56 // number of neopixels in Ring`
`Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);`
`int delayval = 1; // timing delay`
`int redColor = 0;`
`int greenColor = 0;`
`int blueColor = 0;`
`int potAngle = A0;`
`void setup() {`
`pixels.begin(); // Initializes the NeoPixel library.`
`Serial.begin(9600);`
`}`
`void loop() {`
`//get colors from potentiometers`
`getColor();`
`//initialize all colors to 'off'`
`//this line enables real-time adjustments.`
`pixels.show();`
`int val = analogRead(potAngle);`
`//this line converts the angle of potentiometer to the brightness of LEDs.`
`int brightness = map(val, 0, 1023, 0, 255);`
`Serial.print("brightness: ");`
`Serial.println(brightness);`
`//this for loop controls all the 24 LEDs every single time.`
`for (int i = 0; i < NUMPIXELS; i++) {`
`// pixels.Color takes RGB values, from 0,0,0 up to 255,255,255`
`pixels.setPixelColor(i, pixels.Color(redColor * brightness / 255, greenColor * brightness / 255, blueColor * brightness / 255));`
`//pixels.show(); // This sends the updated pixel color to the hardware.`
`}`
`pixels.show();`
`}`
`// setColor()`
`// picks random values to set for RGB`
`void setColor() {`
`redColor = random(0, 255);`
`greenColor = random(0, 255);`
`blueColor = random(0, 255);`
`Serial.print("red: ");`
`Serial.println(redColor);`
`Serial.print("green: ");`
`Serial.println(greenColor);`
`Serial.print("blue: ");`
`Serial.println(blueColor);`
`}`
`void getColor() {`
`int redAngle = analogRead(A1);`
`int greenAngle = analogRead(A2);`
`int blueAngle = analogRead(A3);`
`int rVal = map(redAngle, 0, 1023, 0, 255);`
`int gVal = map(greenAngle, 0, 1023, 0, 255);`
`int bVal = map(blueAngle, 0, 1023, 0, 255);`
`redColor = rVal;`
`greenColor = gVal;`
`blueColor = bVal;`
`Serial.print("red: ");`
`Serial.println(redColor);`
`Serial.print("green: ");`
`Serial.println(greenColor);`
`Serial.print("blue: ");`
`Serial.println(blueColor);`
`}`
`Use code tags to format code for the forum
If anyone got clues to solve the trouble i'm opne to suggestion.
