PHP Classes

PHP Led Raspberry PI: Control led lights to turn on and off

Recommend this page to a friend!
  Info   View files Example   View files View files (4)   DownloadInstall with Composer Download .zip   Reputation   Support forum (1)   Blog (2)    
Ratings Unique User Downloads Download Rankings
Not enough user ratingsTotal: 151 All time: 9,041 This week: 109Up
Version License PHP version Categories
led_raspberry 1.0.0Custom (specified...5PHP 5, Hardware
Description 

Author

This class can control led lights to turn on and off.

It can access system variables in a Raspberry PI device to perform several types of operations to control led lights. Currently, it can:

- Turn on and off the led lights
- Set the control variables like export, unexport, direction

Innovation Award
PHP Programming Innovation award nominee
August 2021
Number 7
Raspberry PI is a popular platform for creating small hardware devices that can be controlled by software written in many languages, including PHP.

This package demonstrates how to control a Raspberry PI-based LED light system using PHP.

Manuel Lemos
Picture of Rafael Martin Soto
  Performance   Level  
Name: Rafael Martin Soto <contact>
Classes: 13 packages by
Country: Spain Spain
Age: 49
All time rank: 230058 in Spain Spain
Week rank: 84 Up3 in Spain Spain Up
Innovation award
Innovation award
Nominee: 7x

Winner: 4x

Example

<?php


/** Example of use led class
 * BLINK 2 LEDS EVERY SECOND. ONLY 1 IS ON AT A TIME FOR 10 TIMES.
 *
 * Class for get direct access to GPIO ports on a Raspberry pi with PHP. Made through fwrite() function
 *
 *
 * @author Rafael Martin Soto
 * @author {@link http://www.inatica.com/ Inatica}
 * @blog {@link https://rafamartin10.blogspot.com/ Rafa Martin's blog}
 * @since July 2021
 * @version 1.0.1
 * @license GNU General Public License v3.0 *
*/


include( 'led.class.php' );

// Get de file handle for Export & unexport

$fpUnexport = fopen( '/sys/class/gpio/unexport', 'w' );
$fpExport = fopen( '/sys/class/gpio/export', 'w' );

$Led18 = new Led( '18', $fpUnexport, $fpExport);
$Led23 = new Led( '23', $fpUnexport, $fpExport);

fclose( $fpExport ); // No need Export file handle more
unset( $fpExport );


for(
$i=0;$i<10;$i++){
    if(
$i%2 == 0){
       
$Led18->On();
       
$Led23->Off();
    } else {
       
$Led18->Off();
       
$Led23->On();
    }

   
sleep(1);
}

// Power off leds
$Led18->Off();
$Led23->Off();

// Unexport leds
$Led18->unexport();
$Led23->unexport();

fclose($fpUnexport); // close file handle unexport

// Free Mem
unset( $Led18 );
unset(
$Led23 );
unset(
$i );
unset(
$fpUnexport );
?>


  Files folder image Files  
File Role Description
Accessible without login Plain text file example.php Example Example script
Plain text file led.class.php Class Class source
Accessible without login Plain text file LICENSE Lic. License text
Accessible without login Plain text file README.md Doc. Documentation

 Version Control Unique User Downloads Download Rankings  
 100%
Total:151
This week:0
All time:9,041
This week:109Up
User Comments (1)
Great work overall!
2 years ago (Filip Komar)
80%StarStarStarStarStar