#include <Adafruit_NeoPixel.h>
// Which pin on the Arduino is connected to the NeoPixels?
#define LED_PIN 6 // Connected to first NeoPixel DIN
// How many NeoPixels are attached to the Arduino?
#define NUMPIXELS 19 // 4 NeoPixels chained together
// NeoPixel library setup
Adafruit_NeoPixel pixels(NUMPIXELS, LED_PIN, NEO_GRB + NEO_KHZ800);
#define DELAYVAL 40 // Time (in milliseconds) to pause between updates (40ms ~= 25fps)
// Potentiometer pins
int RedSliderPin = A0; // Red channel slider
int GreenSliderPin = A1; // Green channel slider
int BlueSliderPin = A2; // Blue channel slider
// Sensor values
int RedSensorValue = 0;
int GreenSensorValue = 0;
int BlueSensorValue = 0;
void setup() {
Serial.begin(9600); // For debugging
pixels.begin(); // INITIALIZE NeoPixel strip object (REQUIRED)
pixels.clear(); // Set all pixels off initially
pixels.show(); // Apply the changes
Serial.println("RGB NeoPixel Controller Started!");
Serial.println("LED 0: Red Channel Only");
Serial.println("LED 1: Green Channel Only");
Serial.println("LED 2: Blue Channel Only");
Serial.println("LED 3: RGB Combination");
}
void loop() {
// Read the values from the sliders and convert to 0-255 range
RedSensorValue = analogRead(RedSliderPin) / 4; // 1023/4 = ~255
GreenSensorValue = analogRead(GreenSliderPin) / 4;
BlueSensorValue = analogRead(BlueSliderPin) / 4;
// Clear all pixels
pixels.clear();
// Set individual channel LEDs
pixels.setPixelColor(0, pixels.Color(RedSensorValue, 0, 0)); // LED 0: Red only
pixels.setPixelColor(1, pixels.Color(0, GreenSensorValue, 0)); // LED 1: Green only
pixels.setPixelColor(2, pixels.Color(0, 0, BlueSensorValue)); // LED 2: Blue only
pixels.fill(pixels.Color(RedSensorValue, GreenSensorValue, BlueSensorValue), 3, NUMPIXELS - 3);
// Send the updated pixel colors to the hardware
pixels.show();
// Debug output (optional)
Serial.print("R:"); Serial.print(RedSensorValue);
Serial.print(" G:"); Serial.print(GreenSensorValue);
Serial.print(" B:"); Serial.println(BlueSensorValue);
delay(DELAYVAL); // Pause before next pass through loop
}