2014-06-05 00:20:22 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
require_once __DIR__."/../vendor/autoload.php";
|
2014-06-13 12:04:04 +00:00
|
|
|
require_once __DIR__."/GLOBALS.php";
|
2014-06-05 00:20:22 +00:00
|
|
|
|
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-13 12:04:04 +00:00
|
|
|
$led = $gpio[LED_A]
|
2014-06-06 17:50:17 +00:00
|
|
|
->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);
|
|
|
|
}
|