Shop OBEX P1 Docs P2 Docs Learn Events
Another simple question — Parallax Forums

Another simple question

hottnikks36hottnikks36 Posts: 8
edited 2006-03-20 03:02 in BASIC Stamp
Hello guys,

I have a question about a similar topic that i saw on these boards a few weeks ago, but sadly i cannot find that thread anymore. So sorry if i seem a bit repetitive with this question.

I'm trying to run a bit of code every 15-20 seconds. The precise measuring of time is not important.

I have a Parallax Bluetooth EB500 transceiver attached to my BS2p, and in the code, i have simple lines that say:

'status is an INPUT pin. When status = 1, that means some other Bluetooth device is connected to my EB500

WaitForConnection:
IF status = 0 THEN WaitForConnection 'this loops keeps looping until status = 1
DEBUG "Status Pin HIGH. Connection established", CR

Now lets say I don't want to wait for a connection forever (like that code is doing, just keeps looping until connection). I want to add a timeout, after 15-20 seconds of waiting for a connection, if no connection comes (status still = 0), it goes and does another piece of code. Is there a way to implement a timer of some sorts in the BS2p?

Thanks for your help, very much appreciated.

Comments

  • PJAllenPJAllen Banned Posts: 5,065
    edited 2006-03-20 00:32
    · SERIN has the optional labels Timeout and Tlabel.· Timeout tells it how long to wait and Tlabel tells the program where to go in the event that Timeout is met/exceeded.
  • aliniousalinious Posts: 51
    edited 2006-03-20 01:17
    You could use a DO.. WHILE LOOP and a variable to count the number of times the loop executes. I have attached a piece of sample code that will enter a DO...WHILE LOOP if the status pin equals zero. While in the DO...WHILE LOOP, the "TimeOut" Variable increments every time the loop is executed. The "IF" statement breaks the loop if the timeout variable accumulates a value of 20000. The reason I chose 20000 for the timeout is because the loop pauses for one millisecond, therefore, the loop will be exited after approximately 20 seconds.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    "I learn when I succeed, but I learn more when I fail."
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2006-03-20 03:02
    By any chance was this the thread you were looking for?

    http://forums.parallax.com/showthread.php?p=570148

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
    csavage@parallax.com
Sign In or Register to comment.