Alarm Clock
Author |
Message |
mace
|
Posted: Fri Jun 27, 2008 10:35 pm Post subject: Alarm Clock |
|
|
i hated every alarm clock i ever bought, so i made my own
the are 6 different actual 'alarms' to run
to set the alarm you have to go to "alarm 1 set" or "alarm 2 set", then you have to arm the alarms
when you set the alarm it arms it, but each time the alarm goes off you have to set it again
all of the times are in 24 hour clock
to use the buttons just click the text, the buttons may be a little of center though
Turing: |
var year, month, dayOfWeek, day, hour, minute, second : int %the variables that wil hold the times
var sechand, minhand, hourhand : int %the variables that will run the clock
var alarmHour1, alarmHour2, alarmMin1, alarmMin2 : int := - 1 %the variables that will hold the times for the alarms
var alarm1sound, alarm2sound : int := 1 %the variabels that will hold the variables for the alarm sounds
var xmouse, ymouse, button : int %the varaibels that will hold teh mouse movements
var theTime : string %the variable that will hold the date and time string
var tim : int %the variable for number of seconds since 1970:00:00:00:00
var font : int %the variable that will hold the font used
var counttime : int %the variable that will be used to coutn time
var alarm1Arm, alarm2Arm : boolean := false %is used to see if the alarm should be run
var a1Set, a2Set : boolean := false %sees if the alarms are set
font := Font.New ("Times:12:bold,italic")
procedure scifi
cls %clears the screen
Font.Draw ("Awake", 100, 100, font, brightred) %puts the word awake to the screen
drawfillbox (150, 150, 160, 160, red) %draws the awake clickbox
loop %loops to run the alarm
Mouse.Where (xmouse, ymouse, button ) %sees where the mouse is
if xmouse > 150 and xmouse < 160 and ymouse > 150 and ymouse < 160 and button = 1 then %sees if the player clicked
exit %exits the alarm loop
end if
sound (20000, 200)
sound (10000, 200)
sound (5000, 200)
sound (1250, 200)
sound (750, 200)
sound (300, 200)
end loop
end scifi
procedure lowbeeping
cls %clears the screen
Font.Draw ("Awake", 100, 100, font, brightred) %puts the word awake to the screen
drawfillbox (150, 150, 160, 160, red) %draws the awake clickbox
loop %loops to run the alarm
Mouse.Where (xmouse, ymouse, button ) %sees where the mouse is
if xmouse > 150 and xmouse < 160 and ymouse > 150 and ymouse < 160 and button = 1 then %sees if the player clicked
exit %exits the alarm loop
end if
sound (50, 200)
sound (70, 200)
end loop
end lowbeeping
procedure mediumbeeping
cls %clears the screen
Font.Draw ("Awake", 100, 100, font, brightred) %puts the word awake to the screen
drawfillbox (150, 150, 160, 160, red) %draws the awake clickbox
loop %loops to run the alarm
Mouse.Where (xmouse, ymouse, button ) %sees where the mouse is
if xmouse > 150 and xmouse < 160 and ymouse > 150 and ymouse < 160 and button = 1 then %sees if the player clicked
exit %exits the alarm loop
end if
sound (440, 200)
sound (200, 200)
end loop
end mediumbeeping
procedure highbeeping
cls %clears the screen
Font.Draw ("Awake", 100, 100, font, brightred) %puts the word awake to the screen
drawfillbox (150, 150, 160, 160, red) %draws the awake clickbox
loop %loops to run the alarm
Mouse.Where (xmouse, ymouse, button ) %sees where the mouse is
if xmouse > 150 and xmouse < 160 and ymouse > 150 and ymouse < 160 and button = 1 then %sees if the player clicked
exit %exits the alarm loop
end if
sound (4000, 200)
sound (2000, 200)
end loop
end highbeeping
procedure bass
cls %clears the screen
Font.Draw ("Awake", 100, 100, font, brightred) %puts the word awake to the screen
drawfillbox (150, 150, 160, 160, red) %draws the awake clickbox
loop %loops to run the alarm
Mouse.Where (xmouse, ymouse, button ) %sees where the mouse is
if xmouse > 150 and xmouse < 160 and ymouse > 150 and ymouse < 160 and button = 1 then %sees if the player clicked
exit %exits the alarm loop
end if
for count : 40 .. 100
sound (count, 100)
end for
for decreasing count : 100 .. 40
sound (count, 100)
end for
end loop
end bass
procedure helicopter
cls %clears the screen
Font.Draw ("Awake", 100, 100, font, brightred) %puts the word awake to the screen
drawfillbox (150, 150, 160, 160, red) %draws the awake clickbox
loop %loops to run the alarm
Mouse.Where (xmouse, ymouse, button ) %sees where the mouse is
if xmouse > 150 and xmouse < 160 and ymouse > 150 and ymouse < 160 and button = 1 then %sees if the player clicked
exit %exits the alarm loop
end if
for count : 40 .. 500
sound (count, 50)
end for
for decreasing count : 500 .. 40
sound (count, 50)
end for
end loop
end helicopter
procedure alarm1set
cls
put "Which time would you like to set the first alarm for? (hour, minute)"
get alarmHour1, alarmMin1
put "Which sound would you like the alarm to play?"
Font.Draw ("1:Sci-fi", 0, 200, font, brightred)
Font.Draw ("2:Low Beeping", 50, 200, font, brightred)
Font.Draw ("3:Medium Beeping", 160, 200, font, brightred)
Font.Draw ("4:High Beeping", 290, 200, font, brightred)
Font.Draw ("5:Bass", 400, 200, font, brightred)
Font.Draw ("6:Helicopter", 450, 200, font, brightred)
get alarm1sound
alarm1Arm := true
a1Set := true
end alarm1set
procedure alarm2set
cls
put "Which time would you like to set the second alarm for? (hour, minute)"
get alarmHour2, alarmMin2
put "Which sound would you like the alarm to play?"
Font.Draw ("1:Sci-fi", 0, 200, font, brightred)
Font.Draw ("2:Low Beeping", 50, 200, font, brightred)
Font.Draw ("3:Medium Beeping", 160, 200, font, brightred)
Font.Draw ("4:High Beeping", 290, 200, font, brightred)
Font.Draw ("5:Bass", 400, 200, font, brightred)
Font.Draw ("6:Helicopter", 450, 200, font, brightred)
get alarm2sound
alarm2Arm := true
a2Set := true
end alarm2set
procedure getTime
tim := Time.Sec
Time.SecParts (Time.Sec, year, month, day, dayOfWeek, hour, minute, second )
theTime := Time.Date
end getTime
%MAIN CODE
loop
cls %clears the screen
Font.Draw ("Alarm 1 Set", 10, 10, font, brightred)
Font.Draw ("Alarm 2 Set", 100, 10, font, brightred)
Font.Draw ("Arm Alarm 1", 210, 10, font, brightred)
Font.Draw ("Arm Alarm 2", 310, 10, font, brightred)
Font.Draw ("Alarm 1:", 10, 300, font, brightred)
Font.Draw ("Set:", 50, 280, font, brightred)
Font.Draw ("Armed:", 50, 260, font, brightred)
Font.Draw ("Alarm 2:", 200, 300, font, brightred)
Font.Draw ("Set:", 250, 280, font, brightred)
Font.Draw ("Armed:", 250, 260, font, brightred)
if a1Set = true then %sees if the alarm 1 is set
drawfillarc (90, 284, 5, 5, 0, 360, green)
else
drawfillarc (90, 284, 5, 5, 0, 360, red)
end if
if a2Set = true then %sees if the alarm 1 is set
drawfillarc (290, 284, 5, 5, 0, 360, green)
else
drawfillarc (290, 284, 5, 5, 0, 360, red)
end if
if alarm1Arm = true then %sees if the alarm 1 is set
drawfillarc (110, 264, 5, 5, 0, 360, green)
else
drawfillarc (110, 264, 5, 5, 0, 360, red)
end if
if alarm2Arm = true then %sees if the alarm 1 is set
drawfillarc (310, 264, 5, 5, 0, 360, green)
else
drawfillarc (310, 264, 5, 5, 0, 360, red)
end if
loop
getTime %gets the time
locate (1, 1) %locates top of screen
put theTime %puts the time
Mouse.Where (xmouse, ymouse, button ) %sees where the mouse is
if xmouse > 10 and xmouse < 90 and ymouse > 10 and ymouse < 20 and button = 1 then %sees if the user wants to set the alarm times
alarm1set
exit
end if
if xmouse > 100 and xmouse < 190 and ymouse > 10 and ymouse < 20 and button = 1 then %sees if the user wants to set the alarm times
alarm2set
exit
end if
if xmouse > 210 and xmouse < 300 and ymouse > 10 and ymouse < 20 and button = 1 then %sees if the user wants to arm the 1 alarm
alarm1Arm := true
drawfillarc (110, 264, 5, 5, 0, 360, green)
end if
if xmouse > 310 and xmouse < 400 and ymouse > 10 and ymouse < 20 and button = 1 then %sees if the user wants to arm the 2 alarm
alarm2Arm := true
drawfillarc (310, 264, 5, 5, 0, 360, green)
end if
%sees if the first alarm should sound
if alarm1Arm = true then %sees if the alarm is armed
if alarmHour1 = hour and alarmMin1 = minute then %sees if it is the right time to run the alarm
if alarm1sound = 1 then
scifi %accesses the alarm
alarm1Arm := false %sets the alarm to un-armed
Music.SoundOff %quits all music
exit %exits the loop to run the alarm
end if
if alarm1sound = 2 then
lowbeeping %accesses the alarm
alarm1Arm := false %sets the alarm to un-armed
Music.SoundOff %quits all music
exit %exits the loop to run the alarm
end if
if alarm1sound = 3 then
mediumbeeping %accesses the alarm
alarm1Arm := false %sets the alarm to un-armed
Music.SoundOff %quits all music
exit %exits the loop to run the alarm
end if
if alarm1sound = 4 then
highbeeping %accesses the alarm
alarm1Arm := false %sets the alarm to un-armed
Music.SoundOff %quits all music
exit %exits the loop to run the alarm
end if
if alarm1sound = 5 then
bass %accesses the alarm
alarm1Arm := false %sets the alarm to un-armed
Music.SoundOff %quits all music
exit %exits the loop to run the alarm
end if
if alarm1sound = 6 then
helicopter %accesses the alarm
alarm1Arm := false %sets the alarm to un-armed
Music.SoundOff %quits all music
exit %exits the loop to run the alarm
end if
end if
end if
if alarm2Arm = true then %sees if the alarm is armed
%sees if the second alarm should sound
if alarmHour2 = hour and alarmMin2 = minute then %sees if it is the right time to run the alarm
if alarm2sound = 1 then
scifi %accesses the alarm
alarm2Arm := false %sets the alarm to un-armed
Music.SoundOff %quits all music
exit %exits the loop to run the alarm
end if
if alarm2sound = 2 then
lowbeeping %accesses the alarm
alarm2Arm := false %sets the alarm to un-armed
Music.SoundOff %quits all music
exit %exits the loop to run the alarm
end if
if alarm2sound = 3 then
mediumbeeping %accesses the alarm
alarm2Arm := false %sets the alarm to un-armed
Music.SoundOff %quits all music
exit %exits the loop to run the alarm
end if
if alarm2sound = 4 then
highbeeping %accesses the alarm
alarm2Arm := false %sets the alarm to un-armed
Music.SoundOff %quits all music
exit %exits the loop to run the alarm
end if
if alarm2sound = 5 then
bass %accesses the alarm
alarm2Arm := false %sets the alarm to un-armed
Music.SoundOff %quits all music
exit %exits the loop to run the alarm
end if
if alarm2sound = 6 then
helicopter %accesses the alarm
alarm2Arm := false %sets the alarm to un-armed
Music.SoundOff %quits all music
exit %exits the loop to run the alarm
end if
end if
end if
end loop
end loop
|
[Mod Edit: Please use syntax tags, [syntax="Turing"]Code here[/syntax]] |
|
|
|
|
![](images/spacer.gif) |
Sponsor Sponsor
![Sponsor Sponsor](templates/subSilver/images/ranks/stars_rank5.gif)
|
|
![](images/spacer.gif) |
Tony
![](http://wiki.compsci.ca/images/f/f4/OniTony.gif)
|
Posted: Fri Jun 27, 2008 10:55 pm Post subject: RE:Alarm Clock |
|
|
Nice.
One thing I notice, is that the main loop repeats a lot of code. Instead of
Turing: |
if alarm2sound = 1 then
scifi %accesses the alarm
alarm2Arm := false %sets the alarm to un-armed
Music.SoundOff %quits all music
exit %exits the loop to run the alarm
end if
if alarm2sound = 2 then
lowbeeping %accesses the alarm
alarm2Arm := false %sets the alarm to un-armed
Music.SoundOff %quits all music
exit %exits the loop to run the alarm
end if
|
You could create an array of procedures, and use an index to call the proper type. Then it all crunches down to
Turing: |
loop
.. .
if alarmHour2 = hour and alarmMin2 = minute then
alarm_type (alarm2sound )
alarm2Arm := false
Music.SoundOff
exit
end if
end loop
|
|
Tony's programming blog. DWITE - a programming contest. |
|
|
|
![](images/spacer.gif) |
Insectoid
![](http://compsci.ca/v3/uploads/user_avatars/13760332514cbd0ce972eaa.jpg)
|
Posted: Sat Jun 28, 2008 11:02 am Post subject: RE:Alarm Clock |
|
|
That's awesome! Though no doubt you will end up hating this one to. Do you actually use it? I suggest drawing boxes around the words to define the buttons. |
|
|
|
|
![](images/spacer.gif) |
mace
|
Posted: Sat Jun 28, 2008 11:02 pm Post subject: Re: Alarm Clock |
|
|
i used it once, but seeing as how it is teh summer, i rly dont need an alarm clock
thx for the advice |
|
|
|
|
![](images/spacer.gif) |
andrew.
|
Posted: Sun Jun 29, 2008 2:03 pm Post subject: RE:Alarm Clock |
|
|
You should convert the time to 12 hour. I just find it easier to read. I was making an iPod Touch "emulator" a while ago and the only thing I really did was convert 24 hour time to 12 hour. Here is the code if you want to look at it.
Turing: | % iPod Touch Emulator
var iPod_window : int := Window.Open ("title:iPod Touch,graphics:225;335,nobuttonbar,offscreenonly,position:center,center")
var TEMPTIME : string := Time.Date
var TEMPTIME2 : int
var TEMPTIME3 : string
var TIME : string := "02"
var arial9, arial10, arial12, arial14, arial16, arial18 : int
arial9 := Font.New ("Arial:9:bold")
arial10 := Font.New ("Arial:10")
arial12 := Font.New ("Arial:12")
arial14 := Font.New ("Arial:14")
arial16 := Font.New ("Arial:16")
arial18 := Font.New ("Arial:18")
proc TIMESTUFF
TIME := ""
TEMPTIME := Time.Date
for decreasing i : 7 .. 3
TIME + = TEMPTIME (length (TEMPTIME ) - i )
end for
TEMPTIME2 := strint (TIME (1) + TIME (2))
if TEMPTIME2 > 12 then
TEMPTIME3 := TIME (3) + TIME (4) + TIME (5)
TIME := " " + intstr (TEMPTIME2 - 12) + TEMPTIME3
TIME + = " PM"
else
TIME + = " AM"
end if
end TIMESTUFF
loop
cls
TIMESTUFF
drawfillbox (0, 0, maxx, maxy, black)
Font.Draw ("iPod", 1, maxy - 11, arial9, white)
Font.Draw (TIME, maxx div 2 - (Font.Width (TIME, arial9 ) div 2), maxy - 12, arial9, white)
View.Update
delay (5)
end loop |
It's modified. I took out some pictures and stuff that I used. |
|
|
|
|
![](images/spacer.gif) |
mace
|
Posted: Mon Jun 30, 2008 12:59 am Post subject: Re: Alarm Clock |
|
|
thx for the advice, i myself like 24 hour time, but i will be sure to incorporate it for ease of use to others |
|
|
|
|
![](images/spacer.gif) |
Tony
![](http://wiki.compsci.ca/images/f/f4/OniTony.gif)
|
Posted: Mon Jun 30, 2008 1:37 am Post subject: RE:Alarm Clock |
|
|
What I'm interested in knowing is how well this works once the computer goes into the sleep mode. |
Tony's programming blog. DWITE - a programming contest. |
|
|
|
![](images/spacer.gif) |
|
|