Module jls.util.Gpio
Manages the Raspberry Pi General Purpose Input Outputs (GPIO).
The GPIO channels are identified by their Broadcom number. The pigpio implementation expects the daemon to be available at localhost:8888.
Class Gpio
| Gpio:new () | Creates a new GPIO controller. |
| gpio:close () | Closes this GPIO instance. |
| gpio:set (num, name, value) | Sets a GPIO pin property value. |
| gpio:setBias (num[, value]) | Sets the internal bias pull/up down for a GPIO pin. |
| gpio:setDirection (num[, value]) | Sets the direction for a GPIO pin. |
| gpio:read (num) | Reads a GPIO channel. |
| gpio:write (num, level) | Writes a GPIO channel. |
| gpio:readStart (fn, ...) | Starts reading changes on pins. |
| gpio:readStop () | Stops reading changes. |
Class Gpio
This class represents a GPIO.
- Gpio:new ()
- Creates a new GPIO controller.
- gpio:close ()
- Closes this GPIO instance.
- gpio:set (num, name, value)
-
Sets a GPIO pin property value.
Parameters:
- num number The pin number from 0 to 53
- name string The property name to set
- value The property value to set
- gpio:setBias (num[, value])
-
Sets the internal bias pull/up down for a GPIO pin.
Parameters:
- num number The pin number
- value string The mode: default, pullup, pulldown or disable (optional)
- gpio:setDirection (num[, value])
-
Sets the direction for a GPIO pin.
Parameters:
- num number The pin number
- value string The direction: in or out (optional)
- gpio:read (num)
-
Reads a GPIO channel.
Parameters:
- num number The pin number
Returns:
-
jls.lang.Promise
A promise that resolves to the pin value
- gpio:write (num, level)
-
Writes a GPIO channel.
Parameters:
- num number The pin number
- level boolean The channel level
Returns:
-
jls.lang.Promise
A promise
- gpio:readStart (fn, ...)
-
Starts reading changes on pins.
The function is called with two arguments, error and message.
The message is a table containing the field: num, value, delay.
Corresponding to the pin number, the pin value as a boolean, the delay since last change in milli-seconds.
Parameters:
- fn function The function to call on pin value modification
- ... number The pin numbers to monitor for modification
Returns:
-
jls.lang.Promise
A promise
- gpio:readStop ()
-
Stops reading changes.
Returns:
-
jls.lang.Promise
A promise