BasicMicroUK - Forums

www.basicmicro.co.uk
It is currently Thu Apr 26, 2018 2:56 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 4 posts ] 
Author Message
 Post subject: how to wait 20sec then jump to a menu
PostPosted: Thu Jan 30, 2014 5:52 pm 
Offline
Guru

Joined: Sat Mar 30, 2013 10:19 pm
Posts: 51
Hi all, let me try and explain what i want to achieve. I have an lcd and 3 micro switches, i have a working ish program based around an alarm clock. What i want to do is, when in the setup menu: set time, set alarm1, set alarm2 etc.. and the 3 buttons are poling, waiting for an input, if non is received for 20sec then it will exit that loop, dim the lcd and goto the main display time screen and continue to wait until a button is press again were it will go to full brightness and the relevant menu.
so....
if no button pushes for 20sec then
goto main display
endif

how do i put that in mbasic

thanks in advance


Top
 Profile  
 
 Post subject: Re: how to wait 20sec then jump to a menu
PostPosted: Fri Jan 31, 2014 3:27 am 
Offline
Site Admin
User avatar

Joined: Fri Apr 12, 2013 8:38 pm
Posts: 87
Location: Nottingham, England, UK
HI

Maybe the simplest way to do this would be to set up a loop counter, before you enter the keypad polling loop set this counter to 0 and then within the loop after checking for the key press increment the loop counter by one and then check the value and if its over a certain value leave the polling loop,

You will need to experiment to see what value you need to the loop counter to get to before you exit but this will be determined by how many loops per second its taking to check all 3 buttons and do what ever other things go on within the loop, you can do a test by for example making the press of one button print out the value of the loop count, you then manually wait 20 seconds and press the button, the printed value will then be the number of loops the polling routine has gone through in 20 seconds and that's the compare value you need to use to exit the polling routine,

Remember to size the type of loop count variable to accommodate the expected number of loops, I expect a WORD size variable would be OK here but use LONG if needed,

I hope this helps,

Dave
BasicMicroUK

www.basicmicro.co.uk


Top
 Profile  
 
 Post subject: Re: how to wait 20sec then jump to a menu
PostPosted: Fri Jan 31, 2014 5:55 am 
Offline
Master

Joined: Wed Oct 19, 2011 2:28 am
Posts: 123
Hi,
here it is a program that you can try it. It will read the switches and go to the selection when press. It will run for 20 sec and goes out if not switch press. You may need to modify it for your need.

twenty_sec var word

main


'***********************************************************
read_switch
twenty_sec = 0
repeat

if IN1 = 0 then
gosub update_time
elseif IN2 = 0
gosub update_alarm1
elseif IN3 = 0
gosub update_alarm2
endif
twenty_sec = twenty_sec + 1

until (twenty_sec = 20000) ' Adjust if it is necesary

gosub dim_lcd
pause 100
serout s_out,i9600,["No Switch press ",13]

goto main

'**********************************************************
dim_lcd
serout s_out,i9600,["Dime lcd routine",13]
return
'**********************************************************
full_bri
serout s_out,i9600,["Increase lcd routine",13]
return
'*********************************************************
update_time
serout s_out,i9600,["Set time routine",13]
return
'**********************************************************
update_alarm1
serout s_out,i9600,["Set Alarm 1 routine",13]
return
'***********************************************************
update_alarm2
serout s_out,i9600,["Set Alarm 2 routine",13]
return
'***********************************************************


Top
 Profile  
 
 Post subject: Re: how to wait 20sec then jump to a menu
PostPosted: Thu Feb 06, 2014 12:03 pm 
Offline
Guru

Joined: Sat Mar 30, 2013 10:19 pm
Posts: 51
hi, Using the repeat until command and modding the sample code found me a solution that works and is easy to understand. Thanks to both of you.


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

All times are UTC [ DST ]


Who is online

Users browsing this forum: No registered users and 0 guests


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:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group

phpBB SEO