以下两行代码,是用来打开gpio44和gpio45,增加了一个判断条件,如果不存在则执行echo命令打开相应端口:
if [ ! –d /sys/class/gpio/gpio44 ]; then echo 44 > /sys/class/gpio/export; fi
if [ ! –d /sys/class/gpio/gpio45 ]; then echo 45 > /sys/class/gpio/export; fi
以下两行代码为实现将端口都设置为输出模式“out”:
echo out > /sys/class/gpio/gpio44/direction
echo out > /sys/class/gpio/gpio44/direction