Armed the gpio class
This commit is contained in:
		
							
								
								
									
										35
									
								
								examples/rf-remote.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										35
									
								
								examples/rf-remote.php
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,35 @@
 | 
			
		||||
<?php
 | 
			
		||||
 | 
			
		||||
require_once __DIR__."/../vendor/autoload.php";
 | 
			
		||||
 | 
			
		||||
use NoccyLabs\Gpio\Gpio;
 | 
			
		||||
use NoccyLabs\Gpio\GpioMapper\WiringPiMapper;
 | 
			
		||||
 | 
			
		||||
try {
 | 
			
		||||
    $gpio = new Gpio(true);
 | 
			
		||||
} catch (Gpio\Exception $e) {
 | 
			
		||||
    error_log("Error: {$e}");
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// The mapper translates GPIO to logical pins and vice versa
 | 
			
		||||
$gpio->setMapper( new WiringPiMapper(2) );
 | 
			
		||||
 | 
			
		||||
// Access logical pin 0, since we got a mapper assigned. Otherwise this would
 | 
			
		||||
// be the actual GPIO0 pin.
 | 
			
		||||
$led = $gpio[0]
 | 
			
		||||
    ->export()
 | 
			
		||||
    ->setDirection("input")
 | 
			
		||||
    ->setEdge("rising")
 | 
			
		||||
    ->setHandler(function($e) use($gpio) {
 | 
			
		||||
        
 | 
			
		||||
    })
 | 
			
		||||
    ->setLabel("rfint")
 | 
			
		||||
    ->dumpStatus(true);
 | 
			
		||||
 | 
			
		||||
for($n = 1; $n < 5; $n++) {
 | 
			
		||||
    $gpio[$n]
 | 
			
		||||
        ->setDirection("input")
 | 
			
		||||
        ->setLabel("rfbt{$n}")
 | 
			
		||||
        ->dumpStatus(true);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
		Reference in New Issue
	
	Block a user