GPIO & ADC

Configure pins, read and write digital levels, watch edges, and sample analog inputs.


GPIO is the shortest path from source to a physical result. Start on the built-in LED and boot button, then move to circuit-specific pins.

gpio.output: $led_builtin
gpio.input: $boot_button

to show-button [
  if (gpio.read: $boot_button) = 0 [
    led.on:
  ] else [
    led.off:
  ]
]

show-button:

The common ESP32 boot button is active-low: pressed reads as 0. Other inputs depend on the circuit, pull resistors, and selected pin.

Digital Word Table

WordResultUse
gpio.modenilSet mode 0 for input or 1 for output
gpio.writenilWrite level 0 or 1
pinnilAlias for gpio.write
gpio.readIntRead digital level
gpio.inputnilConfigure input mode
gpio.outputnilConfigure output mode
gpio.highnilWrite level 1
gpio.lownilWrite level 0
gpio.togglenilRead and invert a level

The gpio.* helpers expose logical levels. Board LED helpers additionally use $led_active_level, so led.on: works on both active-high and active-low LEDs.

React To Edges

Register edge handlers inside a word, then call that word once:

to arm-button [
  on $boot_button falling debounce 25 [
    led.toggle:
  ]
]

arm-button:

Use rising, falling, or changes. Cancel every GPIO registration for the pin with cancel $boot_button. See Events for identity, output, and capacity rules.

Analog Input

raw is adc.read: $a0
percent is adc.percent: $a0
above-half? is adc.above: $a0, 2047
WordResultUse
adc.readIntRead the platform ADC value
adc.aboveBoolCompare one reading with a threshold
adc.percentIntMap the ESP32 0–4095 range to 0–100

An unconnected analog pin floats. A stable application circuit needs the appropriate source impedance, reference, filtering, and calibration; the language helper cannot replace those physical details.