Exemplo n.º 1
0
<?php

if ($argc < 2) {
    print 'specify port' . PHP_EOL;
    exit(1);
}
use PHPMake\SerialPort;
$retval = 0;
$device = $argv[1];
$baudRate = 9600;
$prompt = 'brightness>';
$port = new SerialPort();
try {
    $port->open($device);
    $port->setBaudRate($baudRate);
    $port->setFlowControl(SerialPort::FLOW_CONTROL_NONE);
    $port->setCanonical(false);
    $port->setVTime(0)->setVMin(0);
    $stdin = fopen('php://stdin', 'r');
    print $prompt;
    while (FALSE !== ($line = fgets($stdin))) {
        if (preg_match('/^(?:quit|exit)/', $line)) {
            break;
        }
        $brightness = pack('C', (int) $line);
        $port->write($brightness);
        print $prompt;
    }
    fclose($stdin);
} catch (Exception $e) {
    print 'exception occurred' . PHP_EOL;
Exemplo n.º 2
0
 * アップロードされている必要があります。
 */
if ($argc != 2) {
    $filename = basename(__FILE__);
    print <<<EOU
使い方: php {$filename} port
    port    arduino が接続されたポート

EOU;
    exit(1);
}
use PHPMake\SerialPort;
//$pins = array(chr(55), chr(56), chr(57), chr(58), chr(59), chr(60), chr(61));
$pins = array('7', '8', '9', ':', ';', '<', '=');
$port = new SerialPort($argv[1]);
$port->setFlowControl(SerialPort::FLOW_CONTROL_SOFT)->setBaudRate(SerialPort::BAUD_RATE_38400);
$port->setCanonical(false)->setVTime(1)->setVMin(0);
print 'arduino の準備を待っています ';
while ($port->read(1) != '?') {
    print '.';
}
print '準備完了' . PHP_EOL;
$output = count($pins) . implode('', $pins);
$port->write($output);
$asc = true;
$sig = '1';
while (true) {
    $sig = $asc ? '1' : '0';
    foreach ($pins as $pin) {
        $port->write($sig . $pin);
        usleep(50000);