File "interface.php"

Full Path: /home/analogde/www/Virtual/work/interface.php
File size: 1.64 KB
MIME-type: text/x-php
Charset: utf-8

<?php

if ($_POST['initialized']!=1) {
    echo "Initializing port<br>";
    exec("echo 9 > /sys/class/gpio/export", $output, $return);
    exec("echo out > /sys/devices/virtual/gpio/gpio9/direction", $output, $return);
}

if ($_POST['led']==2) {
    echo "Led ON";
    exec("echo 1 > /sys/devices/virtual/gpio/gpio9/value", $output, $return);

}

if ($_POST['led']==1) {
    echo "Led OFF";
    exec("echo 0 > /sys/devices/virtual/gpio/gpio9/value", $output, $return);
}

?>


<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8" />
        <title>Raspberry Pi Gpio</title>
	    <script src="script.js"></script>
		
    </head>
 
    <body style="background-color: black;">
     <!-- On/Off button's picture -->
	 <?php
	 //this php script generate the first page in function of the gpio's status
	 $status = array (0, 0, 0, 0, 0, 0, 0, 0);
	 for ($i = 0; $i < count($status); $i++) {
		//set the pin's mode to output and read them
		system("gpio mode ".$pin." out");
		exec ("gpio read ".$i, $status[$i], $return );
		//if off
		if ($status[$i][0] == 0 ) {
		echo ("<img id='button_".$i."' src='data/img/red/red_".$i.".jpg' alt='off'/>");
		}
		//if on
		if ($status[$i][0] == 1 ) {
		echo ("<img id='button_".$i."' src='data/img/green/green_".$i.".jpg' alt='on'/>");
		}	 
	 }
	 ?>


<form method="post">
<input type="hidden" name="led" value="2">
<input type="hidden" name="initialized" value="1">
<input type="submit" name="submit" value="Led ON"><br>
</form>

<form method="post">
<input type="hidden" name="led" value="1">
<input type="hidden" name="initialized" value="1">
<input type="submit" name="submit" value="Led OFF"><br>
</form>


   </body>
</html>