Recommend this page to a friend! |
Download .zip |
Info | Example | View files (4) | Download .zip | Reputation | Support forum (1) | Blog (2) | Links |
Ratings | Unique User Downloads | Download Rankings | ||||
Not enough user ratings | Total: 155 | All time: 9,021 This week: 571 |
Version | License | PHP version | Categories | |||
led_raspberry 1.0.0 | Custom (specified... | 5 | PHP 5, Hardware |
Description | Author | |
This class can control led lights to turn on and off. Innovation Award
|
<?php |
We can access GPIO ports directly with fwrite() for power on|off leds, without use shell_exec() function. The result is a fasted library to access GPIO ports. This one is written to manage LEDS, but with a litlle changes you can use it for other components (buttons, relay, ....)
# REQUERIMENTS:
- A minimum (minimum, minimum, minimum requeriments is needed). Tested on:
- Simple Raspberry pi (B + 512MB 700 MHz ARM11) with Raspbian Lite PHP7.3 (i love this gadgets) :heart_eyes:
# FILES: There are 2 files:
led.class.php -> Master class. This file is the main file that you need to include in your code.
example.php -> Code with example use of the class
# INSTALLATION: A lot of easy :smiley:. It is written in PURE PHP. Only need to include the files. Tested on basic PHP installation
require_once( 'led.class.php' );
# BASIC USAGE:
- Create the variable with led class on GPIO 18:
$Led18 = new Led( '18' );
- Power ON GPIO led 18:
$Led18->On();
- Power OFF GPIO led 18:
$Led18->Off();
- Unexport GPIO port 18:
$Led18->unexport();
CREATE LED ON GPIO PORT 'X':
Without file handles:
$Led18 = new Led( '18' ); // Without file handles
// Here your code using power on off on leds as you want
// ......
// Remember do Unexport at the end of your code
$Led18->unexport();
With file handles:
$fpUnexport = fopen( '/sys/class/gpio/unexport', 'w' );
$fpExport = fopen( '/sys/class/gpio/export', 'w' );
$Led18 = new Led( '18', $fpUnexport, $fpExport); // With file handles
// Here your code using power on off on leds as you want
// ......
// Remember do Unexport & close files at the end of your code
$Led18->unexport();
fclose( $fpUnexport );
fclose( $fpExport );
Power ON led:
$Led18->On();
Power OFF led:
$Led18->Off();
Unexport GPIO PORT:
$Led18->unexport();
<?php
require_once( 'led.class.php' );
// Create the variable with led class on GPIO 18:
$Led18 = new Led( '18' );
// Power ON GPIO led 18:
$Led18->On();
// Wait 5 seconds
sleep(5);
//Power OFF GPIO led 18:
$Led18->Off();
//Unexport GPIO port 18:
$Led18->unexport();
?>
Of course. You can use it freely :vulcan_salute::alien:
By Rafa.
@author Rafael Martin Soto
@author {@link http://www.inatica.com/ Inatica}
@blog {@link https://rafamartin10.blogspot.com/ Rafael Martin's Blog}
@since July 2021
@version 1.0.0
@license GNU General Public License v3.0
Files |
File | Role | Description |
---|---|---|
example.php | Example | Example script |
led.class.php | Class | Class source |
LICENSE | Lic. | License text |
README.md | Doc. | Documentation |
Version Control | Unique User Downloads | Download Rankings | |||||||||||||||
100% |
|
|
User Comments (1) | |||||
|
Applications that use this package |
If you know an application of this package, send a message to the author to add a link here.
Related pages |
Author blog inform of Launch PHP Led Raspberry PI |