Help With Clock
Author |
Message |
supallama
|
Posted: Sun Oct 02, 2011 2:02 pm Post subject: Help With Clock |
|
|
What is it you are trying to achieve?
I am trying to create a clock that has an alarm
What is the problem you are having?
the GUI buttons do not work
Describe what you have tried to solve this problem
Googled the answer
Post any relevant code (You may choose to attach the file instead of posting the code if it is too long)
no relevent code aside from the whole thing
Turing: |
import GUI
View.Set ("graphics:640;400,nobuttonbar")
var hour, mi, sec : int := 0
var answer : int
var alarm : string
alarm := "00:00:00"
procedure setAlarm
cls
put "Please set alarm : " ..
get alarm
%incase something happens
end setAlarm
procedure displayClock (hourHand, minuteHand, secondHand : int)
colorback (97)
setscreen ("offscreenonly")
const PI := 3. 14159
var whatTime : string
var whatDate : string
var hour, minute, second : int
var x, y, x2, y2 : int
var ang : real
var timeRunning : int
var Seconds : real
loop
var draw : int := GUI.CreateButtonFull (maxx div 2 - 210, 100, 0, "Set Alarm",
setAlarm, 0, '^D', true)
var quitBtn : int := GUI.CreateButton (maxx div 2 + 150, 100, 0, "Quit", GUI.Quit)
clock (timeRunning )
Seconds := timeRunning / 1000
%put "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\nThis program has been running for ", Seconds, " seconds"
date (whatDate )
locate (1, 1)
put " The date is ", whatDate
time (whatTime )
hour := strint (whatTime (1 .. 2))
hour := hour mod 12
minute := strint (whatTime (4 .. 5))
second := strint (whatTime (7 .. 8))
%hour hand
ang := ((hour + (minute / 60)) / 12) * 360 - 90
x := round (cos (-ang * (PI / 180)) * hourHand + maxx div 2)
y := round (sin (-ang * (PI / 180)) * hourHand + maxy div 2)
drawline (maxx div 2, maxy div 2, x, y, 7)
%minute hand
ang := (minute / 60) * 360 - 90
x := round (cos (-ang * (PI / 180)) * minuteHand + maxx div 2)
y := round (sin (-ang * (PI / 180)) * minuteHand + maxy div 2)
drawline (maxx div 2, maxy div 2, x, y, 7)
%second hand
ang := (second / 60) * 360 - 90
x := round (cos (-ang * (PI / 180)) * secondHand + maxx div 2)
y := round (sin (-ang * (PI / 180)) * secondHand + maxy div 2)
drawline (maxx div 2, maxy div 2, x, y, 7)
%draw face
for i : - 90 .. 270 by 6
if i mod 15 = 0 then
x := round (cos (-i * (PI / 180)) * (max (hourHand, max (minuteHand, secondHand ))) + maxx div 2)
y := round (sin (-i * (PI / 180)) * (max (hourHand, max (minuteHand, secondHand ))) + maxy div 2)
x2 := round (cos (-i * (PI / 180)) * (max (hourHand, max (minuteHand, secondHand )) + 10) + maxx div 2)
y2 := round (sin (-i * (PI / 180)) * (max (hourHand, max (minuteHand, secondHand )) + 10) + maxy div 2)
else
x := round (cos (-i * (PI / 180)) * (max (hourHand, max (minuteHand, secondHand )) + 5) + maxx div 2)
y := round (sin (-i * (PI / 180)) * (max (hourHand, max (minuteHand, secondHand )) + 5) + maxy div 2)
x2 := round (cos (-i * (PI / 180)) * (max (hourHand, max (minuteHand, secondHand )) + 10) + maxx div 2)
y2 := round (sin (-i * (PI / 180)) * (max (hourHand, max (minuteHand, secondHand )) + 10) + maxy div 2)
end if
drawline (x, y, x2, y2, 7)
end for
drawoval (maxx div 2, maxy div 2, max (hourHand, max (minuteHand, secondHand )) + 10, max (hourHand, max (minuteHand, secondHand )) + 10, 7)
put " The time is : ", whatTime
if alarm = whatTime then
Music.PlayFileReturn ("gm.mp3")
end if
View.Update
cls
GUI.Refresh
end loop
GUI.Refresh
end displayClock
%main program
loop
Music.PlayFileLoop ("tic.mp3")
displayClock (40, 70, 80)
exit when GUI.ProcessEvent
end loop
|
Please specify what version of Turing you are using
Turing 4.1.1 |
|
|
|
|
|
Sponsor Sponsor
|
|
|
Tony
|
Posted: Sun Oct 02, 2011 2:15 pm Post subject: RE:Help With Clock |
|
|
GUI buttons "work" only during the moment that GUI.ProcessEvent line is being called. Which, in your program, is precisely never. |
Tony's programming blog. DWITE - a programming contest. |
|
|
|
|
supallama
|
Posted: Sun Oct 02, 2011 2:15 pm Post subject: RE:Help With Clock |
|
|
**ADDITIONAL INFORMATION**
-The clock is supposed to get the time from the user and then play good morning by the beatles and continue moving
-The clock is also supposed to play a tick noise while moving
- I was hoping to put 12, 3, 6, and 9 on the face of the clock, or outside of the clock but that was somthing I would have gotten to after the GUI buttons |
|
|
|
|
|
supallama
|
Posted: Sun Oct 02, 2011 2:28 pm Post subject: RE:Help With Clock |
|
|
OK, so I have moved GUI.ProcessEent from the main program loop to just underneath GUI.Refresh near the bottom of the displayClock procedure and it makes it active, but the words "please set alarm" are not revealed unless I close the running window |
|
|
|
|
|
Tony
|
Posted: Sun Oct 02, 2011 3:08 pm Post subject: RE:Help With Clock |
|
|
Take a few guesses as to why you might not be able to see those words. |
Tony's programming blog. DWITE - a programming contest. |
|
|
|
|
supallama
|
Posted: Sun Oct 02, 2011 8:35 pm Post subject: RE:Help With Clock |
|
|
tell ya the truth I have no idea, I am a newbie at this |
|
|
|
|
|
Tony
|
Posted: Sun Oct 02, 2011 9:05 pm Post subject: RE:Help With Clock |
|
|
The very first step to approaching this problem is to confirm that this code even runs. We can't see the output on the screen, but we could do other things... e.g. we could try writing to a file. Though since we just want a yes/no answer here, we could throw an exception
code: |
put "Please set alarm : " ..
quit
|
This confirms that the code actually runs. Good.
This leaves you with two options:
- the text is drawn and then quickly erased (unlikely; proof left as an exercise for the student)
- the text is drawn but the screen is not updated |
Tony's programming blog. DWITE - a programming contest. |
|
|
|
|
|
|