Last active
February 14, 2024 01:06
-
-
Save locnnil/38d95f7234e96862f95bb7771b07fd07 to your computer and use it in GitHub Desktop.
Bash blink code using gpiod
This file contains 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
#!/usr/bin/env bash | |
set -e | |
gpiodetect > /dev/null 2>&1 | |
if [ $? -ne 0 ]; then | |
echo "Debian package gpiod not installed..." | |
apt-get update | |
apt-get install gpiod | |
fi | |
chip="0" | |
line="16" | |
if [ ! -z $1 ] && [ ! -z $2 ]; then | |
chip=$1 | |
line=$2 | |
fi | |
echo "Using chip $chip and line $line" | |
handle_sigint(){ | |
echo "Received SIGINT, exiting..." | |
gpioset $chip $line=0 | |
exit 0 | |
} | |
trap handle_sigint SIGINT | |
while : ;do | |
gpioset $chip $line=1 | |
echo "On" | |
sleep 0.5 | |
gpioset $chip $line=0 | |
echo "Off" | |
sleep 0.5 | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment