#!/bin/bash
# Simple script to light up LEDs using sysfs interface
# Pass in GPIO number as argument (not what is labeled on CHIP)
if [ $# -eq 0 ]
then
echo "Usage: gpio-led.sh [pin number]"
exit 1
fi
pinNumber=$1
function setup() {
if [ ! -d /sys/class/gpio/gpio$pinNumber ]
then
sudo sh -c "echo $pinNumber > /sys/class/gpio/export"
sudo sh -c "echo out > /sys/class/gpio/gpio$pinNumber/direction"
fi
}
function cleanup() {
if [ -d /sys/class/gpio/gpio$pinNumber ]
then
sudo sh -c "echo $pinNumber > /sys/class/gpio/unexport"
fi
}
function dash() {
sudo sh -c "echo 1 > /sys/class/gpio/gpio$pinNumber/value"
sleep 1
sudo sh -c "echo 0 > /sys/class/gpio/gpio$pinNumber/value"
}
function dot() {
sudo sh -c "echo 1 > /sys/class/gpio/gpio$pinNumber/value"
sleep .1
sudo sh -c "echo 0 > /sys/class/gpio/gpio$pinNumber/value"
}
# Example
setup
dash
dot
cleanup