PHP Classes

File: example/pulse.php

Recommend this page to a friend!
  Classes of Andrew Collington   iWire PHP Raspberry PI GPIO Class   example/pulse.php   Download  
File: example/pulse.php
Role: Example script
Content type: text/plain
Description: Example script
Class: iWire PHP Raspberry PI GPIO Class
Control a Raspberry PI board using GPIO
Author: By
Last change:
Date: 6 years ago
Size: 821 bytes
 

Contents

Class file image Download
<?php

/**
 * Phpiwire: A PHP wrapper for wiringPi
 *
 * Example of using hardware PWM to pulse an LED.
 *
 * @author Andrew Collington, andy@amnuts.com
 * @version 0.2.0
 * @link https://github.com/amnuts/phpiwire
 * @license MIT, http://acollington.mit-license.org/
 */

namespace Phpiwire;

if (
PHP_SAPI !== 'cli') {
    echo
'Sorry, you can only use this via the command line.';
    return;
}

set_time_limit(0);

echo
"Raspberry Pi pulse - use ^C to stop\n";

$pi = new Board();
$p = $pi->getPin(1)->mode(Pin::PWM_OUT);
$p->pwmWrite(0);

$sleep = 500;
$pwmValue = 1024; // 0 min, 1024 max

while (true) {
    for (
$i = 0; $i <= $pwmValue; ++$i) {
       
$p->pwmWrite($i);
       
usleep($sleep);
    }
   
sleep(1);
    for (
$i = $pwmValue; $i > 0; --$i) {
       
$p->pwmWrite($i);
       
usleep($sleep);
    }
}