#include <Adafruit_NeoPixel.h>
#define LED_PIN 2
#define NUM_LEDS 1
Adafruit_NeoPixel strip(NUM_LEDS, LED_PIN, NEO_GRB + NEO_KHZ800);
void setup() {
Serial.begin(115200);
strip.begin();
strip.show(); // Initialize LED to 'off'
Serial.println("Ready. Send color name (e.g., red, green, blue).");
}
void loop() {
if (Serial.available()) {
String input = Serial.readStringUntil('\n');
input.trim();
uint32_t color = parseColor(input);
strip.setPixelColor(0, color);
strip.show();
Serial.print("LED set to ");
Serial.println(input);
}
}
uint32_t parseColor(String color) {
color.toLowerCase();
if (color == "red") return strip.Color(255, 0, 0);
if (color == "green") return strip.Color(0, 255, 0);
if (color == "blue") return strip.Color(0, 0, 255);
if (color == "yellow") return strip.Color(255, 255, 0);
if (color == "cyan") return strip.Color(0, 255, 255);
if (color == "magenta") return strip.Color(255, 0, 255);
if (color == "white") return strip.Color(255, 255, 255);
if (color == "off") return strip.Color(0, 0, 0);
return strip.Color(0, 0, 0); // Default to 'off'
}