Sign in to follow this  
Followers 0
Donald8282

Alarm Clock

3 posts in this topic

Hello, Anyone that would like to, would you test my alarm clock and tell me if you find any bugs at all. Thank you. I know the code is very messy but I don't like to make clean code =P just a habit.

#include <GUIConstantsEx.au3>
#include <EditConstants.au3>
#include <WindowsConstants.au3>
#include <ComboConstants.au3>


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;Month and day setup;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
$month = @MON

If $month = 1 Then
$month = "January"
ElseIf $month = 2 Then
$month = "February"
ElseIf $month = 3 Then
$month = "March"
ElseIf $month = 4 Then
$month = "April"
ElseIf $month = 5 Then
$month = "May"
ElseIf $month = 6 Then
$month = "June"
ElseIf $month = 7 Then
$month = "July"
ElseIf $month = 8 Then
$month = "August"
ElseIf $month = 9 Then
$month = "September"
ElseIf $month = 10 Then
$month = "October"
ElseIf $month = 11 Then
$month = "November"
ElseIf $month = 12 Then
$month = "December"
EndIf

$day1 = @WDAY

If $day1 = 1 Then
    $day1 = "Sunday"
ElseIf $day1 = 2 Then
    $day1 = "Monday"
ElseIf $day1 = 3 Then
    $day1 = "Tuesday"
ElseIf $day1 = 4 Then
    $day1 = "Wednesday"
ElseIf $day1 = 5 Then
    $day1 = "Thursday"
ElseIf $day1 = 6 Then
    $day1 = "Friday"
ElseIf $day1 = 7 Then
    $day1 = "Saturday"
EndIf
    


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;Alarm GUI setup;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
$GUI = GUICreate($day1 & ", " & $month & " " & @MDAY & " " & @YEAR, 300, 140)
GUISetState()

GUICtrlCreateLabel("Hour:", 10, 13)
$HourCheck = ""
$Hour = GUICtrlCreateInput("1", 40, 10, 40, 20, $ES_READONLY)
GUICtrlSetBkColor($Hour, 0xFFFFFF)
GUICtrlCreateUpdown($Hour)

GUICtrlCreateLabel("Minute:", 90, 13)
$MinuteCheck = ""
$Minute = GUICtrlCreateInput("0", 130, 10, 40, 20, $ES_READONLY)
GUICtrlSetBkColor($Minute, 0xFFFFFF)
GUICtrlCreateUpdown($Minute)

GUICtrlCreateLabel("Day:", 10, 43)
$DayCheck = ""
$Day = GUICtrlCreateCombo("Choose a day", 40, 40, 90, 20)
GUICtrlSetData($Day, "Monday|Tuesday|Wednesday|Thursday|Friday|Saturday|Sunday")

$periodcheck = ""
$period = GUICtrlCreateCombo("AM", 130, 40, 40, 20)
GUICtrlSetData($period, "PM")

$OpenButton = GUICtrlCreateButton("Alarm Music", 220, 8, 70, 25)
$create = GUICtrlCreateButton("Create Alarm", 220, 38, 70, 25)

$songname = ""
$song = ""
$music = GUICtrlCreateLabel("Song - " & $song, 10, 70, 300, 40)


$TimerOn = 0

$savedMin = IniRead("Timer.ini", "Time", "Minutes", "0")
$savedTimerOn = IniRead("Timer.ini", "Time", "TimerOn", "0")
$SavedHour = IniRead("Timer.ini", "Time", "Hours", "1")
$SavedDay = IniRead("Timer.ini", "Time", "Day", "Monday")
$SavedDay2 = IniRead("Timer.ini", "Time", "Day2", "2")
$SavedSong = IniRead("Timer.ini", "Song", "Directory", "0")
$SavedPeriod = IniRead("Timer.ini", "Time", "Period", "AM")
$SavedMessage= IniRead("Timer.ini", "Message", "Message", "Chicken nuggets rule")


    $SongGet = ""
    $Hour1 = ""
    
    $GUIHour = ""
    $GUIMinute = ""
    $GUIDay = ""
    $GUIPeriod = ""

If FileExists(@ScriptDir & "/Timer.ini") then
    GUICtrlSetData($Hour, $SavedHour)
    
    GUICtrlSetData($Minute, $SavedMin)
    GUICtrlSetData($Day, $SavedDay)
    GUICtrlSetData($Music, $SavedSong)
    GUICtrlSetData($period, $SavedPeriod)
    
    $Day2 = $SavedDay2
    
    $message = $SavedMessage

    


    
    $TimerOn = $SavedTimerOn
    $Songget = $SavedSong
    
    
    
    
    $GUIMinute = GUICtrlRead($Minute)
    $GUIDay = GUICtrlRead($Day)
    $SongName = GUICtrlRead($music)
    $GUIPeriod = GUICtrlRead($period)
    
If $GUIPeriod = "PM" Then
    GUICtrlSetData($Hour, $SavedHour - 12)
Else
    GUICtrlSetData($Hour, $SavedHour)
EndIf
    
    $hour1 = $SavedHour
    
    
    
Else

EndIf



While 1
    sleep(10)
    $GUIHour = GUICtrlRead($Hour)
    $GUIMinute = GUICtrlRead($Minute)
    $GUIDay = GUICtrlRead($Day)
    $SongName = GUICtrlRead($music)
    $GUIPeriod = GUICtrlRead($period)
    


    

    
    
    If $GUIHour > 11 Then
        GUICtrlSetData($Hour, 12)
    ElseIf $GUIHour < 2 Then
        GUICtrlSetData($Hour, 1)
    EndIf
    
    If $GUIMinute > 58 Then
        GUICtrlSetData($Minute, 59)
    ElseIf $GUIMinute < 1 Then
        GUICtrlSetData($Minute, 0)
    EndIf


$msg = GUIGetMsg()
Select
Case $msg = $OpenButton
    $songGet = FileOpenDialog("Open...", @DesktopDir & "\", "Music(*.mp3)")
    If @error Then
        $songget = ""
        GUICtrlSetData($music, "Song - " & $songget)
    Else
    GUICtrlSetData($music, "Song - " & $songget)
EndIf
Case $msg = $GUI_EVENT_CLOSE
    Exit
Case $msg = $create
    
    $HourCheck = $GUIHour
    $MinuteCheck = $GUIMinute
    $DayCheck = $GUIDay
    $songname = $song
    $PeriodCheck = $GUIPeriod
    
    
    If $songget = "" Then
        MsgBox(0, "", "Please select a song.")
    Else
        $TimerOn = 1
    
    
        If $GUIDay = "Sunday" Then
        $Day2 = 1
    ElseIf $GUIDay = "Monday" Then
        $Day2 = 2
    ElseIf $GUIDay = "Tuesday" Then
        $Day2 = 3
    ElseIf $GUIDay = "Wednesday" Then
        $Day2 = 4
    ElseIf $GUIDay = "Thursday" Then
        $Day2 = 5
    ElseIf $GUIDay = "Friday" Then
        $Day2 = 6
    ElseIf $GUIDay = "Saturday" Then
        $Day2 = 7
    Else
        MsgBox(0, "", "Please select a day.")
    EndIf
    
    
    If $GUIHour = 1 And $GUIPeriod = "PM" Then
        $Hour1 = 12 + 1
    ElseIf $GUIHour = 2 And $GUIPeriod = "PM" Then
        $Hour1 = 12 + 2
    ElseIf $GUIHour = 3 And $GUIPeriod = "PM" Then
        $Hour1 = 12 + 3
    ElseIf $GUIHour = 4 And $GUIPeriod = "PM" Then
        $Hour1 = 12 + 4
    ElseIf $GUIHour = 5 And $GUIPeriod = "PM" Then
        $Hour1 = 12 + 5
    ElseIf $GUIHour = 6 And $GUIPeriod = "PM" Then
        $Hour1 = 12 + 6
    ElseIf $GUIHour = 7 And $GUIPeriod = "PM" Then
        $Hour1 = 12 + 7
    ElseIf $GUIHour = 8 And $GUIPeriod = "PM" Then
        $Hour1 = 12 + 8
    ElseIf $GUIHour = 9 And $GUIPeriod = "PM" Then
        $Hour1 = 12 + 9
    ElseIf $GUIHour = 10 And $GUIPeriod = "PM" Then
        $Hour1 = 12 + 10
    ElseIf $GUIHour = 11 And $GUIPeriod = "PM" Then
        $Hour1 = 12 + 11
    ElseIf $GUIHour = 12 And $GUIPeriod = "PM" Then
        $Hour1 = 12
        
    ElseIf $GUIHour = 1 And $GUIPeriod = "AM" Then
        $Hour1 = 1
    ElseIf $GUIHour = 2 And $GUIPeriod = "AM" Then
        $Hour1 = 2
    ElseIf $GUIHour = 3 And $GUIPeriod = "AM" Then
        $Hour1 = 3
    ElseIf $GUIHour = 4 And $GUIPeriod = "AM" Then
        $Hour1 = 4
    ElseIf $GUIHour = 5 And $GUIPeriod = "AM" Then
        $Hour1 = 5
    ElseIf $GUIHour = 6 And $GUIPeriod = "AM" Then
        $Hour1 = 6
    ElseIf $GUIHour = 7 And $GUIPeriod = "AM" Then
        $Hour1 = 7
    ElseIf $GUIHour = 8 And $GUIPeriod = "AM" Then
        $Hour1 = 8
    ElseIf $GUIHour = 9 And $GUIPeriod = "AM" Then
        $Hour1 = 9
    ElseIf $GUIHour = 10 And $GUIPeriod = "AM" Then
        $Hour1 = 10
    ElseIf $GUIHour = 11 And $GUIPeriod = "AM" Then
        $Hour1 = 11
    ElseIf $GUIHour = 12 And $GUIPeriod = "AM" Then
        $Hour1 = 12 - 12
    EndIf
    
    $message = InputBox("Message", "What would you like your alarm message to say?")
EndIf


IniWrite(@ScriptDir & "/Timer.ini", "Time", "Minutes", $GUIMinute)
IniWrite(@ScriptDir & "/Timer.ini", "Time", "TimerOn", $TimerOn)
IniWrite(@ScriptDir & "/Timer.ini", "Time", "Hours", $hour1)
IniWrite(@ScriptDir & "/Timer.ini", "Time", "Day", $GUIDay)
IniWrite(@ScriptDir & "/Timer.ini", "Time", "Day2", $Day2)
IniWrite(@ScriptDir & "/Timer.ini", "Song", "Directory", $SongGet)
IniWrite(@ScriptDir & "/Timer.ini", "Time", "Period", $GUIPeriod)
IniWrite(@ScriptDir & "/Timer.ini", "Message", "Message", $message)



EndSelect


    If $TimerOn = 1 And $GUIminute = @MIN And @SEC = 0 And $hour1 = @HOUR And $Day2 = @WDAY then
        SoundPlay($songget)
        MsgBox(0, "Alarm", $message)
    EndIf


WEnd

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Hi,

Thanks for sharing, nice idea. It appears to work ok.

I notice you don't have an option to turn the alarm off while the gui is showing.

I had a play with your code, feel free to claim it as your own

#include <GUIConstantsEx.au3>
#include <EditConstants.au3>
#include <WindowsConstants.au3>
#include <ComboConstants.au3>

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;Global Variables;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Global $Ini = @ScriptDir & "\Timer.ini"
Global $sDays = "Sunday|Monday|Tuesday|Wednesday|Thursday|Friday|Saturday|Every Day"
Global $sMonths = "January|February|March|April|May|June|July|August|September|October|November|December"
Global $aDay = StringSplit($sDays, "|"), $aMonth = StringSplit($sMonths, "|")
Global $aCurrent = _LoadIni()
Global $aToggleAlarm[2] = ["Turn On Alarm", "Turn Off Alarm"]
Global $hGui, $iHour, $iMinute, $iDay, $iPeriod, $iSong, $iBrowse, $iMessage, $iToggleAlarm, $iMsg


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;Alarm GUI setup;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
$hGui = GUICreate($aDay[@WDAY] & ", " & $aMonth[@MON] & " " & @MDAY & ", " & @YEAR, 290, 225)
GUICtrlCreateGroup("1. Select Day", 5, 5, 110, 55)
$iDay = GUICtrlCreateCombo("", 15, 25, 90, 20, $CBS_DROPDOWNLIST)
GUICtrlSetData(-1, $sDays, $aCurrent[1])
GUICtrlCreateGroup("2. Select Time", 120, 5, 165, 55)
$iHour = GUICtrlCreateCombo("", 130, 25, 40, 20, $CBS_DROPDOWNLIST)
GUICtrlSetData(-1, "1|2|3|4|5|6|7|8|9|10|11|12", _12Hour($aCurrent[2]))
GUICtrlCreateLabel(":", 172, 25, 5, 20)
GUICtrlSetFont(-1, 13, 700)
$iMinute = GUICtrlCreateCombo("", 179, 25, 40, 20, BitOR($CBS_DROPDOWNLIST, $WS_VSCROLL))
For $i = 0 To 59
    GUICtrlSetData(-1, StringFormat("%02i", $i), $aCurrent[3])
Next
GUICtrlCreateLabel(":", 221, 25, 5, 20)
GUICtrlSetFont(-1, 13, 700)
$iPeriod = GUICtrlCreateCombo("", 229, 25, 45, 20)
GUICtrlSetData(-1, "AM|PM", $aCurrent[4])
GUICtrlCreateGroup("3. Select Sound", 5, 65, 280, 55)
$iSong = GUICtrlCreateInput($aCurrent[5], 15, 85, 200, 20, $ES_READONLY)
GUICtrlSetBkColor(-1, 0xFFFFFF)
$iBrowse = GUICtrlCreateButton("Browse", 220, 85, 55, 20)
GUICtrlCreateGroup("4. Alarm Message", 5, 125, 280, 55)
$iMessage = GUICtrlCreateInput($aCurrent[6], 15, 145, 260, 20)
$iToggleAlarm = GUICtrlCreateButton($aToggleAlarm[0], 5, 190, 280, 25)
GUISetState(@SW_SHOW, $hGui)

While 1
    $iMsg = GUIGetMsg()
    Switch $iMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $iDay
            _TurnOffAlarm()
            $aCurrent[1] = GUICtrlRead($iMsg)
        Case $iHour
            _TurnOffAlarm()
            $aCurrent[2] = _24Hour(GUICtrlRead($iMsg), $aCurrent[4])
        Case $iMinute
            _TurnOffAlarm()
            $aCurrent[3] = GUICtrlRead($iMsg)
        Case $iPeriod
            _TurnOffAlarm()
            $aCurrent[4] = GUICtrlRead($iMsg)
            $aCurrent[2] = _24Hour(GUICtrlRead($iHour), $aCurrent[4])
        Case $iBrowse
            _TurnOffAlarm()
            _Browse()
        Case $iToggleAlarm
            _ToggleAlarrm()
    EndSwitch
WEnd

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;Functions;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Func _24Hour($iHr, $iPrd)
    Switch $iPrd
        Case "PM"
            If $iHr = 12 Then Return 0
            Return $iHr + 12
        Case Else
            Return $iHr
    EndSwitch
EndFunc   ;==>_24Hour

Func _12Hour($iHr)
    Switch $iHr
        Case 0
            Return 12
        Case 13 To 23
            Return $iHr - 12
        Case Else
            Return $iHr
    EndSwitch
EndFunc   ;==>_12Hour

Func _LoadIni()
    Dim $aRet[8] = [7, "Every Day", 6, 30, "AM", "Path To Sound", "Alram Message", 0]
    For $i = 1 To $aRet[0]
        $aRet[$i] = IniRead($Ini, "Time", $i, $aRet[$i])
    Next
    Return $aRet
EndFunc   ;==>_LoadIni

Func _Browse()
    Local $sFOD
    $sFOD = FileOpenDialog("Select an audio file", "", "Sound File (*.wav;*.mp3)", 3, "", $hGui)
    If Not @error Then
        $aCurrent[5] = $sFOD
        GUICtrlSetData($iSong, $aCurrent[5])
    EndIf
EndFunc   ;==>_Browse

Func _ToggleAlarrm()
    If GUICtrlRead($iToggleAlarm) = $aToggleAlarm[0] Then
        $aCurrent[6] = GUICtrlRead($iMessage)
        $aCurrent[7] = 1
        For $i = 1 To $aCurrent[0] - 1
            IniWrite($Ini, "Time", $i, $aCurrent[$i])
        Next
        AdlibRegister("_CheckAlarm", 250)
    Else
        _TurnOffAlarm()
    EndIf
    GUICtrlSetData($iToggleAlarm, $aToggleAlarm[$aCurrent[7]])
    Return 1
EndFunc   ;==>_ToggleAlarrm

Func _TurnOffAlarm()
    If $aCurrent[7] Then
        $aCurrent[7] = 0
        AdlibUnRegister("_CheckAlarm")
    EndIf
EndFunc   ;==>_TurnOffAlarm

Func _CheckAlarm()
    Switch $aCurrent[1]
        Case "Every Day"
            If $aCurrent[2] = @HOUR And $aCurrent[3] = @MIN And @SEC = 0 Then _PlayAlarm()
        Case Else
            If $aDay[@WDAY] = $aCurrent[1] And $aCurrent[2] = @HOUR And $aCurrent[3] = @MIN And @SEC = 0 Then _PlayAlarm()
    EndSwitch
EndFunc   ;==>_CheckAlarm

Func _PlayAlarm()
    If FileExists($aCurrent[5]) Then SoundPlay($aCurrent[5])
    MsgBox(64, "Alarm", $aCurrent[6], 0, $hGui)
    Sleep(1000)
EndFunc   ;==>_PlayAlarm

Cheers

Edited by smashly

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Wow, thank you! No, I can't take credit for this work. I worked on this for about 4 hours. I'm not too well at AutoIt yet but I'm getting there. I'm not good at arrays or anything. Just basic stuff.

Edited by Donald8282

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0