Skip to content

Instantly share code, notes, and snippets.

@kahagon
Created June 26, 2014 20:41
Show Gist options
  • Select an option

  • Save kahagon/9848c84d4677ced35c45 to your computer and use it in GitHub Desktop.

Select an option

Save kahagon/9848c84d4677ced35c45 to your computer and use it in GitHub Desktop.
<?php
require dirname(__FILE__) . '/vendor/autoload.php';
use \PHPMake\Firmata;
$devName = '/dev/tty.usbmodemfa131';
class DigitalPinObserver implements Firmata\Device\PinObserver {
public $count = 0;
public $limit = 3;
public function notify(Firmata\Device $dev, Firmata\Device\Pin $pin, $state) {
if ($state) {
$this->count += 1;
printf("%d回押されました。\n", $this->count);
if ($this->count == $this->limit) {
$dev->stop();
}
}
}
}
class Loop implements Firmata\LoopDelegate {
public function tick(Firmata\Device $device) {
//print __METHOD__.PHP_EOL;
}
public function getInterval() {
return 50000; // 50 milliseconds
}
}
$dev = new Firmata\Device($devName);
$dev->reportDigitalPin(13); // (1)
$dev->addDigitalPinObserver(new DigitalPinObserver()); // (2)
$dev->run(new Loop());// (3)
print "(^_^)/~\n";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment