45 lines
699 B
Bash
Executable File
45 lines
699 B
Bash
Executable File
#!/usr/bin/env bash
|
|
# usage: led.sh <port>
|
|
set -o xtrace
|
|
|
|
# config default
|
|
GPIO_PORT="${1:-18}"
|
|
|
|
function export_port() {
|
|
port="${1}"
|
|
echo "${port}" > /sys/class/gpio/export
|
|
}
|
|
function unexport_port() {
|
|
port="${1}"
|
|
echo "${port}" > /sys/class/gpio/unexport
|
|
}
|
|
|
|
function set_value() {
|
|
port="${1}"
|
|
value="${2}"
|
|
echo "${value}" > "/sys/class/gpio/gpio${port}/value"
|
|
}
|
|
|
|
function on() {
|
|
port="${1}"
|
|
set_value "${port}" "0"
|
|
}
|
|
function off() {
|
|
port="${1}"
|
|
set_value "${port}" "1"
|
|
}
|
|
|
|
# set exit trap
|
|
trap 'unexport_port "${GPIO_PORT}"' EXIT
|
|
|
|
# init GPIO port
|
|
export_port "${GPIO_PORT}"
|
|
|
|
# loop led on/off
|
|
while true; do
|
|
on "${GPIO_PORT}"
|
|
sleep 1
|
|
off "${GPIO_PORT}"
|
|
sleep 1
|
|
done
|