Blog 12

From BitWizard Wiki
Jump to navigation Jump to search

BETA!

Alarm

This time I am going to make an Alarm. For this I will use:

  • Rp_ui_board
  • 3pin earplugs ( I didn't have a speaker )

I want to make it possible that you can change the alarm time through the pushbuttons. The options you should get is:

Change alarm minutes
Change alarm hours
stop alarm music playing
Reset alarm time 
Activating the alarm time given
show on display current time + time of the alarm. 
  • AlarmMenu

Main menu where you can select the scripts

  • TimeAndAlarm(Button 3)

This will show at start up the time given as alarm and the current time.

  • CronTime3(Button 1)

Here you can set the hour you want the alarm to turn on.

  • CrontimeTSE(Button 2)

Here you can set the minute you want the alarm to turn on.

  • AcTime(Button 6)

This will put the given hour and or minute in the crontab.

  • StopSong(Button 4)

To stop the alarm song/sound that is now playing.( killall omxplayer.bin )

  • ResetAlarm(Button 5)

This will reset the hour and minutes to 99 so that they won't be usable. ( because minutes goes from 0-59 and hours from 0-23)

How do you use my alarm?

When you start the script, you can press use all the 6 buttons. When started up it will start at button 3. which is the button that shows the current time and time of when the alarm song plays. With button 1 you change the specific hour of when the song has to be played from the alarm. After button 1 pressed you change the hour with button 1 till 4.

1 = +1  
2 = -1  
3 = +5 
4 = -5

If you then want to confirm you want to have the specific hour you selected you have to press 5. With button 6 pressed you leave the script. ( If you didn't press 5 before 6 the given time will not be remembered ) Button 2 is in the same way designed as button 1 outside of it instead changing hours it changes minutes. Button 4 is just 1 button press to stop the song that is currently playing. When you get out of this menu it should be possible that it can play an alarm song again the next day. Button 5 will reset the alarm time to 99, so that it will never play an alarm. Button 6 Is to activate the alarm.

Scripts AlarmMenu

#!/bin/bash  

#BUTTON=CrontimeTSE 
#BUTTON=Crontime3 
#BUTTON=AcTime 
#BUTTON=StopSong 
BUTTON=TimeAndAlarm 
#BUTTON=ResetAlarm 
bw_tool -I -D /dev/i2c-1 -a 94 -w 10:00 

while true; do 
 DETECT=`bw_tool -I -D /dev/i2c-1 -a 94 -R 30:b` 

 if [ $DETECT  != "00" ]; then 
   bw_tool -I -D /dev/i2c-1 -a 94 -w 10:00 
 fi 

 if [ $DETECT  = "20" ]; then 
   BUTTON=Crontime3 
 fi 

 if [ $DETECT  = "10" ]; then 
   BUTTON=CrontimeTSE 
 fi 

 if [ $DETECT  = "08" ]; then 
   BUTTON=TimeAndAlarm 
 fi 

 if [ $DETECT  = "04" ]; then 
   BUTTON=StopSong 
   bw_tool -I -D /dev/i2c-1 -a 94 -t "Audio mute" 
 fi 

 if [ $DETECT  = "02" ]; then 
   BUTTON=ResetAlarm 
 fi 

 if [ $DETECT = "01" ]; then 
   BUTTON=AcTime 
 fi 

 bw_tool -I -D /dev/i2c-1 -a 94 -w 11:00 
  ./$BUTTON 

  sleep 1 
done

Script TimeAndAlarm

#!/bin/bash 

Min=$(cat Minutes) 
Hr=$(cat Hours) 

   bw_tool -I -D /dev/i2c-1 -a 94 -w 10:00 
   bw_tool -I -D /dev/i2c-1 -a 94 -w 11:00 
   bw_tool -I -D /dev/i2c-1 -a 94 -t "Alarm " $(printf %02d $Hr)":"$(printf %02d $Min) 

   bw_tool -I -D /dev/i2c-1 -a 94 -w 11:20 
   bw_tool -I -D /dev/i2c-1 -a 94 -t "Time   "`date +%T

Script Crontime3

#!/bin/bash 

bw_tool -I -D /dev/i2c-1 -a 94 -w 10:00 

while true; do 
 Scan=`bw_tool -I -D /dev/i2c-1 -a 94 -R 30:b` 

 if [ $Scan  != "00" ]; then 
   bw_tool -I -D /dev/i2c-1 -a 94 -w 10:00 
 fi 

 if [ $Scan  = "20" ]; then 
   bw_tool -I -D /dev/i2c-1 -a 94 -w 10:00 
   TimeOnhh=$((   (TimeOnhh + 01) %  24   )) 
 fi 

 if [ $Scan  = "10" ]; then 
   bw_tool -I -D /dev/i2c-1 -a 94 -w 10:00 
   TimeOnhh=$(( (TimeOnhh + 23) %   24    )) 
 fi 

 if [ $Scan  = "08" ]; then 
   bw_tool -I -D /dev/i2c-1 -a 94 -w 10:00 
   TimeOnhh=$(( (TimeOnhh + 05) %   24    )) 
 fi 

 if [ $Scan  = "04" ]; then 
   bw_tool -I -D /dev/i2c-1 -a 94 -w 10:00 
   TimeOnhh=$(( (TimeOnhh + 19) %   24    )) 
 fi 

 if [ $Scan  = "02" ]; then 
   bw_tool -I -D /dev/i2c-1 -a 94 -w 10:00 
   echo $TimeOnhh > Hours 
   bw_tool -I -D /dev/i2c-1 -a 94 -w 11:20 
   bw_tool -I -D /dev/i2c-1 -a 94 -t "Set!" 
   sleep 1 
 fi 

 if [ $Scan  = "01" ]; then 
   exit 
 fi 

 bw_tool -I -D /dev/i2c-1 -a 94 -w 11:00 
 bw_tool -I -D /dev/i2c-1 -a 94 -t "Hours "$(printf %02d $TimeOnhh)
 bw_tool -I -D /dev/i2c-1 -a 94 -w 11:20 
 bw_tool -I -D /dev/i2c-1 -a 94 -t "Time  "`date +%T` 

  sleep 1 

done

Script AcTime

#!/bin/bash 

Min=$(cat Minutes) 
Hr=$(cat Hours)  

(echo "#  mm hh dom mon dow command"; echo ""$Min" "$Hr" * * * mplayer /home/pi/ru.mp3") | crontab 

bw_tool -I -D /dev/i2c-1 -a 94 -w 11:00 
bw_tool -I -D /dev/i2c-1 -a 94 -t "Activated " 
bw_tool -I -D /dev/i2c-1 -a 94 -w 11:20 
bw_tool -I -D /dev/i2c-1 -a 94 -t "If times set" 

Script StopSong

#!/bin/bash 

killall mplayer 

Script ResetAlarm

#!/bin/bash 

Min="99" 
Hr="99" 

echo $Min > Hours 
echo $Hr > Minutes 

(echo "#  mm hh dom mon dow command"; echo ""$Min" "$Hr" * * * mplayer /home/pi/ru.mp3") | crontab 
   bw_tool -I -D /dev/i2c-1 -a 94 -w 10:00 
   bw_tool -I -D /dev/i2c-1 -a 94 -w 11:00 
   bw_tool -I -D /dev/i2c-1 -a 94 -t "Alarm " "$Hr":"$Min" "Res" 
   bw_tool -I -D /dev/i2c-1 -a 94 -w 11:20 
   bw_tool -I -D /dev/i2c-1 -a 94 -t "Time   "`date +%T`