#include <Adafruit_NeoPixel.h>
#include <Adafruit_SSD1306.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
// Pin definitions
#define PIN 6 // Pin connected to NeoPixel data input
#define NUMPIXELS 1 // Number of NeoPixels (1 in this case)
// Potentiometer Pins
#define POT_RED_PIN A0
#define POT_GREEN_PIN A1
#define POT_BLUE_PIN A2
// OLED Display settings
#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 64
#define OLED_RESET -1
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
// NeoPixel object
Adafruit_NeoPixel strip = Adafruit_NeoPixel(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);
void setup() {
// Start Serial Monitor for debugging
Serial.begin(9600);
// Initialize the NeoPixel strip
strip.begin();
strip.show(); // Initialize all pixels to 'off'
// Initialize OLED
if(!display.begin(SSD1306_PAGEADDR, OLED_RESET)) {
Serial.println(F("SSD1306 allocation failed"));
for(;;);
}
display.display(); // Clear the buffer
// Display initial text
display.clearDisplay();
display.setTextSize(1);
display.setTextColor(SSD1306_WHITE);
}
void loop() {
// Read potentiometer values
int redValue = analogRead(POT_RED_PIN) / 4; // Scale to 0-255
int greenValue = analogRead(POT_GREEN_PIN) / 4;
int blueValue = analogRead(POT_BLUE_PIN) / 4;
// Set the color of the NeoPixel
strip.setPixelColor(0, redValue, greenValue, blueValue);
strip.show(); // Update the LED
// Display RGB values on OLED
display.clearDisplay();
display.setCursor(0, 0);
display.print("R: ");
display.print(redValue);
display.setCursor(0, 10);
display.print("G: ");
display.print(greenValue);
display.setCursor(0, 20);
display.print("B: ");
display.print(blueValue);
display.display(); // Update OLED
delay(50); // Short delay for smoother updates
}