// Define DIP switch and LED bar graph pins
const int dipSwitchPins[] = {2, 3, 4, 5}; // Pins connected to the DIP switch
const int numDipSwitches = 4; // Number of switches in the DIP switch
const int ledPins[] = {6, 7, 8, 9}; // Pins connected to the LEDs in the bar graph
const int numLEDs = 4; // Number of LEDs in the bar graph
void setup() {
// Set DIP switch pins as inputs with internal pull-up resistors
for (int i = 0; i < numDipSwitches; i++) {
pinMode(dipSwitchPins[i], INPUT_PULLUP);
}
// Set LED bar graph pins as outputs
for (int i = 0; i < numLEDs; i++) {
pinMode(ledPins[i], OUTPUT);
}
}
void loop() {
// Read the state of the DIP switch
for (int i = 0; i < numDipSwitches; i++) {
int switchState = digitalRead(dipSwitchPins[i]);
// Illuminate corresponding LED if the switch is ON
if (switchState == LOW) {
illuminateLEDs(i);
} else {
turnOffLEDs();
}
}
}
void illuminateLEDs(int switchIndex) {
// Turn on LEDs up to the specified switch index
for (int i = 0; i <= switchIndex; i++) {
digitalWrite(ledPins[i], HIGH);
}
}
void turnOffLEDs() {
// Turn off all LEDs in the bar graph
for (int i = 0; i < numLEDs; i++) {
digitalWrite(ledPins[i], LOW);
}
}
uno:A5.2
uno:A4.2
uno:AREF
uno:GND.1
uno:13
uno:12
uno:11
uno:10
uno:9
uno:8
uno:7
uno:6
uno:5
uno:4
uno:3
uno:2
uno:1
uno:0
uno:IOREF
uno:RESET
uno:3.3V
uno:5V
uno:GND.2
uno:GND.3
uno:VIN
uno:A0
uno:A1
uno:A2
uno:A3
uno:A4
uno:A5
sw1:1a
sw1:2a
sw1:3a
sw1:4a
sw1:5a
sw1:6a
sw1:7a
sw1:8a
sw1:8b
sw1:7b
sw1:6b
sw1:5b
sw1:4b
sw1:3b
sw1:2b
sw1:1b
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