Coder Social home page Coder Social logo

rpi-buttonwatcher's Introduction

NAME

RPi::ButtonWatcher - A button push event supplier

SYNOPSIS

use RPi::Wiring::Pi;
use RPi::ButtonWatcher;

die if wiringPiSetup() != 0;

# Takes WiringPi pin numbers.
my $watcher = RPi::ButtonWatcher.new(pins => ( 4, 5, 6 ), edge => BOTH, PUD => PULL_UP);
$watcher.getSupply.tap( -> %v {
    my $e = %v<edge> == Edge.RISING ?? 'up' !! 'down';
    say "Pin: %v<pin>, Edge: $e";
});

DESCRIPTION

This library provides a supplier of GPIO pin state changes.

Read/write access to /sys/class/gpio/export and /sys/class/gpio/gpioXX/ is required for this library to work. This usually means the user running the code has to be in the gpio group.

This module uses polling to detect state changes. A polling interval of 0.1 seconds is usually fast enough for normal button pushes.

The Sysfs interface is documented here: https://www.kernel.org/doc/Documentation/gpio/sysfs.txt

METHODS

new

Do initialize WiringPi before using this class using wiringPiSetup!

Takes the following parameters:

  • pins

A list of WiringPi pin numbers to watch.

  • edge

The edges to listen for.

* `Edge.RISING`

Triggered when a button is released.

* `Edge.FALLING`

Triggered when a button is pressed.

* `Edge.BOTH`

Triggered on both, button presses and releases.

  • debounce

Time in seconds to sleep between polls. Faster means more responsive, but also more system resource eating. Defaults to 0.1 (100ms).

getSupply

Returns a supply that can be tapped. The supply will emit hashes with two entries:

  • pin

The WiringPi pin number that was triggered.

  • edge

Either Edge.RISING or Edge.FALLING.

rpi-buttonwatcher's People

Contributors

patrickbkr2 avatar patrickbkr avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.