Improved sysfs file access code
This commit is contained in:
@ -2,6 +2,21 @@
|
||||
|
||||
require_once __DIR__."/../vendor/autoload.php";
|
||||
|
||||
/*
|
||||
* This example demonstrates using a 4-button wireless remote control with the
|
||||
* GPIO, in this case with the pins mapped against WiringPi for a Rev2 board.
|
||||
* If you are using this code with any other hardware, please update the mapper
|
||||
* below.
|
||||
*
|
||||
* It is assumed that Pin 0 is the interrupt pin (VT) to signal when a button
|
||||
* press has been received, and Pin 1-4 are connected to the pins for button
|
||||
* A to D on the remote control.
|
||||
*
|
||||
* Note that the Raspberry Pi GPIO is not 5V tolerant, so use an optoisolator
|
||||
* or transistors to ensure that you don't zap your preciouos hardware.
|
||||
*
|
||||
*/
|
||||
|
||||
use NoccyLabs\Gpio\Gpio;
|
||||
use NoccyLabs\Gpio\GpioMapper\WiringPiMapper;
|
||||
|
||||
@ -21,7 +36,12 @@ $led = $gpio[0]
|
||||
->setDirection("input")
|
||||
->setEdge("rising")
|
||||
->setHandler(function($e) use($gpio) {
|
||||
|
||||
if ($gpio[1]->getValue()) { echo "A"; }
|
||||
elseif ($gpio[2]->getValue()) { echo "B"; }
|
||||
elseif ($gpio[3]->getValue()) { echo "C"; }
|
||||
elseif ($gpio[4]->getValue()) { echo "D"; }
|
||||
else { echo "None"; }
|
||||
echo "\n";
|
||||
})
|
||||
->setLabel("rfint")
|
||||
->dumpStatus(true);
|
||||
@ -33,3 +53,7 @@ for($n = 1; $n < 5; $n++) {
|
||||
->dumpStatus(true);
|
||||
}
|
||||
|
||||
while(true) {
|
||||
$gpio->refresh();
|
||||
usleep(10000);
|
||||
}
|
||||
|
Reference in New Issue
Block a user