Time Delay Not Working

Hi Everyone,

I need help with making a time delay between events. So what I have is two screens. Screen 1 has a Bluetooth List picker as below.

So after the Bluetooth device is connected, the code jumps to the next screen called "StartingScreen" as seen above.

So I want to display "StartingScreen" for 5 seconds before moving to "SlectionScreen" as seen below.

None of the above coding works. What happens now is that after the Bluetooth device is connected, the screen goes black for the duration of the delay (5 seconds), then the "StartingScreen" screen appears for like half a second the jumps to "SlectionScreen". The delay I have does not wait for "StartingScreen" to initialize and the execute the delay.
Your assistance will be very much appreciated.

Many Thanks

You are doing two things wrong.

  • You are trying to loop to wait
  • you are switching screens in a BlueTooth app.

Pull in a Clock from the Sensors drawer and use its Timer event to change your display.

Use a hidden arrangement instead of each screen, your life will be simpler.

1 Like

Hi ABG,

Thank you so much for you prompt response. Is it perhaps possible for you to show me how to achieve that? I'm a serious noob so my skill is not as tuned as it should be yet.

Thanks

see tip 1

and Please Wait method by Scott

Taifun


Trying to push the limits! Snippets, Tutorials and Extensions from Pura Vida Apps by icon24 Taifun.

2 Likes

Hi again ABG,

When you get the time please assist with this if you're able to. I just need a brief note on how to achieve using a clock timer to switch screens like you mentioned before.

Many Thanks.

One way to do it is like this, but as @ABG suggested since you are using bluetooth it is better to use hidden arrangements as virtual screens. So when Clock.Timer hide one arrangement ( set visible to false) and show another (set visible to true)

You must abandon all other Screens besides Screen1 if you want to use BlueTooth.

Do an AI2->Project->SaveAs into a new Project name, as backup in case you lose something and need to go back and Copy (Ctrl-C) and Paste (Ctrl-V) into your new project.

Remove those other Screens, and make new Vertical Arrangements in Screen1, for your different displays.
Example project:

In particular, see the section where I hide and expose Vertical Arrangements, and the Designer section where I show the stacked Vertical Arrangements in Screen1.

Regarding the BlueTooth Clock usage, here is a standard set of blocks for that, using a Delimiter:


global message
(draggable)

(yes, I should have set the Delimiter in Screen1.Initialize, some day I will get around to fixing this.)

Here is the standard explanation for this:

Please see the Delimiter article in FAQ

Be sure to use println() at the end of each message to send from the sending device, to signal end of message. Do not rely on timing for this, which is unreliable.

In the AI2 Designer, set the Delimiter attribute of the BlueTooth Client component to 10 to recognize the End of Line character.
BlueToothClient1_Properties
Also, return data is not immediately available after sending a request,
you have to start a Clock Timer repeating and watch for its arrival in the Clock Timer event. The repeat rate of the Clock Timer should be faster than the transmission rate in the sending device, to not flood the AI2 buffers.

In your Clock Timer, you should check

  Is the BlueTooth Client still Connected?
  Is Bytes Available > 0?
     IF Bytes Available > 0 THEN
       set message var  to BT.ReceiveText(-1) 

This takes advantage of a special case in the ReceiveText block:

ReceiveText(numberOfBytes)
Receive text from the connected Bluetooth device. If numberOfBytes is less than 0, read until a delimiter byte value is received.

If you are sending multiple data values per message separated by | or comma, have your message split into a local or global variable for inspection before trying to select list items from it. Test if (length of list(split list result) >= expected list length) before doing any select list item operations, to avoid taking a long walk on a short pier. This bulletproofing is necessary in case your sending device sneaks in some commentary messages with the data values.

1 Like

Thank you so much ABG,

I tried this solution separately and it seemed to work, though I had no clue what I was doing. However, Deleting all my other screens was not an option for me. I have recently found out that having multiple screens is not necessarily the best idea, but I already have them and deleting them would mean starting my project from scratch, which I am not prepared to do at this point. All my hard work fam. I'll keep this solution in mind for my next app. I appreciate you so much for taking the time to work through this with me.

Hi Guys,

So I was able to solve this by playing around with the clock sensor. Took a lot of doing, but I finally got it to work.

The call is a procedure. So is it that you've introduced a variable? called close_screen. Particularly, I am new in here and certainly would be happy if helped?
Also, I am not making a Bluetooth app. Actually, I want to make a screen that gives a delay of 5 seconds after a person logs in (On Screen 1, there is a login form, that is done and working.)
Please assist asap.
Thanking you in advance.

These examples are for splash screens but should give you an idea of what to do