0

Here is my PHP script that I'm using to host a server for en Electronics class. The buttons are simply supposed to light up different LED's.

<!DOCTYPE html>
<HTML>
<BODY>
    <CENTER>
    <!-- Header -->
    <H1>Raspberry Pi LED Contorl Utility</H1>
    <body style="background-color: grey;">

    <!-- Configuring Pins -->
    <?php
    $pins = array(22,27,4,23,24,18,17);
    $status = array(0,0,0,0,0,0,0);

    //-----Decoration-----  
    for($i=0; $i<count($pins); $i++){
    $bcm = $pins[$i];
    system('gpio -g mode '.$bcm.' out');
    echo("<img id='LED_'.$bcm.'' src='/res/dots/LED_".$bcm.".png'/>");
    } ?>

   <br>
   <br>
   <button type="submit" name="up" style="background-color:transparent; border-color:transparent;">
     <img src="res/buttons/up.png" height="40"/>
       </button>
   <br>
   <button type="submit" name="left" style="background-color:transparent; border-color:transparent;">
     <img src="res/buttons/left.png" height="40"/>
       </button>
   <button type="submit" name="right" style="background-color:transparent; border-color:transparent;">
     <img src="res/buttons/right.png" height="40"/>
       </button>
   <br>
   <button type="submit" name="down" style="background-color:transparent; border-color:transparent;">
     <img src="res/buttons/down.png" height="40"/>
       </button>

<?php
$bcm = 27;
system('gpio -g write '.$bcm.' 1');
if(isset($_POST["up"])){$bcm=move($bcm,1);}
if(isset($_POST["down"])){$bcm=move($bcm,3);}
if(isset($_POST["left"])){$bcm=move($bcm,2);}
if(isset($_POST["right"])){$bcm=move($bcm,0);}
?>

</CENTER>
</BODY>

<?php
function move($pin,$dir){
if($pin==22 AND $dir==3){
    system('gpio -g write 27 1');
    system('gpio -g write 22 0');
    $pin = 27;
}elseif($pin==27 AND $dir==3){
    system('gpio -g write 4 1');
    system('gpio -g write 27 0');
    $pin = 4;
}elseif($pin==27 AND $dir==1){
    system('gpio -g write 22 1');
    system('gpio -g write 27 0');
    $pin = 4;   
}elseif($pin==27 AND $dir==0){
    system('gpio -g write 23 1');
    system('gpio -g write 18 1');
    system('gpio -g write 27 0');
    $pin = 23;
}elseif($pin==4 AND $dir==1){
    system('gpio -g write 27 1');
    system('gpio -g write 4 0');
    $pin = 27;
}elseif($pin==23 AND $dir==0){
    system('gpio -g write 17 1');
    system('gpio -g write 23 0');
    system('gpio -g write 18 0');
    $pin = 17;
}elseif($pin==23 AND $dir==2){
    system('gpio -g write 27 1');
    system('gpio -g write 23 0');
    system('gpio -g write 18 0');
    $pin = 27;
}elseif($pin==17 AND $dir==2){
    system('gpio -g write 23 1');
    system('gpio -g write 18 1');
    system('gpio -g write 17 0');
    $pin = 23;
}
return $pin;
} ?>

Don't worry about the indent errors, they are fine, the formatting on here is just being annoying. I've tried to add print statements and all kinds of things to the function and nothing ever appears. The lights don't change at all, it seems as though the function isn't even being called. The move function is the function in question.

pretzlstyle
  • 2,774
  • 5
  • 23
  • 40

1 Answers1

-1

The buttons are of type Submit yet they are not in a form. Put the buttons into a form ie <form> ---- </form>

JobSam
  • 287
  • 5
  • 11