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 | pinMode() |
||||
Examples | import processing.io.*; // On the Raspberry Pi GPIO 4 is physical pin 7 on the header void setup() { // INPUT_PULLUP enables the built-in pull-up resistor for this pin // left alone, the pin will read as HIGH // connected to ground (via e.g. a button or switch) it will read LOW GPIO.pinMode(4, GPIO.INPUT_PULLUP); } void draw() { if (GPIO.digitalRead(4) == GPIO.LOW) { // button is pressed fill(255); } else { // button is not pressed fill(204); } stroke(255); ellipse(width/2, height/2, width*0.75, height*0.75); } | ||||
Description |
Configures a pin to act either as input (INPUT), or input with internal pull-up resistor (INPUT_PULLUP), or input with internal pull-down resistor (INPUT_PULLDOWN) or output (OUTPUT) Unlike on Arduino, where pins are implicitly set to inputs by default, it is necessary to call this function for any pin you want to access, including input pins. Pull-up and pull-down resistors are very useful when connecting buttons and switches, since they will force the value of the pin in a specified electrical state when no electrical connection is made, and the pin would otherwise be left "floating". The ability to set (and clear) pull-up and pull-down resistors is currently limited to the Raspberry Pi running the Raspbian distribution. On other systems, a warning will be shown. |
||||
Syntax | .pinMode(pin, mode) | ||||
Parameters |
| ||||
Returns | void |