php-linux-gpio/examples/bitmap.php

46 lines
816 B
PHP
Raw Permalink Normal View History

<?php
require_once __DIR__."/../vendor/autoload.php";
2014-06-13 23:32:20 +00:00
require_once __DIR__."/GLOBALS.php";
/*
* This example demonstrates mapping GpioPins to bit values and writing bits
* in parallel.
*
*/
use NoccyLabs\Gpio\Gpio;
use NoccyLabs\Gpio\Util\BitmappedGpio;
use NoccyLabs\Gpio\GpioMapper\WiringPiMapper;
$gpio = new Gpio();
$gpio->setMapper( new WiringPiMapper(2) );
$par = new BitmappedGpio();
for($n = 0; $n < 7; $n++) {
$pin = $gpio[$n]->setDirection("out");
$par->setGpioPin($n,$pin);
}
for($n = 0; $n < 5; $n++) {
$par->write(0xFF);
usleep(300000);
$par->write(0x00);
usleep(300000);
}
for($n = 1; $n < 16; $n++) {
$par->write($n);
usleep(500000);
}
for($m = 0; $m < 20; $m++) {
2014-06-13 12:06:27 +00:00
foreach(array(0, 0, 8, 12, 14, 15, 7, 3, 1, 0) as $n) {
$par->write($n);
usleep(100000);
}
}
$par->write(0);