On Feb 17, 2007, at 2:21 PM, Jeffrey Ellis wrote:

So now, that's working, but I have set up 3 timers to do the alarm.

TimeTimer, AlarmTimer, and DelayTimer.

The idea is to test if we have passed the Alarm Time, and Speak a phrase, once every minute for 5 minutes. Then it should delay for another 5 minutes, then repeat speaking the phrase once a minute for 5 minutes again. Then
stop.


That's definitely unnecessary. One timer should be all you need. Just store some settings as properties to keep track of various states, like the delay and whether the alarm as sounded. Ideally you should make your own custom timer class that includes those properties as well as methods for initializing, setting the alarm time, delay value, and events such as drawCurrentTime, etc.

For instance, you could have a property "AlarmRinging as boolean" that indicates whether the alarm time has been reached. If it hasn't, you then do your time comparison to see if the alarm should go off. If the time comparison is positive, that's where you'd set "AlarmRinging = true".

If AlarmRinging is false, you can increment a delay value or check the "ticks" function and compare to the saved delay value. This will tell you how much time has passed since the last alarm sound. You then check to see if that's over a threshhold (like your five minute value) and if it is, you sound the alarm again (and reset the delay time to zero). Each time the alarm sounds you could also increment a counter to indicate the number of times the alarm as sounded, so you could stop after a certain number of alarms.

The result of all this is that your timer, which executes once every second, is doing very little at each check:


Timer Action Event:

currentDate = new date
if alarmRinging then
  delayDifference = ticks - delayCount
  if delayDifference > (5 * 60) then SoundAlarm // Method
else
if currentDate.totalseconds > targetDate.totalseconds then SoundAlarm // Method
end if

drawCurrentTime(currentDate) // Event


SoundAlarm method:

alarmRinging = true
delayCount = ticks // Reset
speak "The time is now " + currentDate.shorttime + ". Please wake up!"
alarmCount = alarmCount + 1
if alarmCount > 5 then me.mode = 0 // Turn off timer


This is untested code but is just about all you'd need. If you have questions about how to create a custom class to do this, write me off list and I can help.



Marc Zeedar
Publisher, REALbasic Developer magazine
www.rbdeveloper.com


_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>

Search the archives:
<http://support.realsoftware.com/listarchives/lists.html>

Reply via email to