Hey guys,
could someone help me out with the following problem:
When pressing a button I need to increment a counter variable by one (so far so good), when this button has been pressed and held down for 3+ seconds the counter variable should increment by 5 and if the button has been pressed for a total of 10+ seconds the counter variable should increment by 50 until it reaches a certain number.
Thank you!
I posted in the wrong forum. If a mod would move it into the appropriate forum please?
capture the time when the button was pressed using millis and then keep reading it.
When you see the time condition occur you want and the button has not been released, then count=count+5, or count=count+50.
Update as often as you think you can read it - every 1/2 second?
Thank you.
Half second or even per second is fast enough. The reason for this is b/c the counter must go as high as 500 for this application and if the count is down at a really low number it would take forever to go up into the hundreds.
You have a sample code by any chance?
Nope - I thought I described it pretty well for you.
If your void loop() is set up like blink without delaym should be easy to add.
ex:
void loop(){
current_millis = millis();
if ((current_millis - previous_millis)>=duration){
// previous_millis = current_millis; //set up for next pass thru
// do stuff in your code, track how long button was pressed, update counter, etc
}
I'll try again and post what I have if I need more help. Thank you though!