uwezi

arduino wait for pin

Apr 29th, 2019
126
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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. }
RAW Paste Data