这是我用来为电子类托管服务器的 PHP 脚本。这些按钮只是应该点亮不同的 LED。
<!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;
} ?>
不要担心缩进错误,它们很好,这里的格式很烦人。我试图在函数中添加打印语句和各种东西,但什么都没有出现。灯光根本没有变化,似乎甚至没有调用该函数。该move
功能是有问题的功能。