Robots with PHP

hold on to your butts!

Robots with PHP

hold on to your butts!

Don't use PHP

Don't use PHP

This is experimental

but it's also fun

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!

Look!

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>");
    }
);

WAAAAAAAAAAAAAAT

github.com/oasynnoum/phpmake_serialport

It's cheap!

It's fun!

Introduce your people to coding!

Thanks

twitter.com/assertchris

Robots with PHP

By Christopher Pitt

Robots with PHP

  • 1,515