button control

hi.my name is Rashad,I am new in Arduino.I use button library for debouncing.I use two button.I need when I press button1 led1 flashs 10 times.But when led1 flashs button2 doesnt work until flashing finishs.how to write program for two button work in the same time?thanks

#include <Button.h>

/*
  Wire like this:
  GND -----/ button ------ pin 12
*/
Button button1 = Button(11,BUTTON_PULLDOWN);
Button button2 = Button(9,BUTTON_PULLDOWN);

int led1=10;
int led2=12;

void setup()
{
  pinMode(led1,OUTPUT);
  pinMode(led2,OUTPUT);
}

void loop()
{
  
//***********************************
  if(button1.isPressed())
  {
  for (int i=0; i<10; i++)
    {
    digitalWrite(led1,HIGH);
    delay(1000);
    digitalWrite(led1,LOW);
    delay(1000);
    }
  }
//*************************************
 if(button2.isPressed())
  {
    digitalWrite(led2,HIGH);
  }
  else
  {
    digitalWrite(led2,LOW);
  }

Have a look at the blink without delay tut

I'm thinking of applying to have that reply to be given its own dedicated control :D

It needs a number, for sure. Single-digit, probably.

Thinking in terms of root-cause analysis, the real answer is to delete the Blink example, and rename BlinkWithoutDelay to Blink.

-br

billroy: rename BlinkWithoutDelay to Blink.

And Blink to BlinkWITHDelay? 8)

the real answer is to delete the Blink example

I think BlinkTheStupidWay and BlinkTheSmartWay should be the names of the sketches.

:)

OP, your problem is that when the processor is executing the "delay()"s in your sketch, it can't be doing anything else, like looking for button presses.

The trick is to remember that changing the state of a LED from on to off or vice versa, or looking at the state of a switch take very, very little time, but sitting in a "delay()" means you can't do anything else, so, the "delay()"s have to go!

AWOL: I'm thinking of applying to have that reply to be given its own dedicated control :D

Damned fine idea! While we're on the subject, could I also suggest that any text pasted into the edit window should automatically be enclosed in code tags? My guess is that would reduce the moderator workload by a large factor.

Yes, I know this isn't the right place to suggest it ... :roll_eyes: