Skip to content

Commit f90beef

Browse files
committed
Problem: need a blink command
Solution: add zoobab's shell script
1 parent a603d9c commit f90beef

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

commands/blink

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#! /bin/sh
2+
# Blink a LED
3+
#
4+
# blink [times] [sleep]
5+
#
6+
GPNR="1"
7+
TIMES=$1
8+
SLEEP=$2
9+
test -z $TIMES && TIMES=1
10+
test -z $SLEEP && SLEEP=0.2
11+
12+
GPPATH="/sys/class/gpio"
13+
GPIODIR="${GPPATH}/gpio${GPNR}"
14+
15+
# export the GPIO pin
16+
if [ -d "${GPIODIR}" ]; then
17+
echo "${GPIODIR} found"
18+
else
19+
echo "${GPIODIR} not found, creating it"
20+
echo ${GPNR} > ${GPPATH}/export
21+
fi
22+
23+
echo "Initalize the GPIO direction"
24+
echo out > ${GPIODIR}/direction
25+
26+
echo "Blinking loop..."
27+
COUNTER=0
28+
while [ $COUNTER -lt $TIMES ]; do
29+
echo 1 > ${GPIODIR}/value
30+
sleep $SLEEP
31+
echo 0 > ${GPIODIR}/value
32+
sleep $SLEEP
33+
COUNTER=`expr $COUNTER + 1`
34+
done
35+

0 commit comments

Comments
 (0)