Last active
December 23, 2015 03:09
-
-
Save hogelog/6571336 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
NO=7 | |
GPIO=/sys/class/gpio/gpio$NO | |
setup() { | |
echo start! | |
echo $NO > /sys/class/gpio/export | |
echo in > $GPIO/direction | |
} | |
finish() { | |
echo $NO > /sys/class/gpio/unexport | |
echo finish! | |
} | |
input() { | |
cat $GPIO/value | |
} | |
prev_input_value=0 | |
switch_on() { | |
input_value=`input` | |
switch_value=$(($input_value & ($prev_input_value == 0))) | |
prev_input_value=$input_value | |
return $(( $switch_value == 0 )) | |
} | |
setup | |
trap finish EXIT | |
while [ 1 ] | |
do | |
if switch_on; then | |
echo switch on! | |
fi | |
sleep 0.1 | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
そろそろシェルスクリプトじゃなくてPythonやRuby教える方に切り替えるべきかも。
変数の扱いなどがとても微妙なので、自分でシェルスクリプトいじりだすと混乱しそう。