示例#1
0
文件: Output.php 项目: calcinai/phpi
 public function pulse($iterations = null, $interval = 1, $duty = 0.5)
 {
     $this->on();
     $on_time = $interval * $duty;
     $this->pin->getBoard()->getLoop()->addTimer($on_time, [$this, 'off'])->getLoop()->addPeriodicTimer($interval, function (TimerInterface $timer) use(&$iterations, $on_time) {
         if ($iterations !== null && --$iterations === 0) {
             $timer->cancel();
             return;
         }
         $this->on();
         $timer->getLoop()->addTimer($on_time, [$this, 'off']);
     });
 }