Skip to content

Commit 14973ec

Browse files
committed
Added hardware PWM write ability and example PHP script.
Updated version to 0.1.0.
1 parent b04f645 commit 14973ec

File tree

7 files changed

+51
-6
lines changed

7 files changed

+51
-6
lines changed

config.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555
"name": "PHPiWire",
5656
"description": "Control the RaspberryPi GPIO via PHP (with wiringPi)",
5757
"author": "Andrew Collington (andy@amnuts.com)",
58-
"version": "0.0.1",
58+
"version": "0.1.0",
5959
"verbose": false,
6060
"requires": {
6161
"extensions": []

example/blink.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* Example of blinking an LED connected to pin 0
77
*
88
* @author Andrew Collington, andy@amnuts.com
9-
* @version 0.0.1
9+
* @version 0.1.0
1010
* @link https://github.com/amnuts/phpiwire
1111
* @license MIT, http://acollington.mit-license.org/
1212
*/

example/board.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* Get the board information
77
*
88
* @author Andrew Collington, andy@amnuts.com
9-
* @version 0.0.1
9+
* @version 0.1.0
1010
* @link https://github.com/amnuts/phpiwire
1111
* @license MIT, http://acollington.mit-license.org/
1212
*/

example/pin.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* Checking pin status
77
*
88
* @author Andrew Collington, andy@amnuts.com
9-
* @version 0.0.1
9+
* @version 0.1.0
1010
* @link https://github.com/amnuts/phpiwire
1111
* @license MIT, http://acollington.mit-license.org/
1212
*/

example/pulse.php

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<?php
2+
3+
/**
4+
* Phpiwire: A PHP wrapper for wiringPi
5+
*
6+
* Example of using hardware PWM to pulse an LED.
7+
*
8+
* @author Andrew Collington, andy@amnuts.com
9+
* @version 0.1.0
10+
* @link https://github.com/amnuts/phpiwire
11+
* @license MIT, http://acollington.mit-license.org/
12+
*/
13+
14+
namespace Phpiwire;
15+
16+
if (PHP_SAPI !== 'cli') {
17+
echo 'Sorry, you can only use this via the command line.';
18+
return;
19+
}
20+
21+
set_time_limit(0);
22+
23+
echo "Raspberry Pi pulse - use ^C to stop\n";
24+
25+
$pi = new Board();
26+
$p = $pi->getPin(1)->mode(Pin::PWM_OUT);
27+
$p->pwmWrite(0);
28+
29+
$sleep = 500;
30+
$pwmValue = 1024; // 0 min, 1024 max
31+
32+
while (true) {
33+
for ($i = 0; $i <= $pwmValue; ++$i) {
34+
$p->pwmWrite($i);
35+
usleep($sleep);
36+
}
37+
sleep(1);
38+
for ($i = $pwmValue; $i > 0; --$i) {
39+
$p->pwmWrite($i);
40+
usleep($sleep);
41+
}
42+
}

phpiwire/Board.zep

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* Phpiwire: A PHP wrapper for wiringPi
33
*
44
* @author Andrew Collington, andy@amnuts.com
5-
* @version 0.0.1
5+
* @version 0.1.0
66
* @link https://github.com/amnuts/phpiwire
77
* @license MIT, http://acollington.mit-license.org/
88
*

phpiwire/Pin.zep

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* Phpiwire: A PHP wrapper for wiringPi
33
*
44
* @author Andrew Collington, andy@amnuts.com
5-
* @version 0.0.1
5+
* @version 0.1.0
66
* @link https://github.com/amnuts/phpiwire
77
* @license MIT, http://acollington.mit-license.org/
88
*
@@ -204,6 +204,9 @@ class Pin
204204
case self::ANALOG:
205205
%{ analogWrite(pin, value); }%
206206
break;
207+
case self::PWM:
208+
%{ pwmWrite(pin, value); }%
209+
break;
207210
}
208211

209212
return this;

0 commit comments

Comments
 (0)