Go Down

Topic: check frequency by pressing button (Read 244 times) previous topic - next topic

hello people
I wish that when a button was pressed in a 3-second interval the program to continue to do what he's doing, if he were not in a tight range of 3 seconds it does something else.

Pressed once, after first checking if it was pressed again at an interval of 3 seconds, doing this until he ceases to be pressed in a 3-second interval.


something like this
Code: [Select]

int f = 1;  // f = function to execute
void setup()
  unsigned long start = millis();
  f = 1;

void loop()
  if (digitalRead(button) == HIGH && millis() - start < 3000UL)
    start = millis();  // fast enough => restart timeout
    f = 1;
    f = 2; // too late :(
  if (f == 1) f1();
  else f2();

void f1()

void f2()
Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

Go Up

Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

via Egeo 16
Torino, 10131