GPIO

CONSTANTS

gpio.OUTPUT, gpio.INPUT
gpio.HIGH, gpio.LOW
gpio.FLOAT, gpio.PULLUP (version 1.0.20150115)


gpio.mode()

Description

initialize pin to GPIO mode, set the pin in/out mode.

Syntax

gpio.mode(pin, mode)

Parameters

pin: 0~15, GPIO index
mode: gpio.OUTPUT or gpio.INPUT
pull(option): gpio.FLOAT(default), gpio.PULLUP (version 1.0.20150115)

Returns

nil

Example

— set GPIO2 as output.
gpio.mode(2, gpio.OUTPUT)

— set GPIO4 as input with internal weak pull up.
gpio.mode(4, gpio.INPUT, gpio.PULLUP)

See also

– gpio.read()
– gpio.write()


gpio.read()

Description

read pin value.

Syntax

gpio.read(pin)

Parameters

pin: 0~15, GPIO index

Returns

number:0 – low, 1 – high

Example

— read value of gpio 2.
gpio.read(2)

See also

– gpio.mode()
– gpio.write()


gpio.write()

Description

set pin value.

Syntax

gpio.write(pin)

Parameters

pin: 0~15, GPIO index
level: gpio.HIGH or gpio.LOW

Returns

nil

Example

— set GPIO2 to GPIO mode, and set the pin to high.
pin=2
gpio.mode(pin, gpio.OUTPUT)
gpio.write(pin, gpio.HIGH)

See also

– gpio.mode()
– gpio.read()