#include <Servo.h> // Included as allowed package (not used in this sketch)
const int led1Pin = 32; // Pin for led1
const int led2Pin = 33; // Pin for led2
// Array for the 10 bar graph segments connected to pins 22-31
const int barPins[10] = {22, 23, 24, 25, 26, 27, 28, 29, 30, 31};
void setup() {
// Set up the individual LED pins as outputs.
pinMode(led1Pin, OUTPUT);
pinMode(led2Pin, OUTPUT);
// Set up each bar graph segment pin as outputs.
for (int i = 0; i < 10; i++) {
pinMode(barPins[i], OUTPUT);
digitalWrite(barPins[i], LOW); // Make sure it's off initially.
}
// Turn off the individual LEDs on startup.
digitalWrite(led1Pin, LOW);
digitalWrite(led2Pin, LOW);
}
void loop() {
// The variable used to alternate the two individual LEDs.
bool toggleLED = true;
// Fill the bar graph sequentially.
for (int seg = 0; seg < 10; seg++) {
// Turn on the current bargraph segment.
digitalWrite(barPins[seg], HIGH);
// Blink the two LEDs alternately on each 2000ms interval.
if (toggleLED) {
digitalWrite(led1Pin, HIGH);
digitalWrite(led2Pin, LOW);
} else {
digitalWrite(led1Pin, LOW);
digitalWrite(led2Pin, HIGH);
}
// Wait 2000 milliseconds.
delay(2000);
// Toggle the LED blinking for next step.
toggleLED = !toggleLED;
}
// After the bargraph is fully lit, wait a little bit and then reset the animation.
// (Turn off all bar graph segments)
for (int seg = 0; seg < 10; seg++) {
digitalWrite(barPins[seg], LOW);
}
// Turn off the individual LEDs before restarting.
digitalWrite(led1Pin, LOW);
digitalWrite(led2Pin, LOW);
// Short delay before restarting the animation.
delay(500);
}