Help with coding a delay

Hi everyone,
I have a problem with making APP to run correctly,
I have my C8051F380 getting "chars" from the APP, I need to make a loop of button being "Touched Down" and inside of it making a loop of maybe "while loop" so it will continue to send via Bluetooth text, (same text) as long as the button is pressed.

In C8051F380 program I have a condition of "while I getting x via Bluetooth, checking distance" with ultrasonic.

Thanks for helping.


AI2 does not support delay procedures like you would find in low level devices.

Instead, have a Clock (from the Sensors Drawer) periodically cycle through whatever global variables or Button attributes (Bold, background color) have been set by your button Touchdown and TouchUP events for the Clock Timer event block to know what to send.

Thanks for the quick response,
but I didn't really understood you, I have (I think) global function for a delay, using a clock (from the Sensors Drawer) how I can do a loop now in "when Button1.RouchDown" ?

You can start by reading about that here:

1 Like

There is not a Block Method like DelayClock in App Inventor 2 . What you can do with a Clock is documented here in Clock


What app inventor builder are you using Vit?

Of course, there is:


Here is a sample project.
I don't have BlueTooth, but imagine my text to speech is bluetooth for the demo.
button_down_up.aia (2.4 KB)

And here's a video of it working ...

(I haven't figured out how to get Loom to record my PC speaker output yet, and I don't have a microphone attached to my PC, so the video is unfortunately silent. Run the demo on your own setup to hear the beeps and boops.

1 Like

as it already has been said

see also Why is a wait procedure generally a bad idea?
and The model of event processing in App Inventor by Lyn
see how to do it here Please Wait method by Scott

but you also could try this extension, which might be easier for you?

if you want to try the extension, then please let us know how it works for you...


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

1 Like

This is NOT a Block Method, what is shown in these Blocks is a renaming a Clock component. Not a very good idea to use this ad hoc delay Procedure. See Taifun's comments regarding avoiding delay procedures like this. :frowning:

Yes, but that doesn't contradict my statement.

Perhaps, you could use "When Clock.timer" or a procedure block loop
(Procedure{SCRIPT, if-Procedure})

Thanks for your detailed answer but I still having some issue,
unforgettably still didn't work, with this code can't sent char via Bluetooth

Perhaps this is easier to understand. I use a label instead of a bluetooth send text, you can see in the video the 1's being sent while button is held down, then a 0 when button released. This is using a clock interval of 1 second.

blocks (1)

1 Like

You are life saver ! <3 thanks, it's worked :slight_smile:

that what i did...

I have another question , how can I arrange that all functions to look more visually appealing ?

Thanks to everyone who haled and gave advise :slight_smile:

Have a look at the any component blocks. You should be able to easily reduce the touch up events to just one, given the output is always the same.

More complicated, but doable, would be to use the anyButton Touch Down event

But each button must sent another char, just on the "Touch Up" button I need to send '0'

As I said: More complicated, but doable....... for the touch down events

1 Like

ooh okay, got you :wink: thanks again for help

Not tested, but something like this:

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.