#include <Servo.h> // Included per allowed packages
// Define Arduino pins used for the LEDs and the bar graph segments.
const int ledPins[3] = {22, 23, 24};
const int barPins[10] = {30, 31, 32, 33, 34, 35, 36, 37, 38, 39};
// A helper function to update the bar graph display.
// It will turn on the first 'count' segments and turn off the others.
void updateBarGraph(int count) {
for (int i = 0; i < 10; i++) {
if (i < count) {
digitalWrite(barPins[i], HIGH);
} else {
digitalWrite(barPins[i], LOW);
}
}
}
void setup() {
// Initialize LED output pins
for (int i = 0; i < 3; i++) {
pinMode(ledPins[i], OUTPUT);
digitalWrite(ledPins[i], LOW);
}
// Initialize bar graph output pins
for (int i = 0; i < 10; i++) {
pinMode(barPins[i], OUTPUT);
digitalWrite(barPins[i], LOW);
}
}
void loop() {
// Phase 1: Only led1 is ON; bar graph shows 1 segment.
digitalWrite(ledPins[0], HIGH);
digitalWrite(ledPins[1], LOW);
digitalWrite(ledPins[2], LOW);
updateBarGraph(1);
delay(2000);
// Phase 2: led1 and led2 are ON; bar graph shows 2 segments.
digitalWrite(ledPins[0], HIGH);
digitalWrite(ledPins[1], HIGH);
digitalWrite(ledPins[2], LOW);
updateBarGraph(2);
delay(2000);
// Phase 3: All three LEDs are ON; bar graph shows 3 segments.
digitalWrite(ledPins[0], HIGH);
digitalWrite(ledPins[1], HIGH);
digitalWrite(ledPins[2], HIGH);
updateBarGraph(3);
delay(2000);
// Final Phase: Turn off all LEDs; bar graph lights all 10 segments.
digitalWrite(ledPins[0], LOW);
digitalWrite(ledPins[1], LOW);
digitalWrite(ledPins[2], LOW);
updateBarGraph(10);
delay(2000);
// After the final phase, reset everything OFF for the next cycle.
for (int i = 0; i < 3; i++) {
digitalWrite(ledPins[i], LOW);
}
updateBarGraph(0);
delay(500); // brief pause before repeating the cycle
}