Class for manage directly leds on raspberry pi in PHP

Overview

led_raspberry

Class for manage directly leds on raspberry pi in 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) 😍

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 😃 . 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();
    

RESUME OF METHODS:

CREATE LED ON GPIO PORT 'X':

  • You can pass $fpUnexport & $fpExport file handles if you have more than 1 led. In this way, only 1 file will be openned for Export and Unexport. If not params given, every led will open and close individually files for export and unexport. With $fpUnexport & $fpExport params yo will get a better performance.

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();

Example

     <?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 🖖 👽

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

You might also like...
A small package to add computed properties to any PHP class. 🐘

Computed Properties This package provides a trait and attribute that can provide computed property support. Installation This package can be installed

A lightweight php class for formatting sql statements. Handles automatic indentation and syntax highlighting.

A lightweight php class for formatting sql statements. Handles automatic indentation and syntax highlighting.

Allows generate class files parse from json and map json to php object, including multi-level and complex objects;

nixihz/php-object Allows generate class files parse from json and map json to php object, including multi-level and complex objects; Installation You

Simple class that implement a CAPTCHA for your PHP App.

simple-captcha Simple class that implement a CAPTCHA for your PHP App. Installation Use the package manager composer to install. composer require will

Php-timer - Utility class for timing

phpunit/php-timer Utility class for timing things, factored out of PHPUnit into a stand-alone component. Installation You can add this library as a lo

Polonium is a world class old school ✍️ blog website made with Php and Tailwind 🌀

Polonium Polonium is a world class old school ✍️ blog website made with Php and Tailwind 🌀 to write dump articles about... Yeah I know, you should pr

This PHP class uploads files and manipulates images very easily

This PHP class uploads files and manipulates images very easily. It is in fact as much as an image processing class than it is an upload class. Compatible with PHP4, 5 and 7. Supports processing of local files, uploaded files, files sent through XMLHttpRequest.

My solution use PHP with a class for easy setup

My solution use PHP with a class for easy setup. It accepts requests with the get method just passing the username and password as well as the ip and http port of the Proxmox server. Just needing a web server.

PHP class for convert KA letters to LAT and back

Kautilities PHP class for convert KA letters to LAT and back Installation Install this package through Composer. Edit your project's composer.json fil

Owner
Rafael Martin Soto
PHP programmer. Passionate about PHP programming and artificial intelligence. Nice projects done with servers and raspberry pi ^_^
Rafael Martin Soto
A status monitor for Elite Dangerous, written in PHP. Designed for 1080p screens in the four-panel-view in panel.php, and for 7 inch screens with a resolution of 1024x600 connected to a Raspberry Pi.

EDStatusPanel A status monitor for Elite Dangerous, written in PHP. Designed for 1080p screens in the four-panel-view in panel.php, and for 7 inch scr

marcus-s 24 Oct 4, 2022
A PHP library to play with the Raspberry PI's GPIO pins

php-gpio php-gpio is a simple PHP library to play with the Raspberry PI's GPIO pins. It provides simple tools such as reading & writing to pins. [UPDA

Ronan Guilloux 266 Oct 17, 2022
Raspberry Pi Self Hosted Server Based on Docker / Portainer.io

Pi-Hosted Portainer Template V2 This repository is a collection of tutorials for hosting a variety of server applications using Docker and Portainer.

don 776 Jan 8, 2023
A now playing screen for the Raspberry Pi using the Last.fm API.

raspberry-pi-now-playing A now playing screen for the Raspberry Pi using the Last.fm API. This project is detailed, with photos of how I used it with

null 44 Dec 17, 2022
Raspberry Pi wifi hotspot with an offline-first community portal. Optionally shares internet access over Tor.

Raspberry Pi wifi hotspot with an offline-first community portal. Optionally shares internet access over Tor.

Martti Malmi 17 Dec 15, 2022
KodExplorer is a file manager for web. It is also a web code editor, which allows you to develop websites directly within the web browser.

KodExplorer is a file manager for web. It is also a web code editor, which allows you to develop websites directly within the web browser.

warlee 5.5k Feb 10, 2022
This tool can write the monolog standard log directly to clickhouse in real time via the tcp protocol

log2ck This tool can write the monolog standard log directly to clickhouse in real time via the tcp protocol. If you can write regular rules, other st

Hisune 9 Aug 15, 2022
Simple Plugin To Get EXP Directly To Inventory.

Simple Plugin To Get EXP Directly To Inventory.

HenryDM 6 Nov 21, 2022
Exploiting and fixing security vulnerabilities of an old version of E-Class. Project implemented as part of the class YS13 Cyber-Security.

Open eClass 2.3 Development of XSS, CSRF, SQLi, RFI attacks/defences of an older,vulnerable version of eclass. Project implemented as part of the clas

Aristi_Papastavrou 11 Apr 23, 2022
Optimizes class loading performance by generating a single PHP file containing all of the autoloaded files.

Class Preloader for PHP This tool is used to generate a single PHP script containing all of the classes required for a specific use case. Using a sing

Class Preloader 356 Nov 26, 2022