// Constants for pins
const int potPin1 = A0; // Potentiometer 1 input pin
const int potPin2 = A1; // Potentiometer 2 input pin
const int potPin3 = A2; // Potentiometer 3 input pin
const int ledPin1 = 2; // LED 1 output pin
const int ledPin2 = 3; // LED 2 output pin
// LED bar graph pins (Arduino pins 4-13)
const int barGraphSize = 10;
const int barGraphStartPin = 4;
int barGraphPins[barGraphSize];
void setup() {
// Initialize LED pins as outputs
pinMode(ledPin1, OUTPUT);
pinMode(ledPin2, OUTPUT);
// Initialize LED bar graph pins as outputs
for (int i = 0; i < barGraphSize; i++) {
barGraphPins[i] = barGraphStartPin + i;
pinMode(barGraphPins[i], OUTPUT);
}
// Turn off all LEDs initially
analogWrite(ledPin1, 0);
analogWrite(ledPin2, 0);
for (int i = 0; i < barGraphSize; i++) {
digitalWrite(barGraphPins[i], LOW);
}
}
void loop() {
// Read values from potentiometers (0-1023)
int potValue1 = analogRead(potPin1);
int potValue2 = analogRead(potPin2);
int potValue3 = analogRead(potPin3);
// Map potentiometer values for LED brightness (0-255)
int brightnessLed1 = map(potValue1, 0, 1023, 0, 255);
int brightnessLed2 = map(potValue2, 0, 1023, 0, 255);
// Map potentiometer value for LED bar graph segments (0-10)
int barSegments = map(potValue3, 0, 1023, 0, 10);
// Set LED brightness using PWM
analogWrite(ledPin1, brightnessLed1);
analogWrite(ledPin2, brightnessLed2);
// Update LED bar graph
for (int i = 0; i < barGraphSize; i++) {
if (i < barSegments) {
digitalWrite(barGraphPins[i], HIGH);
} else {
digitalWrite(barGraphPins[i], LOW);
}
}
// Small delay for stability
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
bargraph1:A1
bargraph1:A2
bargraph1:A3
bargraph1:A4
bargraph1:A5
bargraph1:A6
bargraph1:A7
bargraph1:A8
bargraph1:A9
bargraph1:A10
bargraph1:C1
bargraph1:C2
bargraph1:C3
bargraph1:C4
bargraph1:C5
bargraph1:C6
bargraph1:C7
bargraph1:C8
bargraph1:C9
bargraph1:C10
pot1:VCC
pot1:SIG
pot1:GND
pot2:VCC
pot2:SIG
pot2:GND
pot3:VCC
pot3:SIG
pot3:GND