Skip to content

Commit dc6dd3d

Browse files
committed
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.
1 parent b4af01f commit dc6dd3d

File tree

3 files changed

+14
-21
lines changed

3 files changed

+14
-21
lines changed

java/libraries/io/examples/Interrupt/Interrupt.pde

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,19 @@
11
import processing.io.*;
22
color bgcolor = 0;
33

4-
// RPI.PIN7 refers to the physical pin 7 on the Raspberry Pi's
5-
// pin header, which is located on the fourth row, above one of
6-
// the Ground pins
4+
// GPIO numbers refer to different phyiscal pins on various boards
5+
// On the Raspberry Pi GPIO 4 is physical pin 7 on the header
76

87
void setup() {
9-
GPIO.pinMode(RPI.PIN7, GPIO.INPUT);
10-
GPIO.attachInterrupt(RPI.PIN7, this, "pinEvent", GPIO.RISING);
8+
GPIO.pinMode(4, GPIO.INPUT);
9+
GPIO.attachInterrupt(4, this, "pinEvent", GPIO.RISING);
1110
}
1211

1312
void draw() {
1413
background(bgcolor);
1514
}
1615

17-
// this function will be called whenever pin 7 is brought from LOW to HIGH
16+
// this function will be called whenever GPIO 4 is brought from LOW to HIGH
1817
void pinEvent(int pin) {
1918
println("Received interrupt");
2019
if (bgcolor == 0) {

java/libraries/io/examples/SimpleInput/SimpleInput.pde

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,15 @@
11
import processing.io.*;
22

3-
// RPI.PIN7 refers to the physical pin 7 on the Raspberry Pi's
4-
// pin header, which is located on the fourth row, above one of
5-
// the Ground pins
3+
// GPIO numbers refer to different phyiscal pins on various boards
4+
// On the Raspberry Pi GPIO 4 is physical pin 7 on the header
65

76
void setup() {
8-
GPIO.pinMode(RPI.PIN7, GPIO.INPUT);
9-
// this is equivalent to addressing the pin with its GPIO number:
10-
// GPIO.pinMode(4, GPIO.INPUT);
7+
GPIO.pinMode(4, GPIO.INPUT);
118
}
129

1310
void draw() {
1411
// sense the input pin
15-
if (GPIO.digitalRead(RPI.PIN7) == GPIO.HIGH) {
12+
if (GPIO.digitalRead(4) == GPIO.HIGH) {
1613
fill(255);
1714
} else {
1815
fill(204);

java/libraries/io/examples/SimpleOutput/SimpleOutput.pde

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,22 @@
11
import processing.io.*;
22
boolean ledOn = false;
33

4-
// RPI.PIN7 refers to the physical pin 7 on the Raspberry Pi's
5-
// pin header, which is located on the fourth row, above one of
6-
// the Ground pins
4+
// GPIO numbers refer to different phyiscal pins on various boards
5+
// On the Raspberry Pi GPIO 4 is physical pin 7 on the header
76

87
void setup() {
9-
GPIO.pinMode(RPI.PIN7, GPIO.OUTPUT);
10-
// this is equivalent to addressing the pin with its GPIO number:
11-
// GPIO.pinMode(4, GPIO.OUTPUT);
8+
GPIO.pinMode(4, GPIO.OUTPUT);
129
frameRate(0.5);
1310
}
1411

1512
void draw() {
1613
// make the LED blink
1714
ledOn = !ledOn;
1815
if (ledOn) {
19-
GPIO.digitalWrite(RPI.PIN7, GPIO.LOW);
16+
GPIO.digitalWrite(4, GPIO.LOW);
2017
fill(204);
2118
} else {
22-
GPIO.digitalWrite(RPI.PIN7, GPIO.HIGH);
19+
GPIO.digitalWrite(4, GPIO.HIGH);
2320
fill(255);
2421
}
2522
stroke(255);

0 commit comments

Comments
 (0)