php-linux-gpio/examples/softwarespi.php

26 lines
522 B
PHP
Raw Permalink Normal View History

2014-06-14 01:10:07 +00:00
<?php
require_once __DIR__."/../vendor/autoload.php";
require_once __DIR__."/GLOBALS.php";
use NoccyLabs\Gpio\Gpio;
use NoccyLabs\Gpio\GpioTickHandler;
use NoccyLabs\Gpio\Bus\SoftwareSpiBus as SPI;
use NoccyLabs\Crap\Dumper;
2014-06-14 22:34:33 +00:00
$gpio = new Gpio();
2014-06-14 01:10:07 +00:00
// create spi bus
$spi = new SPI();
// bind the spi pins
$spi->sclk = $gpio[1];
$spi->mosi = $gpio[2];
$spi->miso = $gpio[3];
// write to the spi bus
$spi->write("\xBE\xEF");
// read the two bytes exchanged with the write()
$read = $spi->read(2);
//
Dumper::dump($read);