Beispiel #1
0
<?php

include 'gpiohelper.php';
/*

This script toggles an LED 6 times when a button is pressed, then exits.

pin 0 - button
pin 1 - LED and resistor
*/
$io = new GPIO([0 => 'in', 1 => 'out']);
header('content-type: text/plain');
$io->onChange(0, function (GPIOEvent $event) {
    static $count = 0;
    if ($event->state == 1) {
        // button is down
        $state = $event->io->getPin(1);
        $event->io->setPin(1, 1 - $state);
        $count++;
        if ($count >= 6) {
            $event->io->end();
        }
    }
});
$io->run();
echo 'done';
<?php

include 'gpiohelper.php';
/*

This script cycles a 7-segment display through the numbers 0-9, then exits.

pin 0 - button
other pins - see declaration of GPIOSevenSegmentDisplay
*/
$io = new GPIO([0 => 'in', 1 => 'out']);
header('content-type: text/plain');
$io->addComponent('display', new GPIOSevenSegmentDisplay($io, ['a' => 1, 'b' => 23, 'c' => 13, 'd' => 14, 'e' => 6, 'f' => 7, 'g' => 26]));
$io->display->setValue(0);
$io->onChange(0, function (GPIOEvent $event) {
    static $count = 0;
    if ($event->state == 1) {
        // button is down
        $count++;
        $event->io->display->setValue($count);
        if ($count >= 9) {
            $event->io->end();
        }
    }
});
$io->run();
echo 'done';
Beispiel #3
0
00000010
00000001
00000000
1
0
0
0
0
0
0
0
0
0
LINES;
$lines = explode("\n", $lines);
$io->onClock(7, function (GPIOEventClock $event) use(&$lines) {
    if ($line = next($lines)) {
        setLine($line);
    } else {
        reset($lines);
    }
    time_nanosleep(0, 100000000);
});
$io->onChange(7, function (GPIOEventPinStateChange $event) {
    $event->io->end();
});
$io->run();
echo 'done';
?>
<a href="/php/shifttest.php" style="padding:15px; background-color: #999999;color: black;border:1px solid #666666">Run Again</a>