#include <Adafruit_NeoPixel.h>

#define PIN 7
#define NUMPIXELS 16

Adafruit_NeoPixel pixels(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);

uint8_t red = 0;
uint8_t green = 0;
uint8_t blue = 0;

void setup() {
  pixels.begin();
  pixels.show();  // Initialize all pixels to 'off'
  Serial.begin(9600);
  Serial.println("Neopixel ready. Waiting for commands...");
}

void loop() {
  if (Serial.available() > 0) {
    char command = Serial.read();
    handleCommand(command);
    updatePixels();
  }
}

void handleCommand(char command) {
  switch (command) {
    case 'L':
      red = 255;
      green = 255;
      blue = 255;
      Serial.println("Command L: All LEDs White");
      break;
    case 'O':
      red = 0;
      green = 0;
      blue = 0;
      Serial.println("Command O: All LEDs Off");
      break;
    case 'R':
      red = 255;
      green = 0;
      blue = 0;
      Serial.println("Command R: Red On");
      break;
    case 'G':
      green = 255;
      red = 0;
      blue = 0;
      Serial.println("Command G: Green On");
      break;
    case 'B':
      blue = 255;
      red = 0;
      green = 0;
      Serial.println("Command B: Blue On");
      break;
    case 'X': // Turn off red
      red = 0;
      Serial.println("Command X: Red Off");
      break;
    case 'Y': // Turn off green
      green = 0;
      Serial.println("Command Y: Green Off");
      break;
    case 'Z': // Turn off blue
      blue = 0;
      Serial.println("Command Z: Blue Off");
      break;
    default:
      Serial.println("Unknown command");
      break;
  }
}

void updatePixels() {
  for (int i = 0; i < NUMPIXELS; i++) {
    pixels.setPixelColor(i, pixels.Color(red, green, blue));
  }
  pixels.show();
}