<?php if (\Request::method() === 'POST') { $pin = \Request::input('pin'); $state = \Request::input('state'); if (empty($pin) && $pin !== 0 || empty($state) && $state !== 0) { throw new \DreamFactory\Core\Exceptions\BadRequestException('Please provide pin and state data'); } $gpio = new \a15lam\RpiGpio\GPIO(); $result = $gpio->mode($pin, $state); $result = empty($result) ? ['success' => true] : $result; return \DreamFactory\Core\Utility\ResourcesWrapper::cleanResources($result); } else { throw new \DreamFactory\Core\Exceptions\BadRequestException('Only POST is accepted'); }
<?php include 'src/GPIO.php'; $gpio = new \a15lam\RpiGpio\GPIO(); $gpio->mode(0, 'out'); $gpio->mode(2, 'out'); while (true) { $gpio->write(0, 1); sleep(1); $gpio->write(0, 0); $gpio->write(2, 1); sleep(1); $gpio->write(2, 0); }