sudo apt-get install apache2 php5
sudo apt-get install git-core
git clone git://git.drogon.net/wiringPi
cd wiringPi ./build
Test by using :
gpio readall
then
nano /etc/var/www/html/gpio.php
copy below code :
------------------------------------------------------------ <html> <head> <meta name="viewport" content="width=device-width" /> <title>LED Control</title> </head> <body> LED Control: <form method="get" action="gpio.php"> <input type="submit" value="ON" name="on"> <input type="submit" value="OFF" name="off"> </form> <?php $setmode17 = shell_exec("/usr/local/bin/gpio -g mode 17 out"); if(isset($_GET['on'])){ $gpio_on = shell_exec("/usr/local/bin/gpio -g write 17 1"); echo "LED is on"; } else if(isset($_GET['off'])){ $gpio_off = shell_exec("/usr/local/bin/gpio -g write 17 0"); echo "LED is off"; } ?> </body> </html> -------------------------------------------------------------
ต่อไฟให้ relay ตามนี้
Code จริง ใช้ขา pin 38 ,40 เท่ากับ GPIO ขา 20,21
<html> <head> <meta name="viewport" content="width=device-width" /> <title>Room Salmon Lighting</title> </head> <body> LED [1] LED [2] <form method="get" action="gpio.php"> <input type="submit" value="ON" name="on"> <input type="submit" value="OFF" name="off"> <form method="get" action="gpio.php"> <input type="submit" value="ON1" name="on1"> <input type="submit" value="OFF1" name="off1"> </form> <?php $setmode20 = shell_exec("/usr/local/bin/gpio -g mode 20 out"); if(isset($_GET['on'])){ $gpio_on = shell_exec("/usr/local/bin/gpio -g write 20 1"); echo "LED is on"; } else if(isset($_GET['off'])){ $gpio_off = shell_exec("/usr/local/bin/gpio -g write 20 0"); echo "LED is off"; } $setmode21 = shell_exec("/usr/local/bin/gpio -g mode 21 out"); if(isset($_GET['on1'])){ $gpio_on = shell_exec("/usr/local/bin/gpio -g write 21 1"); echo "LED is on1"; } else if(isset($_GET['off1'])){ $gpio_off = shell_exec("/usr/local/bin/gpio -g write 21 0"); echo "LED is off1"; } ?> </body> </html>
----
ไม่มีความคิดเห็น:
แสดงความคิดเห็น