I need my led chaser pattern to stop with a push button [with all HIGH LEDs] Help please

#define potentiometer  A0
int read_ADC, delay_time;

int total_leds = 17; // enter the number of LEDs you want to use here
int leds[] = {A1, A2, A3, A4, A5, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13};

void setup() {// put your setup code here, to run once 
Serial.begin(9600);// initialize serial communication at 9600 bits per second:

pinMode(potentiometer, INPUT);

for(int i=0; i<total_leds; i++) { 
pinMode(leds[i], OUTPUT); // declare LEDs as output
}

delay(500); // Waiting for a while
}

void loop() {
  
Serial.println("Effect 1");
for(int i=0; i<3; i++) effect_1();

Serial.println("Effect 2");
for(int i=0; i<3; i++) effect_2();

Serial.println("Effect 3");
for(int i=0; i<20; i++) effect_3();

Serial.println("Effect 4");
for(int i=0; i<3; i++) effect_4();

Serial.println("Effect 5");
for(int i=0; i<3; i++) effect_5();

Serial.println("Effect 6");
for(int i=0; i<3; i++) effect_6();

Serial.println("Effect 7");
for(int i=0; i<3; i++) effect_7();

Serial.println("Effect 8");
for(int i=0; i<3; i++) effect_8();

Serial.println("Effect 9");
for(int i=0; i<10; i++) effect_9();

Serial.println("Effect 10");
for(int i=0; i<10; i++) effect_10();

Serial.println("Effect 11");
for(int i=0; i<5; i++) effect_11();

Serial.println("Effect 12");
for(int i=0; i<5; i++) effect_12();
  
ledsOff();
get_delay();
}

//TURN ON ALL LEDs
void ledsOn() {
for(int i=0; i<total_leds; i++) {
digitalWrite(leds[i], HIGH);
 }
}

//TURN OFF ALL LEDs
void ledsOff() {
for(int i=0; i<total_leds; i++) {
digitalWrite(leds[i], LOW);
 }
}

//LEFT TO RIGH FILL UNFILL - RIGHT TO LEFT FILL UNFIL   
void effect_1() {
int i=0;
for(i=0; i<=total_leds; i++){
digitalWrite(leds[i], HIGH);
get_delay();
}

for(i=0; i<=total_leds; i++){
digitalWrite(leds[i], LOW);
get_delay();
}
  
for(i=total_leds; i>=0; i--){
digitalWrite(leds[i], HIGH);
get_delay();
}

for(i=total_leds; i>=0; i--){
digitalWrite(leds[i], LOW);
get_delay();
}
}

//SPRING
void effect_2() {
int i=0;
for(i=0; i<=total_leds-1; i++){
digitalWrite(leds[i],HIGH);
get_delay();
}
  
for(i=total_leds; i>=0; i--){
digitalWrite(leds[i],LOW);
get_delay();
}
  
for(i=total_leds; i>=0; i--){
digitalWrite(leds[i],HIGH);
get_delay();
}
  
for(i=0; i<=total_leds; i++){
digitalWrite(leds[i],LOW);
get_delay();
 }
}

//RUN ODD LEDs
void effect_3() {
for(int i=0; i<total_leds; i=i+2) {
digitalWrite(leds[i], HIGH);
digitalWrite(leds[i + 1], LOW);
}

get_delay();

for(int i=0; i<total_leds; i=i+2) {
digitalWrite(leds[i], LOW);
digitalWrite(leds[i + 1], HIGH);
}

get_delay();
}

//RUN EVEN ODD LEDs
void effect_4() {
for(int i=0; i<=total_leds; i++){
digitalWrite(leds[i], HIGH);
get_delay();
i=i+1;
}
  
for(int i=0; i<=total_leds; i++){
digitalWrite(leds[i], LOW);
get_delay();
}

for(int j=total_leds +1; j>=0; j--){
digitalWrite(leds[j], HIGH);
get_delay();
j=j-1;
}
  
for(int j=total_leds; j>=0; j--){
digitalWrite(leds[j], LOW);
get_delay();
 }
}


//FROM LEFT AND RIGHT TO CENTER - AND VICE VERSA
void effect_5() {
  int i=0;
for(i=0; i<=total_leds/2 ; i++){
digitalWrite(leds[i],HIGH);
digitalWrite(leds[total_leds-i],HIGH);
get_delay();
}

for(i=0; i<=total_leds/2 ; i++){
digitalWrite(leds[i],LOW);
digitalWrite(leds[total_leds-i],LOW);
get_delay();
}

get_delay();

for(i=0; i<=total_leds/2 ; i++){
digitalWrite(leds[i],HIGH);
digitalWrite(leds[total_leds-i],HIGH);
get_delay();
}
for(i=total_leds/2; i>=0 ; i--){
digitalWrite(leds[i],LOW);
digitalWrite(leds[total_leds-i],LOW);
get_delay();
 }
}

//NIGHT RIDER LEFT TO RIGHT (ONE LED)
void effect_6() {
for(int i=0; i<total_leds; i++) {
digitalWrite(leds[i], HIGH);
get_delay();
digitalWrite(leds[i], LOW);
 }
}

