Skip to content

Instantly share code, notes, and snippets.

@malambra
Created May 10, 2014 18:25
Show Gist options
  • Save malambra/b4e85c65b3284d4f7bda to your computer and use it in GitHub Desktop.
Save malambra/b4e85c65b3284d4f7bda to your computer and use it in GitHub Desktop.
Shell script to control GPIO ports - perform operations controlled by a switch.
#! /bin/bash
################
## Celtha. 2013
################
if [[ $EUID -ne 0 ]]; then
echo "Error: Debo ejecutarme como root" >&2
exit 1
fi
#Usamos GPIO1 este es el PIN5 - Raspberry GPIO Rev.1
#Para cambiarle el valor a "0" Usamos GND en el PIN6
#Al puentear el PIN5 y PIN6 los valores seran "0"
#Nuestro interruptor corticircuita el PIN5 y el PIN6
#Valor de GPIO... GPIO1.
SHUTDOWN_PIN="1"
#Inicializamos PIN5..... referenciandolo como GPIO1
#Indicamos que admite valores de entrada
echo "$SHUTDOWN_PIN" > /sys/class/gpio/export
echo "in" > /sys/class/gpio/gpio"$SHUTDOWN_PIN"/direction
while ( true )
do
#Si el valor de GPIO1 es "0" shutdown
if [ $(</sys/class/gpio/gpio"$SHUTDOWN_PIN"/value) == 0 ]; then
echo "$SHUTDOWN_PIN" > /sys/class/gpio/unexport
#Ejecutamos la accion deseada.
shutdown -h now "Apagando por valor de GPIO1"
fi
sleep 60
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment