Skip to content

Instantly share code, notes, and snippets.

@ma2shita
Last active December 29, 2021 03:32
Show Gist options
  • Save ma2shita/22d5161ee03da4971560bb96078a1596 to your computer and use it in GitHub Desktop.
Save ma2shita/22d5161ee03da4971560bb96078a1596 to your computer and use it in GitHub Desktop.
Let's try IoT Prototyping / Fixed point camera with RPi (gpio6 / implementation)
#!/bin/bash
BCM_PIN=6
trap 'exit 0' 1 2 3 15
function _gpio_read() {
# $1 = reading GPIO pin (number of BMC pin)
raspi-gpio get $1 | awk -v RS=" " -F "=" -v k="level" '$1==k {print $2}'
}
raspi-gpio set $BCM_PIN ip pu
PREV=$(_gpio_read $BCM_PIN)
while true
do
CURR=$(_gpio_read $BCM_PIN)
if [ "$PREV" -ne "$CURR" ]; then
echo "Trigger on $0"
echo "Diff!: $PREV -> $CURR"
if [ "$CURR" -eq 0 ]; then
echo "shooting!" | nc localhost 19000
fi
echo "$0 End."
fi
PREV=$CURR
sleep 0.1
done
@ma2shita
Copy link
Author

12/29/2021: Updating for using raspi-gpio from gpio(Wriring Pi). ref: https://qiita.com/ma2shita/items/b11045717333bcd79d15

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