BasicMicroUK - Forums

www.basicmicro.co.uk
It is currently Fri Oct 19, 2018 9:15 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: alarm clock display logic question
PostPosted: Thu Nov 14, 2013 3:28 pm 
Offline
Guru

Joined: Sat Mar 30, 2013 10:19 pm
Posts: 51
Hi all, im stuck on the display part of the alarm clock im working on. All works fine other than what is displayed on screen on the alarm side. The display shows on the top line of a 2x16 lcd the time from the rtc ds1307 the next line is supposed to show the alarm that is next due, that's one of two alarm times. Below you'll find code that Ive been playing with. Is there a command equivalent to the expression inbetween? eg: if the time is in between alarm 1 and 2 show display1, if alarm is in between 2 and 1 show display 2. I guess another possible issue is what happens at 23:59 or 00:00.
thanks in advance

Code:
Lcdwrite p0\p1\p7\p6\p5\p4,p2, [homelcd,scr,twoline, dec hrs\2, ":", dec mins\2, ":", dec secs\2]   'displays time   
   
   if mins<=a1mins and hrs<=a1hrs then
   Lcdwrite p0\p1\p7\p6\p5\p4,p2, [scr,scrram+64,"Feed ", dec a1hrs\2, ":", dec a1mins\2]    'displays alarm1 time
   endif
   
   'if mins>a1mins and hrs>a1hrs and mins<a2mins and hrs<a2hrs then
   'Lcdwrite p0\p1\p7\p6\p5\p4,p2, [scr,scrram+64,"Feed ", dec a2hrs\2, ":", dec a2mins\2]    'displays alarm2 time
   'endif
      
   if mins>a1mins and hrs>a1hrs then
   Lcdwrite p0\p1\p7\p6\p5\p4,p2, [scr,scrram+64,"Feed ", dec a2hrs\2, ":", dec a2mins\2]    'displays alarm2 time
   endif
   


Top
 Profile  
 
 Post subject: Re: alarm clock display logic question
PostPosted: Thu Nov 14, 2013 4:30 pm 
Offline
Master

Joined: Tue Nov 21, 2006 5:34 pm
Posts: 662
I think I know what you are asking. Something like: If the next alarm to go off is Alarm1 show Alarm1 else show Alarm2?

There are lots of ways to do this, here is a real sloppy way. Note: I am real rusty doing basic.
Code:
minAlarm1 var word
minAlam2  var word

    gosub MinToAlarm[a1hrs, a1mins], minAlarm1
    gosub MinToAlarm[a2hrs, a2mins], minAlarm2

    if (minAlarm1 < minAlarm2) then
        display Alarm 1
    else
        display Alarm 2

...

ALHR var byte
ALMIN var byte
MinToAlarm[ALHR, ALMIN]:
   ; See if the Alarm time is earlier than our current time if so return how long until it would ring the next day
    if ((ALHR < HRS) or ((ALHR = HRS) and (ALMIN< MINS))) then
        return (ALHR-HRS+24)*60 + ALMIN - MINS
    endif
    ; else simple case that it will ring some time today
    return (ALHR-HRS)*60 + ALMIN - MINS


Warning typed on fly not compiled, probably buggy. Also can easily do without subroutines. Also can do without conversion to minutes to alarm, but this might make it easier to understand. Also could have done function without first test, by instead have the delta time variable be a signed variable. Do the calculation of the main return and if the value is < 0 add 24*60 to it...
like:
Code:
minAlarm1 var sword
minAlarm2 var sword

minAlarm1 = (a1hrs-HRS)*60 + a1mins- MINS
if (minAlarm1 < 0) then
    minAlarm1 = minAlarm1 + 24*60
endif

minAlarm2 = (a2hrs-HRS)*60 + a2mins- MINS
if (minAlarm2 < 0) then
    minAlarm2 = minAlarm2 + 24*60
endif
...


Top
 Profile  
 
 Post subject: Re: alarm clock display logic question
PostPosted: Mon Jan 06, 2014 12:37 pm 
Offline
Guru

Joined: Sat Mar 30, 2013 10:19 pm
Posts: 51
hi again, a quick update as im back onto the project. i tried playing with your options but probably due to my limited programming knowledge they didnt work. my work around was to convert parameters to seconds and do a subtraction calculation to get the result.
Code:
'time converted to seconds   
   thrs = (hrs*60)*60             'hrs in seconds
   tmins = (mins*60)              'mins in seconds
   ttime = thrs+tmins+secs         'total time in seconds

'alarm1 converted to seconds
   ta1hrs = (a1hrs*60)*60          'a1hrs in seconds
   ta1mins = (a1mins*60)          'a1mins in seconds   
   talarm1 = ta1hrs+ta1mins      'total alarm1 in seconds

'alarm2 converted to seconds
   ta2hrs = (a2hrs*60)*60          'a2hrs in seconds
   ta2mins = (a2mins*60)         'a2mins in seconds
   talarm2 = ta2hrs+ta2mins      'total alarm2 in seconds
      
'compares time and alarms for next alarm display   
   if  ttime<talarm1 or ttime>talarm2 then
       alarm1trig = 0
       gosub display_alarm1
    else 
       alarm1trig = 1
       gosub display_alarm2
    endif   


still cant understand why the same line "if mins<a1mins and hrs<a1hrs or mins>a2mins and hrs>a2hrs" did not work unless converted as above. thanks again and hope it helps someone else


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group

phpBB SEO