I want to place LED lighting above my galley or to just simply use it as a nightlight, accent lighting, whatever. I have the color and brightness figured out using potentiometers but I cant figure out how to sequentially light them up with a third Pot and insert that into my loop. Working code is below.
ws2812 addressable LED waterproof lightstrip.
3 10k SPST potentiometers for color, brightness and number of LED's.
The SPST is to turn the circuit on, all in one knob, perfect. The brightness pot will be the on/off but you have to buy these pots in packages... The color pot will be for white as there is no white in rainbow spectrum.
So heres what I have planned;
60 LED's spanning 7'.
Arduino reads on analog pins a voltage ranging from 0-1023. so resistance/6=170.5
so r<=170 = 1 led (c), =>340 = 2 led's (c) and etc.
X=black
C=pot color
Aft Fwd
Stove Sink Refrigerator
1 60
data flow=>
<=170 xxxxxcxxxxxcxxxxxcxxxxxcxxxxxcxxxxxcxxxxxcxxxxxcxxxxxcxxxxxc
=>340 xxxxccxxxxccxxxxccxxxxccxxxxccxxxxxcxxxxccxxxxccxxxxccxxxxcc
=>510 xxxcccxxxcccxxxcccxxxcccxxxcccxxxcccxxxcccxxxcccxxxcccxxxccc
=>680 xxccccxxccccxxccccxxccccxxccccxxccccxxccccxxccccxxccccxxcccc
=>850 xcccccxcccccxcccccxcccccxcccccxcccccxcccccxcccccxcccccxccccc
=>980 cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
What am I doing wrong?
I still have to add the POT line, but the code as it is doesn't compile.
//
#include <Adafruit_NeoPixel.h>
// can use #include <FastLed.h>
const int STRIP_LENGTH = 60;
const int LED_STRIP_PIN = 10;
const int BRIGHTNESS_POT = A6;
const int BRIGHTNESS_SWITCH = 8;
const int COLOR_POT = A3;
const int BRIGHTNESS_SWITCH = 6;
float brightness = 0.0;
Adafruit_NeoPixel strip = Adafruit_NeoPixel(STRIP_LENGTH, LED_STRIP_PIN,
NEO_GRB + NEO_KHZ800);
void setup() {
pinMode(COLOR_POT, INPUT);
pinMode(COLOR_SWITCH, INPUT_PULLUP);
pinMode(BRIGHTNESS_POT, INPUT);
pinMode(BRIGHTNESS_SWITCH, INPUT_PULLUP);
strip.begin();
strip.show();
}
void loop() {
if (digitalRead(BRIGHTNESS_SWITCH) == HIGH) {
// Get the percentage of the full brightness.
brightness = 1.0 - (analogRead(BRIGHTNESS_POT) / 1023.0);
Serial.println(brightness);
if (digitalRead(COLOR_SWITCH) == HIGH) {
// Scale down the color range.
int color = (analogRead(COLOR_POT) / 1023.0) * 245.0;
calculateAndChangeColor(color);
} else {
// Color is disabled. Change strip to white.
changeColor(255, 255, 255);
}
} else {
changeColor(0,0,0);
}
delay(50);
}
void changeColor(int red, int green, int blue) {
int i;
for(i=0; i< strip.numPixels(); i++) {
strip.setPixelColor(i, redbrightness, greenbrightness, blue*brightness);
}
strip.show();
}
// This is based on the Adafruit NeoPixel strandtest example.
void calculateAndChangeColor(int potValue) {
int red = 0;
int green = 0;
int blue = 0;
if(potValue < 85) {
red = potValue * 3;
green = 255 - potValue * 3;
} else if(potValue < 170) {
potValue -= 85;
red = 255 - potValue * 3;
blue = potValue * 3;
} else {
potValue -= 170;
green = potValue * 3;
blue = 255 - potValue * 3;
}
changeColor(red, green, blue);
}