Skip to main content
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
deleted 133 characters in body; edited title
Source Link
dda
  • 1.6k
  • 1
  • 12
  • 18

pause code in middle of Pause running program using a pushbutton

I have a program that flashes three ledsLED in sequence indefinitely. How would I be able tocan O program a pushbutton to pause the program in the middle of the code?

Also, how wouldcan I be able to modify the code so that pressing the button a second time would speed up the flashing of the ledLED?

Each time I try to use a pushbutton to pause the program, it only pauses it once the program loops back to the beginning.

Here's my code at the moment (sorry that, it's not very clean):

int ledpins[]   = {4, 5, 6};
int buttonpin   = 3;
int buttonstate = 0;

void setup() {
    Serial.begin(9600);

    for (int pin=6;pin pin>3;= 6; pin > 3; pin--) {
        pinMode(ledpins[pin], OUTPUT);
    }
    
    pinMode(buttonpin, INPUT);
}

void loop() {
 
  buttonstate = buttonstate=digitalReaddigitalRead(buttonpin);
 
    if (buttonstate==HIGHbuttonstate == HIGH) {
            digitalWrite(ledpins, HIGH);
    }
 
    if (buttonstate==LOWbuttonstate == LOW) {
 
    for (int pin = for(int4; pin=4;pin pin<7;< 7; pin++) {
            digitalWrite(pin, HIGH);
            delay(200);
            digitalWrite(pin, LOW);
        }
 
    for (int pin = for(int6; pin=6;pin pin>3;> 3; pin--) {
            digitalWrite(pin, HIGH);
            delay(200);
            digitalWrite(pin, LOW);
        }
    }
}

pause code in middle of running program using pushbutton

I have a program that flashes three leds in sequence indefinitely. How would I be able to program a pushbutton to pause the program in the middle of the code?

Also, how would I be able to modify the code so that pressing the button a second time would speed up the flashing of the led?

Each time I try to use a pushbutton to pause the program, it only pauses it once the program loops back to the beginning.

Here's my code at the moment (sorry that it's not very clean):

int ledpins[]   = {4,5,6};
int buttonpin   = 3;
int buttonstate = 0;

void setup() {
    Serial.begin(9600);

    for(int pin=6; pin>3; pin--) {
        pinMode(ledpins[pin], OUTPUT);
    }
    
    pinMode(buttonpin, INPUT);
}

void loop() {
 
    buttonstate=digitalRead(buttonpin);
 
    if(buttonstate==HIGH) {
            digitalWrite(ledpins, HIGH);
    }
 
    if(buttonstate==LOW) {
 
        for(int pin=4; pin<7; pin++) {
            digitalWrite(pin, HIGH);
            delay(200);
            digitalWrite(pin, LOW);
        }
 
        for(int pin=6; pin>3; pin--) {
            digitalWrite(pin, HIGH);
            delay(200);
            digitalWrite(pin, LOW);
        }
    }
}

Pause running program using a pushbutton

I have a program that flashes three LED in sequence indefinitely. How can O program a pushbutton to pause the program in the middle of the code?

Also, can I modify the code so that pressing the button a second time would speed up the flashing of the LED?

Each time I try to use a pushbutton to pause the program, it only pauses it once the program loops back to the beginning.

Here's my code at the moment (sorry, it's not very clean):

int ledpins[]   = {4, 5, 6};
int buttonpin   = 3;
int buttonstate = 0;

void setup() {
  Serial.begin(9600);

  for (int pin = 6; pin > 3; pin--) {
    pinMode(ledpins[pin], OUTPUT);
  }
  pinMode(buttonpin, INPUT);
}

void loop() {
  buttonstate = digitalRead(buttonpin);
  if (buttonstate == HIGH) {
    digitalWrite(ledpins, HIGH);
  }
  if (buttonstate == LOW) {
    for (int pin = 4; pin < 7; pin++) {
      digitalWrite(pin, HIGH);
      delay(200);
      digitalWrite(pin, LOW);
    }
    for (int pin = 6; pin > 3; pin--) {
      digitalWrite(pin, HIGH);
      delay(200);
      digitalWrite(pin, LOW);
    }
  }
}

