Controlling pins: from pretend devices to Raspberry Pi
GPIO means General Purpose Input/Output: connections, called pins, that can read or send electrical signals. Input reads a signal; output sets one. BCM numbering names the GPIO signal, not the pin’s position in the connector. Always check the board’s GPIO diagram.
In Pliro’s interpreter and browser, pins are virtual: pretend connections with values remembered inside that run. They do not operate real wires. An explicit native Raspberry Pi build can operate physical GPIO. Configure means choose a pin’s job before using it. Logical state is the program’s true-or-false view of that pin; it is not a voltage you type as a Number.
GPIO is provided by built-in functions, so learning it does not require a different version of Pliro’s grammar.
Pins are whole BCM GPIO numbers from 0 through 27, not physical header
positions. A pin must be configured before use. Reconfiguring a virtual pin,
or configuring a native output, resets its logical output state to false:
pinOutput(pin)configures output mode and initializes a physical native
output safely low;pinInput(pin)configures input mode;writePin(pin, value)requires output mode and a Boolean value;readPin(pin)returns the last successfully written logical value for a
configured output, or samples the current level of a configured physical
input.
The interpreter and browser use isolated virtual pin state. Virtual inputs
default to false. Reading a virtual output returns its last written value. A
Raspberry Pi ARM64 or ARMv7 native build uses Linux GPIO character-device access and BCM
numbering with the same program semantics.
# language: en
# BCM 17, not physical header pin 17.
let ledPin = 17
pinOutput(ledPin)
for blink in [1, 2, 3]:
writePin(ledPin, true)
wait(0.25)
writePin(ledPin, false)
wait(0.25)
writePin(ledPin, false)
Follow the board manufacturer’s electrical guidance and use appropriate
resistors, pull-ups or pull-downs, and safe voltage levels.
Words used with real circuits
A resistor limits electric current. A pull-up or pull-down helps give an input a clear high or low state when nothing else drives it. An uncertain input is called floating. Follow the manufacturer’s circuit guidance when moving from the virtual workbench to real components.
