PHP code example of se / wired-pi

1. Go to this page and download the library: Download se/wired-pi library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

se / wired-pi example snippets




use \SE\Component\WiredPi;

$platform = new WiredPi\Platform\RaspberryPi();
$board = new WiredPi\Board($platform);

$map = new WiredPi\PortMap(array(
    // number of the GPIO-pin,
    18
    // you can set default options too, STATE_ON turns the pin by default on
    23 => array(WiredPi\Port::STATE => WiredPi\Port::STATE_ON)
));

$board->setPorts($map);
$board->refresh(); // applies the current state to the microcontroller

// Modification of ports need to be applied again
$board->getPort(18)->on();
$board->refresh();

$port = $board->getPort(18);
$status = $platform->read($port); // returns 0 or 1

$port = $board->getPort(18);
$port->setMode(WiredPi\Port::MODE_IN);

// Do something when Pin switches to 1
while(true) {
    
    if($platform->read($port) == '1') {
        print sprintf('Pin %s went to %s', $port, '1')
        break;
    }
    usleep(5000); // Let the system catch up
}
bash
$ php -S localhost:8000 scripts/server.php