Please,,,Need help ,, with button
digging
Posts: 3
i have a question, which is how to control LED on/off with a single button. so by clicking the button first time will turn LED on for the second time will turn the LED off !!
i know it is really basics but i have tried many ways to do it but i couldn't figure out how it works
i know it is really basics but i have tried many ways to do it but i couldn't figure out how it works
Comments
Welcome to the forums. Have you taken a look at the Propeller Education Kit labs? They have an assortment of button examples.
http://www.parallax.com/Portals/0/Downloads/docs/prod/prop/PELabsFunBook-v1.1.pdf
http://forums.parallax.com/showthread.php?89958-Propeller-Education-Kit-Labs-Tools-and-Applications
It's best to start at the beginning with that free downloadable book and work your way through the examples.
Look at pages 34-35 in the lab book mentioned above. Look at how the REPEAT loop handles the pushing of a button and how the ! operator changes the state of a pin.
hope that helps.
i know how to do that but, what i would like to do is if i click button1 one time the LED will start blinking ( i know how it makes the LED blinking ) and if i click the same button1 for the second time , the LED will stop , so it like to function with one button
thank you in advance
digging,
I haven't tested this code. In fact, I didn't even write it on the SPIN editor, so I hope the indentation is correct on the IF statements, etc..
It's probably not the most elegant way to do this, but I think it might work.
It would certainly be wise to go through some of the beginner lessons listed above, because there are some that are similar to what you are trying to do, and will give you the knowledge you need to work it out on your own. Otherwise, you might be skipping over some of the most important concepts.
i have tested the code but i have to hold the button to make the LED stop flashing
what i would like to do is a single click
digging,
then you want to change the value of the debounce, which in my original code was very long. Try changing it to the following, or perhaps try 1/100th of a second to see if that makes it feel better for you.
And I agree with markaeric that you should take some time to go through the labs. All of this will be a cinch if you do. What I've provided is pretty rudimentary, so to get a functionality that is more crisp feeling, you might need to employ cogs, etc. But that's the kind of stuff you learn if you work through the labs.
Happy button pushing!