//NIGHT RIDER RIGHT TO LEFT (ONE LED)
void effect_7() {
for(int i=total_leds; i>0; i--){
digitalWrite(leds[i-1], HIGH);
get_delay();
digitalWrite(leds[i-1], LOW);
 }
}

//NIGHT RIDER BACK AND FORTH (ONE LED)
void effect_8() {
for(int i=0;i<=total_leds;i++){
digitalWrite(leds[i],HIGH);
get_delay();
digitalWrite(leds[i],LOW);
}
for(int i=total_leds-2;i>=0;i--){
digitalWrite(leds[i],HIGH);
get_delay();
digitalWrite(leds[i],LOW);
 }
}

//INSIDE TO CENTER
void effect_9() {
for(int i=0; i<total_leds/2; i++){
digitalWrite(leds[i], HIGH);
digitalWrite(leds[total_leds - 1 - i], HIGH);
get_delay();
digitalWrite(leds[i], LOW);
digitalWrite(leds[total_leds - 1 - i], LOW);
 }
}

//OUTSIDE FROM CENTER
void effect_10() {
for(int i=(total_leds/2)-1; i>=0; i--){
digitalWrite(leds[i], HIGH);
digitalWrite(leds[total_leds -1 -i], HIGH);
get_delay();
digitalWrite(leds[i], LOW);
digitalWrite(leds[total_leds -1 -i], LOW);
 }
}

//RUN 2 LEDs FROM LEFT TO RIGHT
void effect_11() {
for(int i=0; i < total_leds + 3; i++) {
if(i<=total_leds){digitalWrite(leds[i], HIGH);}
if(i>1){digitalWrite(leds[i - 2], LOW);}
get_delay();
 }
}

//RUN 2 LEDS BACK AND FORTH
void effect_12() {
for(int i=2; i<total_leds; i++) {

if(i==2){
digitalWrite(leds[0], HIGH);
//digitalWrite(leds[1], HIGH);
}

digitalWrite(leds[i], HIGH);
digitalWrite(leds[i - 2], LOW);
get_delay();
}

for(int i=total_leds-3; i>-1; i--) {
digitalWrite(leds[i], HIGH);
digitalWrite(leds[i + 2], LOW);
get_delay();
 }
}

void get_delay(){
read_ADC = analogRead(potentiometer);
delay_time = read_ADC/2.046; //max value ADC 1013/2.046 = 500
if(delay_time<10)delay_time=10;
delay(delay_time);
}

"shop with a push button" ?
or
STOP with a push button ?

Sorry, Stop with push button

In your sketch you have to 'poll' (check, read) this pushbutton.
If it's found active then it goes off to the special function (all OUTs HIGH)

You'll have to adopt the millis-based "blink without delay" approach to do that.

ok , how do ?

Can you Edit to my code ? . Please

How are you sinking or sourcing the power for seventeen LEDs?

After your LED chaser stops, then what happens?

I moved your topic to an appropriate forum category @harshapcb.

In the future, please take some time to pick the forum category that best suits the subject of your topic. There is an "About the _____ category" topic at the top of each category that explains its purpose.

This is an important part of responsible forum usage, as explained in the "How to get the best out of this forum" guide. The guide contains a lot of other useful information. Please read it.

Thanks in advance for your cooperation.

@harshapcb - Something to read...

The only place you call the real delay() that sets the timing is here

void get_delay(){
  read_ADC = analogRead(potentiometer);
  delay_time = read_ADC/2.046; //max value ADC 1013/2.046 = 500
  if(delay_time<10)delay_time=10;
    delay(delay_time);
}

If you had a pushbutton controlling that, all your effects would run super fast.

If you also checked for the same button as pressed in the loop() function, you could itake an action like going to the all on effect and halting.

You don't say what should start it going again.

void get_delay() {
  if (digitalRead(controlPin) == LOW) return;  / hurry up!

  read_ADC = analogRead(potentiometer);
  delay_time = read_ADC/2.046; //max value ADC 1013/2.046 = 500
  if(delay_time<10)delay_time=10;
  delay(delay_time);
}

Assuming you have an input with a pushbutton wired form the input to ground, and this

  pinMode(controlPin, INPUT_PULLUP);

and above that

const byte controlPin = 7;  // or whatever pin you pick

Not the most elegant solution, but it will work. I commented out that delay() in @xfpd's wokwi simulation, and the sketch flies through all the effects like lightning.

a7

I forgot the pot on A0. It works well, now. (no STOP yet)

Didn't even notice! I was looking for a way to adjust the code for the goal. So I was getting random delay, I guess, but always at least 10 milliseconds.

Remove the if statement creating a minimum delay, and you get the same effect of essentially no delay when you dial it down to zero.

My hack just skips out on doing anything at all, so the f/x go quite rapidly. As I said, recognizing the same button and doing something with it in the loop)) to implement STOP or whatever.

BTW I use slide faders instead of the twisty pot in wokwi, it's easier to manipulate especially on a tablet, and I like the visual indication of the setting you at.

a7

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.