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 | |||||||||
---|---|---|---|---|---|---|---|---|---|
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 |
| ||||||||
Returns | void |
This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.