BasicMicroUK - Forums

www.basicmicro.co.uk
It is currently Wed Oct 24, 2018 1:38 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 4 posts ] 
Author Message
 Post subject: Timing?
PostPosted: Tue Sep 02, 2014 9:58 pm 
Offline
New User

Joined: Tue Sep 02, 2014 9:47 pm
Posts: 2
Hello,
Just wondering if anyone can give me a good example of timing?
Lets say I have a button connected to an input pin and an LED on a different output pin.
I press the button and the LED turns on after x seconds.
But I want the program to be able to do other stuff at the same time.

Thoughts?

David


Top
 Profile  
 
 Post subject: Re: Timing?
PostPosted: Thu Sep 04, 2014 2:46 am 
Offline
Master

Joined: Wed Oct 19, 2011 2:28 am
Posts: 123
Hi,
Here it is a small routine for you to try it. See if this is what you are looking. You need to customize the I/O pins.
Just copy it to the basic micro editor and do a program.
tst_swt var bit
led_light con bit = P2 'Led pin output - change the 2 to the desire pin output

Main

loop_here
gosub test_button
pause 1000
goto loop_here
end

'*************************** test button routine ****************************
test_button
'This routine will check the switch and if it is zero then it will delay depending
'of the delay and then turn ON the led light by grounding the led. The led must be
'in seris with a 500 ohms resistor connected to the +5. The led cathode it is
'connected to the output pin of the micro, When the led cathode it is grounded
'the led will turn ON. You caa also connect the led dirrectly in series with a
'500 ohms resistorthe led 'to the pin and allow the 'the micro to feed the led
'when the pin it is high or low.


tst_swt = IN1 'Change the 1 to the desire input pin. Read the input pin 1.
if tst_swt = 0 then
pause 1000 : low led_light 'low will turn on the led
endif

return
'*******************************************************************************


Top
 Profile  
 
 Post subject: Re: Timing?
PostPosted: Thu Sep 04, 2014 5:48 pm 
Offline
New User

Joined: Tue Sep 02, 2014 9:47 pm
Posts: 2
Hi tauro0221,

So the Pause 1000 is for the delay? For 1 second I assume.
But does that 'pause' function make the entire code wait for that one second or can it continue to do other things in the program?
I am new to Basic but have learned C for arduino. A similar thing would be like using the millis() function but I have not found anything in Basic that does that.

Thanks

David


Top
 Profile  
 
 Post subject: Re: Timing?
PostPosted: Thu Sep 04, 2014 7:22 pm 
Offline
Master

Joined: Wed Oct 19, 2011 2:28 am
Posts: 123
Hi,
Yes, your are right. That is why I do not like to use it. You will hold the execution of command until it time out. I also used Arduino,Picaxe and Zbasics. What you do it is try to match/modify the command from the Arduino to Micro basic. I like Basic micro than Arduino because it has more powerful instructions. Once you know a programming language it is easy to move from one to the other. My advised it is to read the reference manual since they have samples on how to uses every commands.


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

phpBB SEO