So I'm trying to make a "volume" control by turning a pot, resulting in a Neopixel strip lighting up and down from blue to red, I made the pixels light up in one color (blue) but I don't know how to map colors from blue to red across the led's, so that it starts blue, and end in red with smooth transition between the colors.
My code so far:
#include <Adafruit_NeoPixel.h>
#include <avr/power.h>
#define PIN 6
int const potPin = A0; //potentiometer input
int potVal; //variable to store the input from the potentiometer
int number; //variable to store number of LED's
// Parameter 1 = number of pixels in strip
// Parameter 2 = Arduino pin number (most are valid)
// Parameter 3 = pixel type flags, add together as needed:
// NEO_KHZ800 800 KHz bitstream (most NeoPixel products w/WS2812 LEDs)
// NEO_GRB Pixels are wired for GRB bitstream (most NeoPixel products)
Adafruit_NeoPixel strip = Adafruit_NeoPixel(9, PIN, NEO_GRB + NEO_KHZ800);
void setup() {
Serial.begin(9600);
strip.begin(); // Start LED Strip
strip.show(); // Initialize all pixels to 'off'
}
void loop() {
uint8_t ledPin[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
uint32_t color = strip.Color(0, 0, 200);
potVal = analogRead(potPin);
for (int i = 0; i < 9; i++) {
if( potVal < 20 ) { strip.setPixelColor(ledPin[0], color);}
else
{strip.setPixelColor(ledPin[0], 0);}
if( (i * 116) > potVal) { strip.setPixelColor(ledPin[i], color);}
else
{ strip.setPixelColor(ledPin[i], 0);}
strip.show();
}
}
As you can see I have only the blue color right now.