php-linux-gpio/examples/basic.php

31 lines
625 B
PHP
Raw Normal View History

2014-06-05 00:20:22 +00:00
<?php
require_once __DIR__."/../vendor/autoload.php";
use NoccyLabs\Gpio\Gpio;
use NoccyLabs\Gpio\GpioMapper\WiringPiMapper;
2014-06-05 00:20:22 +00:00
try {
$gpio = new Gpio();
2014-06-05 00:20:22 +00:00
} catch (Gpio\Exception $e) {
error_log("Error: {$e}");
}
// 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.
$led = $gpio[0]
->export()
->setDirection("output")
->setValue(0)
->dumpStatus(true);
2014-06-12 00:35:19 +00:00
$x = 0;
while(true) {
$x = (int)(!$x);
$led->setValue($x);
usleep(500000);
}