I have a program that flashes three leds in sequence indefinitely. How would I be able to program a pushbutton to pause the program in the middle of the code?

Also, how would I be able to modify the code so that pressing the button a second time would speed up the flashing of the led?

Each time I try to use a pushbutton to pause the program, it only pauses it once the program loops back to the beginning.

Here's my code at the moment (sorry that it's not very clean):

int ledpins[]=ledpins[]   = {4,5,6};
 
int buttonpin=3;
buttonpin   = 3;
int buttonstate=0;buttonstate = 0;

void setup() 
 {
 
    Serial.begin(9600);

    for(int pin=6; pin>3; pin--)

  {
        pinMode(ledpins[pin], OUTPUT);
    }
    
    pinMode(buttonpin, INPUT);
}

void loop() {

    buttonstate=digitalRead(buttonpin);

    if(buttonstate==HIGH)
  {
 
            digitalWrite(ledpins, HIGH);
    }

    if(buttonstate==LOW)

  { 

        for(int pin=4; pin<7; pin++)

  {
            digitalWrite(pin, HIGH);
 
            delay(200);
 
            digitalWrite(pin, LOW);
        }

        for(int pin=6; pin>3; pin--)

  {
            digitalWrite(pin, HIGH);
 
            delay(200);
 
            digitalWrite(pin, LOW);
        }
    }
}

I have a program that flashes three leds in sequence indefinitely. How would I be able to program a pushbutton to pause the program in the middle of the code?

Also, how would I be able to modify the code so that pressing the button a second time would speed up the flashing of the led?

Each time I try to use a pushbutton to pause the program, it only pauses it once the program loops back to the beginning.

Here's my code at the moment (sorry that it's not very clean):

int ledpins[]={4,5,6};
 
int buttonpin=3;

int buttonstate=0;

void setup() 
 {
 
Serial.begin(9600);

for(int pin=6; pin>3; pin--)

 {
pinMode(ledpins[pin], OUTPUT);
}

pinMode(buttonpin, INPUT);
}

void loop() {

buttonstate=digitalRead(buttonpin);

if(buttonstate==HIGH)
 {
 
digitalWrite(ledpins, HIGH);
}

if(buttonstate==LOW)

 {
for(int pin=4; pin<7; pin++)

 {
digitalWrite(pin, HIGH);
 
delay(200);
 
digitalWrite(pin, LOW);
}

for(int pin=6; pin>3; pin--)

 {
digitalWrite(pin, HIGH);
 
delay(200);
 
digitalWrite(pin, LOW);
}
}
}

I have a program that flashes three leds in sequence indefinitely. How would I be able to program a pushbutton to pause the program in the middle of the code?

Also, how would I be able to modify the code so that pressing the button a second time would speed up the flashing of the led?

Each time I try to use a pushbutton to pause the program, it only pauses it once the program loops back to the beginning.

Here's my code at the moment (sorry that it's not very clean):

int ledpins[]   = {4,5,6};
int buttonpin   = 3;
int buttonstate = 0;

void setup() {
    Serial.begin(9600);

    for(int pin=6; pin>3; pin--) {
        pinMode(ledpins[pin], OUTPUT);
    }
    
    pinMode(buttonpin, INPUT);
}

void loop() {

    buttonstate=digitalRead(buttonpin);

    if(buttonstate==HIGH) {
            digitalWrite(ledpins, HIGH);
    }

    if(buttonstate==LOW) { 

        for(int pin=4; pin<7; pin++) {
            digitalWrite(pin, HIGH);
            delay(200);
            digitalWrite(pin, LOW);
        }

        for(int pin=6; pin>3; pin--) {
            digitalWrite(pin, HIGH);
            delay(200);
            digitalWrite(pin, LOW);
        }
    }
}
Format code as code and tag it
Source Link
user31481
user31481

I have a program that flashes three leds in sequence indefinitely. How would I be able to program a pushbutton to pause the program in the middle of the code? 

