uwezi

arduino wait for pin

Apr 29th, 2019
643
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.28 KB | None | 0 0
  1. int wait_pin(int pin, int state, unsigned long int timeout)
  2. {
  3.   unsigned long int starttime = millis();
  4.   while ((digitalRead(pin) != state) && ((millis()-starttime) < timeout));
  5.   if (digitalRead(pin) == state)
  6.   {
  7.     return 0; // OK
  8.   }
  9.   else
  10.   {
  11.     return -1; // NOK
  12.   }
  13. }
Advertisement
Add Comment
Please, Sign In to add comment