button stop

Hello guys, I’m in trouble with a code :confused:
the question is:
there are 3 LEDs that have to blink forward and back, then with a potentiometer adjust the speed and with a button stop the state while the button is pressed but when released, it must resume the cycle from where stopped.

I can’t make the leds blinking stop when I press the button.

this is my code:

int led = 9;
int led2 = 10;
int led3 = 11;
int i = 0;
int pot = 0;
int pushButton = 8;
int buttonSTATE = 0;

void setup() {
pinMode(led,OUTPUT);
pinMode(led2,OUTPUT);
pinMode(led3,OUTPUT);
pinMode(pot,INPUT);
Serial.begin(9600);
pinMode(pushButton,INPUT);

}

void loop() {

 buttonSTATE digitalRead(pushButton);
 for(i=9;i<12;i++)
 {
 
  if (buttonSTATE == LOW){
   digitalWrite(i,HIGH);
    delay(analogRead(0));
     digitalWrite(i,LOW);
      delay(analogRead(0));
       Serial.print(analogRead(0));
        Serial.print("   ");
         Serial.print(analogRead(0)*5./1024);
          }
          else if (buttonSTATE == HIGH){

            
          }
          }
           
          
  
           
       }
       
 for(i=11;i>8;i--)
 { 
  do {
  digitalWrite(i,HIGH);
   delay(analogRead(0));
    digitalWrite(i,LOW);
     delay(analogRead(0));
      Serial.print(analogRead(0));
       Serial.print("   ");
        Serial.print(analogRead(0)*5./1024);
         } while(pushButton == HIGH);
       }



}

First, please edit your post to include code tags.

Next, what is the problem? I only read what you want, not what goes wrong.

Welcome.
What’s not working!

Use CTRL T to format the sketch.
Please use code tags.
Use the </> icon in the posting menu.

[code] Paste sketch here. [/code]

alexbuy:
the question is:
there are 3 LEDs that have to blink forward and back, then with a potentiometer adjust the speed and with a button stop the state while the button is pressed but when released, it must resume the cycle from where stopped.

That's not a question.

while(pushButton == HIGH);
Where are you reading the state?

What’s this doing?
buttonSTATE digitalRead(pushButton);

Use CTRL T to format the sketch.

septillion:
First, please edit your post to include code tags.

Next, what is the problem? I only read what you want, not what goes wrong.

I can't stop the leds blinking using the button, I tried with do while and if but nothing.
The leds must restart from where stopped when I release the button

One more time.

while(pushButton == HIGH);
Where are you reading the state?

What's this doing?
buttonSTATE digitalRead(pushButton);

Use CTRL T to format the sketch.

int led = 9;
int led2 = 10;
int led3 = 11;
int i = 0;
int pot = 0;


void setup() {
  pinMode(led, OUTPUT);
  pinMode(led2, OUTPUT);
  pinMode(led3, OUTPUT);
  pinMode(pot, INPUT);
  Serial.begin(9600);
  

}

void loop() {


  for (i = 9; i < 12; i++)
  {

      digitalWrite(i, HIGH);
      delay(analogRead(0));
      digitalWrite(i, LOW);
      delay(analogRead(0));
      Serial.print(analogRead(0));
      Serial.print("   ");
      Serial.print(analogRead(0) * 5. / 1024);
    
  




}

for (i = 11; i > 8; i--)
{
 
    digitalWrite(i, HIGH);
    delay(analogRead(0));
    digitalWrite(i, LOW);
    delay(analogRead(0));
    Serial.print(analogRead(0));
    Serial.print("   ");
    Serial.print(analogRead(0) * 5. / 1024);
 
}



}

this was the first code, and next, I had to make them stop with the button.

Standard question # 1 when dealing with inputs :

How is the input pin wired ?

One more time.

while(pushButton == HIGH);
Where are you reading the state?

What's this doing?
buttonSTATE digitalRead(pushButton);

Use CTRL T to format the sketch.

Here Larry, let me try to see if he will answer it from my post. If he keeps ignoring our advice we can just put him on the ignore list as a known time waste and move on to someone who actually wants our help.

larryd:
One more time.

while(pushButton == HIGH);
Where are you reading the state?

What’s this doing?
buttonSTATE digitalRead(pushButton);

Use CTRL T to format the sketch.

I’m reading the button state, to make the loop stop when I press it and, when I release, the loop must continue from where stopped.

UKHeliBob, I have a 4 pins button, I connected 1 pin to arduino (8) and 1 to gnd.

_ _
pin 8 → _ _ ← gnd

No, not why are you reading the button state. WHERE in the code are you reading it. That while loop is infinite. If pushButton is HIGH when you enter that empty loop and you never change it in the while loop then it will never change and you’re stuck there forever with your program hung in an empty while loop.

Please pay attention and read carefully. Programming involves using your brain and being very exacting in your communication. If you look like you’re not answering questions or not reading the responses very carefully then people will stop wasting time on you pretty quick.

Delta_G:
No, not why are you reading the button state. WHERE in the code are you reading it. That while loop is infinite. If pushButton is HIGH when you enter that empty loop and you never change it in the while loop then it will never change and you're stuck there forever with your program hung in an empty while loop.

Please pay attention and read carefully. Programming involves using your brain and being very exacting in your communication. If you look like you're not answering questions or not reading the responses very carefully then people will stop wasting time on you pretty quick.

sorry, I do not have a good understanding of English, I want to put in the for cycle but first, I declared the state.