PHP code example of calcinai / phpi

1. Go to this page and download the library: Download calcinai/phpi 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/ */

    

calcinai / phpi example snippets


$board = \Calcinai\PHPi\Factory::create();

use Calcinai\PHPi\Pin\PinFunction;
use Calcinai\PHPi\Pin;

$pin = $board->getPin(17) //BCM pin number
             ->setFunction(PinFunction::INPUT)
             ->setPull(Pin::PULL_UP);

//Will be === to Pin::LEVEL_HIGH or Pin::LEVEL_LOW
var_dump($pin->getLevel());

$pin->setFunction(PinFunction::OUTPUT);
$pin->high();
$pin->low();

$button = new Button($board->getPin(17));
$led = new LED($board->getPin(18));

$button->on('press', [$led, 'on']);
$button->on('release', [$led, 'off']);

$board->getLoop()->run();