Name

waitFor()

Class

GPIO

Description

Waits for the value of an input pin to change

The mode parameter determines when the function will return: GPIO.FALLING occurs when the level changes from high to low, GPIO.RISING when the level changes from low to high, and GPIO.CHANGE when either occurs.

The optional timeout parameter determines how many milliseconds the function will wait at the most. If the value of the input pin hasn't changed at this point, an exception is raised for this line. Without a timeout parameter the function will wait indefinitely until the input pin has changed to the desired state. This function will throw a RuntimeException in case of a timeout.

Examples

  • import processing.io.*;
    
    void setup() {
      GPIO.pinMode(4, GPIO.OUTPUT);
      GPIO.pinMode(5, GPIO.INPUT);
    
      // trigger a reset of an external device with GPIO 4
      GPIO.digitalWrite(4, GPIO.HIGH);
    
      // wait for the device signalling us that it's ready
      // by pulling up our pin 5
      GPIO.waitFor(5, GPIO.RISING, 1000);
      // if this takes longer than 1000ms an exception will be raised
    
      // GPIO.waitFor(5, GPIO.RISING);
      // would alternatively wait indefinitely
    
      // ...
    }
    
    

Syntax

  • .waitFor(pin, mode)
  • .waitFor(pin, mode, timeout)

Parameters

  • pin(int)GPIO pin
  • mode(int)what to wait for: GPIO.CHANGE, GPIO.FALLING or GPIO.RISING
  • timeout(int)don't wait more than timeout milliseconds

Return

  • void