Created
September 6, 2017 23:51
-
-
Save calcinai/40c6b9bf23cccdb3c1559fd5d2900fd0 to your computer and use it in GitHub Desktop.
Example for MCP3008 with PHPi
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
include __DIR__.'/../vendor/autoload.php'; | |
use Calcinai\PHPi\Peripheral\SPI; | |
use Calcinai\PHPi\Pin\PinFunction; | |
use Calcinai\PHPi\External\ADC\Microchip\MCP3008; | |
$board = \Calcinai\PHPi\Factory::create(); | |
//Flip the appropriate pins to their alt functions | |
$board->getPin(10)->setFunction(PinFunction::SPI0_MOSI); | |
$board->getPin(9)->setFunction(PinFunction::SPI0_MISO); | |
$board->getPin(11)->setFunction(PinFunction::SPI0_SCLK); | |
$board->getPin(8)->setFunction(PinFunction::SPI0_CE0_N); | |
$adc = new MCP3008($board->getSPI(SPI::SPI0), 0); | |
$pin = $board->getPin(18); | |
//In 10-bit, will be between 0 and 1024 | |
$value = $adc->getChannel(0)->read(); | |
if($value > 500){ | |
$pin->high(); | |
} else { | |
$pin->low(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi,
where can I find autoload.php?
Thanks in advance