The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

RPi::WiringPi::Pin - Access and manipulate Raspberry Pi GPIO pins

SYNOPSIS

    use RPi::WiringPi::Pin;
    use RPi::Constant qw(:all);

    my $pin = RPi::WiringPi::Pin->new(5);

    $pin->setup;

    $pin->mode(INPUT);
    $pin->write(LOW);

    $pin->set_interrupt(EDGE_RISING, 'pin5_interrupt_handler');

    my $num = $pin->num;
    my $mode = $pin->mode;
    my $state = $pin->read;

    print "pin number $num is in mode $mode with state $state\n";

    sub pin5_interrupt_handler {
        print "in interrupt handler\n";
    }

DESCRIPTION

An object that represents a physical GPIO pin.

Using the pin object's methods, the GPIO pins can be controlled and monitored.

Using this module outside of the base RPi::WiringPi object requires you to run one of the WiringPi::API's setup* methods.

METHODS

new($pin_num)

Takes the number representing the Pi's GPIO pin you want to use, and returns an object for that pin.

Parameters:

    $pin_num

Mandatory.

Mandatory: The pin number to attach to.

mode($mode)

Puts the GPIO pin into either INPUT or OUTPUT mode. If $mode is not sent in, we'll return the pin's current mode.

Parameters:

    $mode

Optional: If not sent in, we'll simply return the current mode of the pin. Otherwise, send in: 0 for INPUT, 1 for OUTPUT, 2 for PWM_OUT and 3 for GPIO_CLOCK (clock) mode.

read()

Returns 1 if the pin is HIGH (on) and 0 if the pin is LOW (off).

write($state)

For pins in OUTPUT mode, will turn on (HIGH) the pin, or off (LOW).

Parameters:

    $state

Send in 1 to turn the pin on, and 0 to turn it off.

pull($direction)

Used to set the internal pull-up or pull-down resistor for a pin.

Parameter:

    $direction

Mandatory: 2 for UP, 1 for DOWN and 0 to turn off the resistor.

interrupt_set($edge, $callback)

Listen for an interrupt on a pin, and do something if it is triggered.

Parameters:

    $edge

Mandatory: 1 (falling), 2 (rising), or 3 for both.

    $callback

The string name of a Perl subroutine that you've already written within your code. This is the interrupt handler. When an interrupt is triggered, the code in this subroutine will run.

interrupt_unset()

Removes an interrupt from the pin, if set.

pwm($value)

Sets the level of the Pulse Width Modulation (PWM) of the pin. Dies if the pin's mode() is not set to PWM (2).

Parameter:

    $value

Mandatory: values range from 0-1023. 0 for 0% (off) and 1023 for 100% (fully on).

num()

Returns the pin number associated with the pin object.

SEE ALSO

AUTHOR

Steve Bertrand, <steveb@cpan.org>

COPYRIGHT AND LICENSE

Copyright (C) 2016 by Steve Bertrand

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.18.2 or, at your option, any later version of Perl 5 you may have available.