2014-06-05 00:20:22 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
require_once __DIR__."/../vendor/autoload.php";
|
|
|
|
|
2014-06-12 12:19:22 +00:00
|
|
|
/*
|
|
|
|
* This example will flash a led connected on pin 0 (GPIO17 on a Pi). If you are
|
|
|
|
* not on a Pi, please change (or remove) the mapper below and update the pin
|
|
|
|
* numbers to match.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2014-06-06 17:50:17 +00:00
|
|
|
use NoccyLabs\Gpio\Gpio;
|
|
|
|
use NoccyLabs\Gpio\GpioMapper\WiringPiMapper;
|
2014-06-05 00:20:22 +00:00
|
|
|
|
|
|
|
try {
|
2014-06-06 17:50:17 +00:00
|
|
|
$gpio = new Gpio();
|
2014-06-05 00:20:22 +00:00
|
|
|
} catch (Gpio\Exception $e) {
|
|
|
|
error_log("Error: {$e}");
|
|
|
|
}
|
|
|
|
|
2014-06-06 17:50:17 +00:00
|
|
|
// The mapper translates GPIO to logical pins and vice versa
|
|
|
|
$gpio->setMapper( new WiringPiMapper(2) );
|
|
|
|
|
|
|
|
// Access logical pin 0, since we got a mapper assigned. Otherwise this would
|
2014-06-12 00:35:19 +00:00
|
|
|
// be the actual GPIO0 pin.
|
2014-06-06 17:50:17 +00:00
|
|
|
$led = $gpio[0]
|
|
|
|
->export()
|
2014-06-12 00:54:55 +00:00
|
|
|
->setEdge(Gpio::EDGE_NONE)
|
|
|
|
->setDirection(Gpio::DIR_OUT)
|
|
|
|
->setLabel("LED pin")
|
|
|
|
->setValue(0);
|
2014-06-06 17:50:17 +00:00
|
|
|
|
2014-06-12 12:19:22 +00:00
|
|
|
// Flash the led
|
2014-06-12 00:35:19 +00:00
|
|
|
$x = 0;
|
|
|
|
while(true) {
|
|
|
|
$x = (int)(!$x);
|
2014-06-12 00:54:55 +00:00
|
|
|
$led->setValue($x)->dumpStatus(true);
|
2014-06-12 00:35:19 +00:00
|
|
|
usleep(500000);
|
|
|
|
}
|