Also, how would I be able to modify the code so that pressing the button a second time would speed up the flashing of the led? 

Each time I try to use a pushbutton to pause the program, it only pauses it once the program loops back to the beginning.

Here's my code at the moment (sorry that it's not very clean):

int ledpins[]={4,5,6};

int buttonpin=3;

int buttonstate=0;

void setup() {

Serial.begin(9600);

for(int pin=6; pin>3; pin--)

{ pinMode(ledpins[pin], OUTPUT); }

pinMode(buttonpin, INPUT); }

void loop() {

buttonstate=digitalRead(buttonpin);

if(buttonstate==HIGH) {

digitalWrite(ledpins, HIGH); }

if(buttonstate==LOW)

{ for(int pin=4; pin<7; pin++)

{ digitalWrite(pin, HIGH);

delay(200);

digitalWrite(pin, LOW); }

for(int pin=6; pin>3; pin--)

{ digitalWrite(pin, HIGH);

delay(200);

digitalWrite(pin, LOW); } } }

int ledpins[]={4,5,6};

int buttonpin=3;

int buttonstate=0;

void setup() 
{

Serial.begin(9600);

for(int pin=6; pin>3; pin--)

{
pinMode(ledpins[pin], OUTPUT);
}

pinMode(buttonpin, INPUT);
}

void loop() {

buttonstate=digitalRead(buttonpin);

if(buttonstate==HIGH)
{

digitalWrite(ledpins, HIGH);
}

if(buttonstate==LOW)

{
for(int pin=4; pin<7; pin++)

{
digitalWrite(pin, HIGH);

delay(200);

digitalWrite(pin, LOW);
}

for(int pin=6; pin>3; pin--)

{
digitalWrite(pin, HIGH);

delay(200);

digitalWrite(pin, LOW);
}
}
}

I have a program that flashes three leds in sequence indefinitely. How would I be able to program a pushbutton to pause the program in the middle of the code? Also, how would I be able to modify the code so that pressing the button a second time would speed up the flashing of the led? Each time I try to use a pushbutton to pause the program, it only pauses it once the program loops back to the beginning.

Here's my code at the moment (sorry that it's not very clean):

int ledpins[]={4,5,6};

int buttonpin=3;

int buttonstate=0;

void setup() {

Serial.begin(9600);

for(int pin=6; pin>3; pin--)

{ pinMode(ledpins[pin], OUTPUT); }

pinMode(buttonpin, INPUT); }

void loop() {

buttonstate=digitalRead(buttonpin);

if(buttonstate==HIGH) {

digitalWrite(ledpins, HIGH); }

if(buttonstate==LOW)

{ for(int pin=4; pin<7; pin++)

{ digitalWrite(pin, HIGH);

delay(200);

digitalWrite(pin, LOW); }

for(int pin=6; pin>3; pin--)

{ digitalWrite(pin, HIGH);

delay(200);

digitalWrite(pin, LOW); } } }

I have a program that flashes three leds in sequence indefinitely. How would I be able to program a pushbutton to pause the program in the middle of the code? 

Also, how would I be able to modify the code so that pressing the button a second time would speed up the flashing of the led? 

Each time I try to use a pushbutton to pause the program, it only pauses it once the program loops back to the beginning.

Here's my code at the moment (sorry that it's not very clean):

int ledpins[]={4,5,6};

int buttonpin=3;

int buttonstate=0;

void setup() 
{

Serial.begin(9600);

for(int pin=6; pin>3; pin--)

{
pinMode(ledpins[pin], OUTPUT);
}

pinMode(buttonpin, INPUT);
}

void loop() {

buttonstate=digitalRead(buttonpin);

if(buttonstate==HIGH)
{

digitalWrite(ledpins, HIGH);
}

if(buttonstate==LOW)

{
for(int pin=4; pin<7; pin++)

{
digitalWrite(pin, HIGH);

delay(200);

digitalWrite(pin, LOW);
}

for(int pin=6; pin>3; pin--)

{
digitalWrite(pin, HIGH);

delay(200);

digitalWrite(pin, LOW);
}
}
}
Source Link
Loading