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

help
about the button,
i want when i press and hold the button the program inside int execute one, if i want to execute it again i release and press again the button.
thank in advance smiley
Logged

Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 603
Posts: 33402
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Not sure what you want? Do you want some one to do it for you or tell you how to do it.

You need to read the button and hold in a while loop until it is pressed.
Do your thing
Then hold in a while loop until it is unpressed.
Logged

Philippines
Offline Offline
Newbie
*
Karma: 0
Posts: 30
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Not sure what you want? Do you want some one to do it for you or tell you how to do it.

You need to read the button and hold in a while loop until it is pressed.
Do your thing
Then hold in a while loop until it is unpressed.
thanks sir for the reply smiley
sir can i have sample code?
my project is a gun sound effect, when i press the trigger it will sound once, until i press it again smiley
Logged

California
Offline Offline
Faraday Member
**
Karma: 88
Posts: 3368
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

thanks sir for the reply smiley
sir can i have sample code?
my project is a gun sound effect, when i press the trigger it will sound once, until i press it again smiley
Look at the Signal Edge Detection example in the Arduino program.
Logged

Philippines
Offline Offline
Newbie
*
Karma: 0
Posts: 30
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

thanks sir for the reply smiley
sir can i have sample code?
my project is a gun sound effect, when i press the trigger it will sound once, until i press it again smiley
Look at the Signal Edge Detection example in the Arduino program.
https://www.facebook.com/photo.php?v=535518566463553

sir this my project..
the problem is when i press and hold the button the sound loop, what i what is when i press and hold the button it will play once.. smiley



Logged

Offline Offline
Edison Member
*
Karma: 26
Posts: 1339
You do some programming to solve a problem, and some to solve it in a particular language. (CC2)
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

You have to detect when the button state (well, its pin actually) changes from LOW to HIGH (or viceversa). For this you have to use a prevBtnState variable anche check it against the current reading.
Logged

Philippines
Offline Offline
Newbie
*
Karma: 0
Posts: 30
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

You have to detect when the button state (well, its pin actually) changes from LOW to HIGH (or viceversa). For this you have to use a prevBtnState variable anche check it against the current reading.

sir can i have example..?
Logged

Offline Offline
Edison Member
*
Karma: 26
Posts: 1339
You do some programming to solve a problem, and some to solve it in a particular language. (CC2)
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Sure:

http://arduino.cc/en/Tutorial/ButtonStateChange

That section has several useful example. It's a recommended reading.
Logged

Pages: [1]   Go Up
Jump to: