Created
June 26, 2014 20:41
-
-
Save kahagon/9848c84d4677ced35c45 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 | |
| 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