Pages: [1]   Go Down
Author Topic: button control  (Read 317 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 12
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Code:

#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);
  }
Logged

Johannesburg. UTC+2
Offline Offline
Faraday Member
**
Karma: 91
Posts: 4217
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Have a look at the blink without delay tut
Logged

Roy from ITCrowd: Have you tried turning it off an on again?
I'm on LinkedIn: http://www.linkedin.com/in/jimbrownza

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 299
Posts: 26196
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I'm thinking of applying to have that reply to be given its own dedicated control   smiley-grin
Logged

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

0
Offline Offline
God Member
*****
Karma: 39
Posts: 988
Get Bitlash: http://bitlash.net
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

Johannesburg. UTC+2
Offline Offline
Faraday Member
**
Karma: 91
Posts: 4217
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

rename BlinkWithoutDelay to Blink.


And Blink to BlinkWITHDelaysmiley-cool
Logged

Roy from ITCrowd: Have you tried turning it off an on again?
I'm on LinkedIn: http://www.linkedin.com/in/jimbrownza

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 610
Posts: 49040
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
the real answer is to delete the Blink example
I think BlinkTheStupidWay and BlinkTheSmartWay should be the names of the sketches.
Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 299
Posts: 26196
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

 smiley

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!
Logged

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

UK
Offline Offline
Shannon Member
****
Karma: 223
Posts: 12631
-
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I'm thinking of applying to have that reply to be given its own dedicated control   smiley-grin

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 ... smiley-roll
Logged

I only provide help via the forum - please do not contact me for private consultancy.

Pages: [1]   Go Up
Jump to: