hey guys whats the best way to detect long and short button press? i need it to read milliseconds
for example i want to turn led on when the button is press but say after 500milli seconds it will turn it off
i have seen other code and iv tried to edit it but i cant get it to work
Record the time when the switch closes. Record the time when it opens. Subtract the closing time from the opening time. Use millis() for that.
And use appropriate debounce code on your button presses
sorry, basically what i need is after say 50mili it will digitally turn the button "off" and stop sending what ever code goes along with it being pressed
it will digitally turn the button "off"
Sorry, I have no idea what you mean. You should probably look at some state change detection. Start with the Button example sketch in the IDE.
its hard to explain.. um i have 2 buttons controlling a motor. with 1 button it will make it turn for X amount of time while button1 is pressed or lets say intill 50mili has passed.
while button 1 is pressed if i then press button 2 it will make the motor move again X amount of time while both pressed but ignoring button 1 "code"
dose that make sense?
Replace the "X"s with numbers.
for X amount of time while button1 is pressed or lets say intill 50mili has passed.
You are trying to register button presses that are shorter than 1/20 second? Because a normal human button press is longer than that. It reads like it will always be active until 50ms has elapsed. So your LED would usually emit a 50ms pulse.
See this post on Nick Gammon’s Switch Manager:
You can use the SwitchManager library to handle many switch related events in your sketches. The library provides: switch de-bouncing, timing and state change information. The SwitchManager.h file should be placed in your libraries folder, i.e. ...