Home Contents | # gpio.new | Gpio | Core4 Lua Event System

## SYNOPSIS

1. gpiohandle = gpio.new(app, callback)
2. function callback(event) ...
3. gpiohandle:close()

## DESCRIPTION

Create a new GPIO event handler. The handler is attached to the event processor passed in app.

Events are reported by calling the passed callback function. The parameter event is a table containing fields describing the event.

type | The event type. This is one of the GPIO_xxx type values from lua/gpio.lh.
pin | The pin number where the event happened.
group | The pin group where the event happened. This is either one of the predefined GPGRP_xxx values from lua/gpio.lh or a group ID registered with gpio.register().
value | The value associated with the event.
rising, falling | For events that report edge counters, these fields contain the counter values. These events do not report a value field.

The gpio:close() will close the GPIO handler when no longer needed. The handle becomes invalid. This automatically happens during garbage collection, but that takes an unknown amount of time.

## RETURN VALUE

Returns a gpio event handler instance.

## NOTES

Call gpio.new() only once per application. With more than one event handler, it is undefined which handler will get the events.

## SEE ALSO

gpio.watch