- Processing
- p5.js
- Processing.py
- Processing for Android

- Processing Foundation

This reference is for Processing 3.0+. If you have a previous version, use the reference included with your software in the Help menu. If you see any errors or have suggestions, please let us know. If you prefer a more technical reference, visit the Processing Core Javadoc and Libraries Javadoc.

Class | GPIO
Name | ### attachInterrupt()
Examples |
    import processing.io.*;
    color bgcolor = 0;

    void setup() {
      GPIO.pinMode(4, GPIO.INPUT);
      GPIO.attachInterrupt(4, this, "pinEvent", GPIO.RISING);
    }

    void draw() {
      background(bgcolor);
    }

    // this function will be called whenever GPIO 4 is brought from low to high
    void pinEvent(int pin) {
      println("Received interrupt");
      if (bgcolor == 0) {
        bgcolor = color(255);
      } else {
        bgcolor = color(0);
      }
    }
Description | Calls a function when the value of an input pin changes The sketch method provided must accept a single integer (int) parameter, which is the number of the GPIO pin that the interrupt occured on. As this method might be called at any time, including when drawing to the display window isn't permitted, it is best to only set simple variables that are being responded to in the next draw() call, as shown above. Calling functions of the Hardware I/O library at this point is certainly possible. The mode parameter determines when the function will be called: 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.
Syntax |
    .attachInterrupt(pin, parent, method, mode)
Parameters |
pin | int: GPIO pin
parent | PApplet: typically use "this"
method | String: name of sketch method to call
mode | int: when to call: GPIO.CHANGE, GPIO.FALLING or GPIO.RISING
Returns | void

Updated on November 10, 2017 05:36:31pm EST