hi all,
i want to ask you about if i have one button, and want it to do some things based on how much time is pressed,
i want if this button pressed for 1 second do some thing,
2 do some thing
5 do some thing
if you have any example or any link for this please help me,
while (button not pressed) {}
long start = millis () ;
while (button pressed) {}
long time_on = millis () - start ;
if (time_on < 1000)
{
// pressed for up to 1 sec
}
else if (time_on < 2000)
{
// pressed for up to 2 sec
}
else if (time_on < 3000)
{
// pressed for up to 3 sec
}
thank yuo MarkT for the code,
but iam new to arduino and microcontroler i want to ask you about this code i must put it in loop ? or can put it in function and call function in loop?
and if there are a libary for this can provied it
thank you
regards
You have to adapt it for your purposes - yes you can put it in loop(), yes you can put it in a function and call it from loop(). First try and understand it though
I don't know what is the purpose of this, but... humans are not very good with time. Especially measuring seconds. So, I'd choose a different way to make the selection of desired actions, or create a feedback to the user.
after 1 second - turn on a LED
after 2 seconds - dim the LED
after 3 seconds - turn off the LED (and turn another one on).