#define RED_PIN 0
#define GREEN_PIN 4
#define BLUE_PIN 1
// Function prototypes
void updateLEDs(int potValue);
void setup() {
  // Set the RGB LED pins as OUTPUT
  pinMode(RED_PIN, OUTPUT);
  pinMode(GREEN_PIN, OUTPUT);
  pinMode(BLUE_PIN, OUTPUT);
}
void loop() {
  // Read analog value from potentiometer
  int potValue = analogRead(A3);
  // Map the analog value to HSV range (0-255)
  int hue = map(potValue, 0, 1023, 0, 255);
  // Update RGB LEDs based on the mapped HSV value
  updateLEDs(hue);
  // Add a delay to avoid rapid changes
  delay(100);
}
void updateLEDs(int hue) {
  // Convert HSV to RGB
  float h = hue / 255.0;
  float s = 1.0;
  float v = 1.0;
  int r, g, b;
  int i = int(h * 6);
  float f = h * 6 - i;
  float p = v * (1 - s);
  float q = v * (1 - f * s);
  float t = v * (1 - (1 - f) * s);
  switch (i % 6) {
    case 0: r = v * 255, g = t * 255, b = p * 255; break;
    case 1: r = q * 255, g = v * 255, b = p * 255; break;
    case 2: r = p * 255, g = v * 255, b = t * 255; break;
    case 3: r = p * 255, g = q * 255, b = v * 255; break;
    case 4: r = t * 255, g = p * 255, b = v * 255; break;
    case 5: r = v * 255, g = p * 255, b = q * 255; break;
  }
  // Update the RGB LEDs with the calculated values
  analogWrite(RED_PIN, r);
  analogWrite(GREEN_PIN, g);
  analogWrite(BLUE_PIN, b);
}