using Bash script to control LED with WiringPi on Raspberry Pi
2013-01-05 01:20
896 查看
Before programming in bash
You need is to install WiringPi first.
Click here for information of installing WiringPi on Raspberry Pi.
SInce bash is already installed on most Linux destros. we just need to move on.
Prepare Circuit
Like what I did before, the short leg of LED light is connect to the GND of the pin pool of Raspberry Pi board.
And I used a 4.7K resistor to connect with between the GPIO 18 and the long leg of the LED light.
![](http://img.my.csdn.net/uploads/201301/05/1357319962_7723.png)
Write a bash script
then we need to write these down:
This script includes an infinite loop.
Make the shell script executable
Run the script
You will see:
using " CTRL + C " for key interrupt to terminate the present processl
Please inform the author or declare the original link of this page when you share with others.
You need is to install WiringPi first.
Click here for information of installing WiringPi on Raspberry Pi.
SInce bash is already installed on most Linux destros. we just need to move on.
Prepare Circuit
Like what I did before, the short leg of LED light is connect to the GND of the pin pool of Raspberry Pi board.
And I used a 4.7K resistor to connect with between the GPIO 18 and the long leg of the LED light.
![](http://img.my.csdn.net/uploads/201301/05/1357319962_7723.png)
Write a bash script
vim blink.sh
then we need to write these down:
gpio -g mode 18 out #set pin 18 mode out gpio -g write 18 1 #set pin 18 on while true; do gpio -g write 18 0 #LED light off echo LED light is off sleep 1 gpio -g write 18 1 #LED light on echo LED light is on sleep 1 done
This script includes an infinite loop.
Make the shell script executable
chmod +x blink.sh
Run the script
./blink.sh
You will see:
pi@raspberrypi ~/songhua $ ./blink.sh LED light is off LED light is on LED light is off LED light is on LED light is off LED light is on LED light is off LED light is on LED light is off LED light is on LED light is off LED light is on LED light is off LED light is on LED light is off LED light is on ^Cpi@raspberrypi ~/songhua $
using " CTRL + C " for key interrupt to terminate the present processl
Please inform the author or declare the original link of this page when you share with others.
相关文章推荐
- chmod 777 wiringpi.ini to control LED on Linux
- How to Control a Lamp With Voice Commands and a Raspberry Pi
- Using SQLCMD to deploy sql script on SQLServer
- Using Delegates with Data Readers to Control DAL Responsibility[转]
- [转贴]How to work with stored procedures by using script in an Office InfoPath 2003 form
- How to configure Red Hat Cluster using KVM fencing with two guest VM's running on a IBM PowerKVM
- 在大于32GB或64GB容量的SD卡上使用NOOB安装树莓派 - Using NOOB on SD cards larger than 32GB or 64GB for Raspberry Pi
- 项目管理实践【五】自动编译和发布网站【Using Visual Studio with Source Control System to build and publish website automatically】
- 项目管理实践【六】自动同步数据库【Using Visual Studio with Source Control System to synchronize database automatically】
- 项目管理实践【四】自动编译和发布网站【Using Visual Studio with Source Control System to build and publish website automatically】
- 项目管理实践【五】自动编译和发布网站【Using Visual Studio with Source Control System to build and publish website automatically】
- 项目管理实践【六】自动同步数据库【Using Visual Studio with Source Control System to synchronize database automatically】
- How to burn raspberry pi image to SD card on ubuntu
- How to populate the datagrid on background thread with data binding by using Visual C#
- Adding an On/Off switch to your Raspberry Pi
- 项目管理实践【五】自动编译和发布网站【Using Visual Studio with Source Control System to build and publish website automatically】
- 【raspberry pi】server assistant to shutdown and reboot raspberry pi using mobile app
- using script with SVG to implement interaction(用脚本来实现svg的动态效果和交互)
- Interfacing an SPI ADC (MCP3008) chip to the Raspberry Pi using C++ (spidev)
- How to Setup RaspBerry Pi with RASPBIAN STRETCH LITE