Christopher Pitt
Writer and coder, working at ringier.co.za
hold on to your butts!
hold on to your butts!
composer require carica/firmata
ls /dev | grep usbmodem
use Carica\Io; use Carica\Firmata; $board = new Firmata\Board( Io\Stream\Serial\Factory::create( "/dev/cu.usbmodem1441", 57600 ) );
$loop = Io\Event\Loop\Factory::get();
print "connecting" . PHP_EOL;
$board
->activate()
->done(function () use ($board) {
print "connected" . PHP_EOL;
$pin = $board->pins[13]; $pin->mode = Firmata\Pin::MODE_OUTPUT; $pin->digital = 1; // ...on!
use Amp\ReactAdapter\ReactAdapter;
use Carica\Firmata;
use Carica\Io;
$adapter = new Io\Event\Loop\React();
$adapter->loop(ReactAdapter::get());
Io\Event\Loop\Factory::set($adapter);
$board = new Firmata\Board(
Io\Stream\Serial\Factory::create(
$port, 57600
)
);
$router->route( "GET", "/forward", ($request, $response) => { $enableA->digital = 1; $enableB->digital = 1; $control1A->digital = 1; $control2A->digital = 0; $control1B->digital = 1; $control2B->digital = 0; $response->end("forward<br>"); } );
$router->route( "GET", "/stop", ($request, $response) => { $enableA->digital = 0; $enableB->digital = 0; $response->end("stop<br>"); } );
twitter.com/assertchris
By Christopher Pitt