Need help for optimization the blocks please

The attached is project use a Joystick to control a car by Bluetooth, the design intent is let the APP send data in the scope of x(60, 220), y(60, 220) by the order of [1, current x, current y], I really think what I have done is not too good, I'd say it quite bad. need help to optimize it please.
attached the pictures for the sprite blocks only, please let me know if you need the whole.

1 Like

Dear @lladam,
I took a sight to your blocks and I see that you send to the BT too much times.
As far as I have understood you want to send to your car only values ranging between 60 and 220 for both X and Y. But in your algorithm, when you check the limits for X you always send the Y value, whatever it is (before checking its real value), This can cause erratical behaviour of your car.
I guess you better organize differently your blocks; in other words: before sending ANY value to the BT, you shall check for the limits of both X and Y, and only after having checked their values, then you can send these values (or the limits, if exceeded) to the car.
Please consider tho blocks below. Honestly to print the X and Y values when they are thresholded seems to me useless, but anyway I did it, also changing their colours from yellow to red.
Cheers, Ugo.



Thank you uskiara
you did great!
It was a busy communication for BT, and died the program often.

1 Like

Glad to have helped :+1: :blush:


Thank you.
one more question, I post the whole blocks below, that keep died the simulation.

1 Like

I am getting deja vu here.

I answered this recently.


Thank you ABG,
this blocks here ref. from: which used Balls.

Here this one used Imagesprite, the reason I used and modified this is its better looks.

Yes. you solved one similar problem before, now it stuck and slow operating when I test on my phone as long as the Imagesprite moved, I didn't find the error yet.

1 Like

The link you provided only works for you.

The general answer here is to receive text only in the Clock Timer, under protection by test for BytesAvailable > 0.


Thank you ABG,
do you mean my design is different, are there any general rules or more popular way to do the job。
the main problem here for me is how to send character and Joystick date together.

1 Like

If you want me to look at project
first try to open this project:

Do you understand the problem with your link yet?

1 Like

Thank you ABG.
I found one '-1' in button 'b' forgot to remove, is this the point?


Dear @lladam,
when you put "-1" as number of bytes, this means that the BT client waits 'till the terminator character is received : i.e. LF linefeed, or 0x0A hex or 10 dec. or other characters that you set in the BT client parameters in the designer view. But this means that if you are not receiving any character from the BT, the block can remain stuck there. I suggest that you use the BytesAvailableToreceive before attempting to receive from the BT. Something like this:

1 Like

One more question in the same project, that is when I restart to use the APP after a little while the APP used, it fall into black screen and need wait till a window pop out see below picture.
For overcome this I added a exit button even, still didn't work, why?


Export your .aia file and upload it here.

1 Like

JMMAGCOR_V5_2 (1).aia (9.8 KB)

I don't see anything obvious that would make the app hang, except possibly some of the drag events trying to transmit before BT is connected.

For good measure, I suggest wrapping each place you send BT data with a test if BT is connected, like you do where you receive BT data.

1 Like

Thank you ABG.
I'll tested that the APP hang in both BT connected and disconnected. I just used the APP interface button did the test, may not correct?

I did not add the required tests.
I left that to you, so
code before you test.

Dear @lladam,
as I told in one of my previous posts you should better check if characters are available in the receiving buffer from the BT. It is not enough to test if the BT is still connected, you always have to check for characters.
In this block (I've downloaded your .aia and unless I have downloaded a wrong one) you still don't do it:
I also would rather suggest to not enable the clock1 from the designer page, but only after you have initialized all the rest, in a block of the screen1 initialize. And I don't allow (typically) clock to fire always, unless you need them to fire in background.
If it still doesn't work, try to play with the period of clock1: 1000 ms is really suitable for your needs ? Normally I use much faster clocks to catch the BT line (i.e. < 100ms). But of course it depends on your updating needs....

Please let us know if you'll get some improvement.
Ciao, Ugo.


Thank you Ciao.
I did the test in my sketch and .aia, that works quite well. Achieved the design purpose I mean the button controlled the LED ON/OFF.
I am not a programmer, if you mean some else testing, would you please send some clues?