Hi! Can anyone help me with the coding?
bool btnIsUp = true; // the button is not being pressed at the start
bool lightIsOn = false; // the LEDs are OFF at the start
// constant variables (won't change)
const int ledPin1 = 3; // LED 1 attached to number 3
const int ledPin2 = 5; // LED 2 attached to number 5
const int ledPin3 = 6; // LED 3 attached to number 6
const int ledPin4 = 9; // LED 4 attached to number 9
const int ledPin5 = 10; // LED 5 attached to number 10
const int btnPin = 2; // push button attached to number 2
const int potPin = A0; // potentiometer attached to A0
// LED Array
int timer = 200;
int ledPins[] = { 3, 5, 6, 9, 10 };
int pinTotal = 5;
void setup() {
// put your setup code here, to run once:
pinMode(ledPin1, OUTPUT);
pinMode(ledPin2, OUTPUT);
pinMode(ledPin3, OUTPUT);
pinMode(ledPin4, OUTPUT);
pinMode(ledPin5, OUTPUT);
pinMode(btnPin, INPUT_PULLUP);
pinMode(potPin, INPUT);
Serial.begin(9600); // default 9600 baud rate
// Set the LEDs off at the start
digitalWrite(ledPin1, lightIsOn);
digitalWrite(ledPin2, lightIsOn);
digitalWrite(ledPin3, lightIsOn);
digitalWrite(ledPin4, lightIsOn);
digitalWrite(ledPin5, lightIsOn);
// LED Array Output
for (int thisPin = 0; thisPin < pinTotal; thisPin++) {
pinMode(ledPins[thisPin], OUTPUT);
}
}
void loop() {
// put your main code here, to run repeatedly:
if (digitalRead(btnPin) == HIGH && btnIsUp) { // if the button is pressed AND the button was UP
btnIsUp = false; // the button is DOWN now
if (lightIsOn) { // to check if the LEDs are ON
lightIsOn = false; // turn the LEDs OFF, if the LEDs are ON
digitalWrite(ledPin1, LOW);
digitalWrite(ledPin2, LOW);
digitalWrite(ledPin3, LOW);
digitalWrite(ledPin4, LOW);
digitalWrite(ledPin5, LOW);
for (int thisPin = 0; thisPin < pinTotal; thisPin++) {
digitalWrite(ledPins[thisPin], HIGH);
delay(timer);
digitalWrite(ledPins[thisPin], LOW);
}
for (int thisPin = 0; thisPin < pinTotal; thisPin++) {
digitalWrite(ledPins[thisPin], HIGH);
delay(timer);
digitalWrite(ledPins[thisPin], LOW);
}
} else {
lightIsOn = true; // turn the LEDs ON, if the lightIsOn is false
digitalWrite(ledPin1, HIGH);
digitalWrite(ledPin2, HIGH);
digitalWrite(ledPin3, HIGH);
digitalWrite(ledPin4, HIGH);
digitalWrite(ledPin5, HIGH);
}
}
if (digitalRead(btnPin) == LOW) { // if the button pin is UP
btnIsUp = true;
}
}
My goal is to make the LEDs turn ON once the button is pressed (the LEDs need to stay ON), then the LEDs will turn OFF when I press the button again.
After I turn ON the LEDs for a few seconds, I want to make a light sweeping effect from LED Pin 1 to 5 where I also be able to adjust the LEDs brightness using the potentiometer.
If it's possible, I also want to use the random() command to make a random light sweep effect, but I don't know how to use it.
I attached my circuit too.
Thank you in advance.


