Skip to content

Instantly share code, notes, and snippets.

@hogelog
Last active December 23, 2015 03:09
Show Gist options
  • Save hogelog/6571336 to your computer and use it in GitHub Desktop.
Save hogelog/6571336 to your computer and use it in GitHub Desktop.
#!/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
@hogelog
Copy link
Author

hogelog commented Sep 15, 2013

  • inputの値が0から1に切り替わった時のみ特定の処理を行うように修正

そろそろシェルスクリプトじゃなくてPythonやRuby教える方に切り替えるべきかも。
変数の扱いなどがとても微妙なので、自分でシェルスクリプトいじりだすと混乱しそう。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment