#!/bin/bash
#
# copyright U. Raich 2017
# This program is part of the workshop on embedded systems held at 
# the University of Cape Coast in the winter semester 2017
# It has been released under the GNU General Public License
# see gnu.org/licenses/gpl.html

# LED Pin - wiringPi pin 0 is BCM_GPIO 17.

PIN=0

gpio mode $PIN out

on_die()
{
    # print message
    #
    echo "Exiting gracefully"
    gpio write $PIN 0 
    exit 0
}

# Execute the function on_die() when receiving INT

trap 'on_die' INT

while true; do
    echo LED on
    gpio write $PIN 1
    sleep 1
    echo LED off
    gpio write $PIN 0
    sleep 1
done

# will never get here
exit 0
