Anites/Big Ben

From Omnia
Jump to navigation Jump to search

Anites: Big Ben Clock - Raspberry Pi - http://www.anites.com/2014/11/big-ben-clock.html

cronjob schedule:

# Big Ben
# hourly from 7am to 10pm
#0 7-22 * * *   /opt/big_ben/big_ben.sh > /dev/null

Alternate schedule:

# Big Ben
# hourly from 7am to 10pm
#0 7-22 * * *   /opt/big_ben/big_ben.sh > /dev/null
# hourly from 7am to 10pm MON-FRI
0 7-22 * * 1-5  /opt/big_ben/big_ben.sh > /dev/null

big_ben.sh:

#!/bin/bash

# Author: Kenneth Burgener  2014
# Purpose: Determine hour and play appropriate Big Ben MP3

# crontab: (from 7am and 10pm)
# 0 7-22 * * *  /opt/big_ben/big_ben.sh > /dev/null

# Audio files: https://www.dropbox.com/s/op69s9jh71w9npf/big_ben.zip

# Get hour (1-12) for mp3 file
HOUR=`date +%l`
HOUR=$(( $HOUR ))

# Get military hour (1-24) for math below
MILHOUR=`date +%k`
MILHOUR=$(( $MILHOUR ))

# Set audio volume depending on time of day
if [ $MILHOUR -le 8 -o $MILHOUR -ge 20 ] ; then
    # 8am and earlier, 8pm and later
    #/usr/bin/amixer set PCM 80% > /dev/null
    /usr/bin/amixer set PCM 90% > /dev/null
else
    # 9am to 7pm
    #/usr/bin/amixer set PCM 95% > /dev/null
    /usr/bin/amixer set PCM 91% > /dev/null
fi

/usr/bin/mpg123 /opt/big_ben/audio/big_ben_$HOUR.mp3 2> /dev/null

Audio files: https://www.dropbox.com/s/op69s9jh71w9npf/big_ben.zip