Go Down

Topic: button (Read 518 times) previous topic - next topic

packingtape

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 :)

Grumpy_Mike

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.

packingtape


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 :)
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 :)

Arrch


thanks sir for the reply :)
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 :)

Look at the Signal Edge Detection example in the Arduino program.

packingtape



thanks sir for the reply :)
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 :)

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.. :)




tuxduino

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.

packingtape


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..?

tuxduino

Sure:

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

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

Go Up