Files
processing4/java/libraries/io/examples/Interrupt/Interrupt.pde
gohai c30aa85ab9 IO: Use GPIO numbers in examples
Even the Raspberry Pi Foundation used GPIO numbers over (congruous) physical pin numbers:
https://www.raspberrypi.org/learning/introduction-to-processing/worksheet-2/

Switch our examples as well, so that it they're more clear and hardware-agnostic.
2016-02-14 01:07:37 +01:00

25 lines
544 B
Plaintext

import processing.io.*;
color bgcolor = 0;
// GPIO numbers refer to different phyiscal pins on various boards
// On the Raspberry Pi GPIO 4 is physical pin 7 on the header
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);
}
}