RPi::WiringPi::Pin - Access and manipulate Raspberry Pi GPIO pins
use RPi::WiringPi; use constant { INPUT => 0, OUTPUT => 1, ON => 1, OFF => 0, }; my $pi = RPi::WiringPi->new; my $pin = $pi->pin(5); $pin->mode(OUTPUT); $pin->write(ON); my $pin_num = $pin->num; my $pin_state = $pin->read; print "pin number $pin_num is in state $pin_state\n";
Through a RPi::WiringPi object, creates objects that directly attach to Raspberry Pi GPIO pins.
Using the pin object's methods, the GPIO pins can be controlled and monitored.
Takes the number representing the Pi's GPIO pin you want to use, and returns an object for that pin.
Parameters:
$pin_num
Mandatory.
The wiringPi representation of a pin number.
Puts the GPIO pin into either INPUT or OUTPUT mode. If $mode is not sent in, we'll return the pin's current mode.
$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 and 3 for GPIO_CLK (clock) mode.
0
1
2
3
Returns 1 if the pin is HIGH (on) and 0 if the pin is LOW (off).
For pins in OUTPUT mode, will turn on (HIGH) the pin, or off (LOW).
$state
Send in 1 to turn the pin on, and 0 to turn it off.
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.
Sets the level of the Pulse Width Modulation (PWM) of the pin. Dies if the pin's mode() is not set to PWM (2).
mode()
$value
Mandatory: values range from 0-1024. 0 for 0% (off) and 1024 for 100% (fully on).
1024
Returns the wiringPi numeric representation of the GPIO pin number attached to this pin object.
Steve Bertrand, <steveb@cpan.org>
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.
To install RPi::WiringPi, copy and paste the appropriate command in to your terminal.
cpanm
cpanm RPi::WiringPi
CPAN shell
perl -MCPAN -e shell install RPi::WiringPi
For more information on module installation, please visit the detailed CPAN module installation guide.