I have configured a port pin which is connected to press button(switch), if high which I will start a motor.And for this I simply applied a condition
if (PORTB.RB6){
// loops for running motors.
}.
But I need to make avoidance of any accidental press. For this I need to hold the button for 3 seconds then motor should start.
How do I check if it is hold on press for 3 seconds or not ? Should I configure any timer for this ?
Any suggestions please.
You can calculate time from system clock.
To check Button is hold, you can make a loop 3 seconds: if Button is pressed, but in 3 seconds is released (to make sure button is released, you can count button state greater than your LIMITATION), set Button is HOLD.
If in 3 seconds, Button is kept in pressed state, set button is held and turn your motor.
if u want to avoid accidental press button then use on counter till like of 50/100 then u can detect the keys and proceed the your work. because as ur keeping 3 second is good for confirming but for continous use of ur keypad will really irritated someone if u want to use install in any product.
use counter
detect key
proceed the key and change it state.