PHP code example of chickentikkamasala / gpio

1. Go to this page and download the library: Download chickentikkamasala/gpio library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

chickentikkamasala / gpio example snippets


'providers' => [

    ...
    
    \ChickenTikkaMasala\GPIO\Bridge\Laravel\GPIOServiceProvider::class,
    
    ...
    
];

$subscribe = [
    \ChickenTikkaMasala\GPIO\Bridge\Laravel\Events\EventSubscriber::class,
];

    'pins' => [
        'redled' => [
            'pin' => 1,
            'mode' => 'pwm',
        ],
    ],

    public function index(GPIOManager $manager) 
    {
        $manager->create('greenled', 2);
        $manager->greenled = 'ON';
    }

    public function index(GPIOManager $manager)
    {
        //create an analog sensor
        $manager->create('sensor', 3, 'aread');
        $value = $manager->sensor;
        
        return response()->json(['sensor' => $value]);
    }


use ChickenTikkaMasala\GPIO\GPIO;

class RedLED extends GPIO
{
    public function __construct()
    {
        parent::__construct(1, 'pwm', 'OFF');
    }
    
    public function getMethod()
    {
        return 'out';
    }
    
}

    public function index(GPIOManager $manager)
    {
        $redLED = new RedLED();
        $manager->add($redLED);
    }

    $manager->create('red', 1, 'LED');

    'modes' => [
        'LED' => \App\GPIO\Modes\LED::class,
    ],

    //PWM all the below = 1023
    $manager->redled = 'HIGH';
    $manager->redled = 'UP';
    $manager->redled = 'ON';
    
    //Where as for write and awrite: these equal to 1
    $manager->redled = 'HIGH';
    $manager->redled = 'UP';
    $manager->redled = 'ON';
    //all equal to 1
    
    //The below all equal to 0
    $manager->redled = 'LOW';
    $manager->redled = 'DOWN'
    $manager->redled = 'OFF';

    $redled = $manager->get('redled');
    
    //if you wanted to put it back simply use the add function again
    
    $manager->add('redled', $redled);

$redled = $manager->get('redled');
$redled->increment(1023, 200);
//redled will 'fade' from 0 to 1023 
//increment will increase every 200th millisecond

$redled->decrement(0, 200);

$manager->add('redled', $redled);

    'pins' => [
        'redled' => [
            'pin' => 18, //wiring pi pin 1 = BCM pin 18
            'mode' => 'pwm',
            'options' => [
                '-g',
            ],
        ],
    ],

    'pins' => [
        'redled' => [
            'pin' => 18,
            'mode' => 'pwm',
            'defaultValue' => 1023,//turn pin on full on boot of application 
        ],
    ],
bash
php artisan vendor:publish --provider="ChickenTikkaMasala\GPIO\Bridge\Laravel\GPIOServiceProvider"
bash
php artisan gpio:set redled 1023
bash
php artisan gpio:list