close
網頁控制LED (開關)
1.
$ sudo apt-get install git-core
$ git clone git://git.drogon.net/wiringPi
$ cd wiringPi
$ ./build
2.
再來是寫控制GPIO4的php,先進到放網頁的地方
$ cd /var/www/html
$ sudo nano gpio.php
<html>
<head>
<meta name="viewport" content="width=device-width" />
<title>LED Control</title>
</head>
<body>
<center>
LED Control:
<form method="get" action="gpio.php">
<input type="submit" value="ON" name="on">
<input type="submit" value="OFF" name="off">
</form>
<?php
$setmode4 = shell_exec("/usr/local/bin/gpio -g mode 4 out");
if(isset($_GET['on'])){
$gpio_on = shell_exec("/usr/local/bin/gpio -g write 4 1");
echo "LED is on";
}
else if(isset($_GET['off'])){
$gpio_off = shell_exec("/usr/local/bin/gpio -g write 4 0");
echo "LED is off";
}
?>
</center>
</body>
</html>
3.
開啟網頁輸入192.168.1.18/gpio.php (前面是網頁伺服器的IP),就可以控制LED開關了。
全站熱搜
留言列表