// Pin definitions for single-color LEDs
const int LED1_PIN = 2;  // Connected to led1, controlled by pot1
const int LED2_PIN = 3;  // Connected to led2, controlled by pot2
const int LED3_PIN = 4;  // Connected to led3, turns on when both pots at max

// Pin definitions for RGB LED components
const int RGB1_R_PIN = 5;  // Red component for rgb1
const int RGB1_G_PIN = 6;  // Green component for rgb1
const int RGB1_B_PIN = 7;  // Blue component for rgb1
const int RGB2_R_PIN = 8;  // Red component for rgb2
const int RGB2_G_PIN = 9;  // Green component for rgb2
const int RGB2_B_PIN = 10; // Blue component for rgb2

// Pin definitions for potentiometers
const int POT1_PIN = A0;  // Pot1 analog input
const int POT2_PIN = A1;  // Pot2 analog input

// Threshold for considering potentiometers at max value
const int MAX_THRESHOLD = 1020;  // Slightly below 1023 to account for variations

void setup() {
  // Initialize single-color LED pins as outputs
  pinMode(LED1_PIN, OUTPUT);
  pinMode(LED2_PIN, OUTPUT);
  pinMode(LED3_PIN, OUTPUT);
  
  // Initialize RGB LED pins as outputs
  pinMode(RGB1_R_PIN, OUTPUT);
  pinMode(RGB1_G_PIN, OUTPUT);
  pinMode(RGB1_B_PIN, OUTPUT);
  pinMode(RGB2_R_PIN, OUTPUT);
  pinMode(RGB2_G_PIN, OUTPUT);
  pinMode(RGB2_B_PIN, OUTPUT);
  
  // Potentiometer pins are automatically set as inputs by analogRead
}

void loop() {
  // Read values from potentiometers (range 0-1023)
  int pot1Value = analogRead(POT1_PIN);
  int pot2Value = analogRead(POT2_PIN);
  
  // Map potentiometer values to LED brightness range (0-255)
  int led1Brightness = map(pot1Value, 0, 1023, 0, 255);
  int led2Brightness = map(pot2Value, 0, 1023, 0, 255);
  
  // Control brightness of single-color LEDs based on pot values
  analogWrite(LED1_PIN, led1Brightness);
  analogWrite(LED2_PIN, led2Brightness);
  
  // Control led3 - on only when both pots are at maximum value
  if (pot1Value >= MAX_THRESHOLD && pot2Value >= MAX_THRESHOLD) {
    digitalWrite(LED3_PIN, HIGH);
  } else {
    digitalWrite(LED3_PIN, LOW);
  }
  
  // Map potentiometer values to RGB color components
  int redComponent = map(pot1Value, 0, 1023, 0, 255);    // Red controlled by pot1
  int greenComponent = map(pot2Value, 0, 1023, 0, 255);  // Green controlled by pot2
  int blueComponent = 0;  // Blue component is off by default
  
  // If both pots are at max value, set blue to max to create white
  if (pot1Value >= MAX_THRESHOLD && pot2Value >= MAX_THRESHOLD) {
    blueComponent = 255;
  }
  
  // Apply the same color to both RGB LEDs
  // First RGB LED
  analogWrite(RGB1_R_PIN, redComponent);
  analogWrite(RGB1_G_PIN, greenComponent);
  analogWrite(RGB1_B_PIN, blueComponent);
  
  // Second RGB LED
  analogWrite(RGB2_R_PIN, redComponent);
  analogWrite(RGB2_G_PIN, greenComponent);
  analogWrite(RGB2_B_PIN, blueComponent);
  
  // Small delay to stabilize readings
  delay(10);
}
mega:SCL
mega:SDA
mega:AREF
mega:GND.1
mega:13
mega:12
mega:11
mega:10
mega:9
mega:8
mega:7
mega:6
mega:5
mega:4
mega:3
mega:2
mega:1
mega:0
mega:14
mega:15
mega:16
mega:17
mega:18
mega:19
mega:20
mega:21
mega:5V.1
mega:5V.2
mega:22
mega:23
mega:24
mega:25
mega:26
mega:27
mega:28
mega:29
mega:30
mega:31
mega:32
mega:33
mega:34
mega:35
mega:36
mega:37
mega:38
mega:39
mega:40
mega:41
mega:42
mega:43
mega:44
mega:45
mega:46
mega:47
mega:48
mega:49
mega:50
mega:51
mega:52
mega:53
mega:GND.4
mega:GND.5
mega:IOREF
mega:RESET
mega:3.3V
mega:5V
mega:GND.2
mega:GND.3
mega:VIN
mega:A0
mega:A1
mega:A2
mega:A3
mega:A4
mega:A5
mega:A6
mega:A7
mega:A8
mega:A9
mega:A10
mega:A11
mega:A12
mega:A13
mega:A14
mega:A15
led1:A
led1:C
led2:A
led2:C
led3:A
led3:C
rgb1:R
rgb1:COM
rgb1:G
rgb1:B
rgb2:R
rgb2:COM
rgb2:G
rgb2:B
pot1:VCC
pot1:SIG
pot1:GND
pot2:VCC
pot2:SIG
pot2:GND