Hi ABG, thanks for your suggestion. I am using microbit block coding, they have a pre-written block 'bluetooth uart service' and can't seem to find print command.. I am sorry that i am not a coding-savvy guy, still much dependent on block coding
You can also read this topic:
i try to use the block 'segment text..start...length' but get into error also..
[50,49,51] => segment text getLDR, start 2, length 8 doesn't seem to be the correct approach. Please advise. Thank You.
Thank you Patryk_F, I'll have a look.
Dear @Thenk_Hou, as far as your "[" and "]" question, you can do like this:
in other words, you can replace whatever character with a null character (not a blank/space, but an empty/null one). Then you can split the remaining at commas.
Of course the suggestions from @Patryk_F or @ABG are good as well !!! You can try and choose whichever ir simpler (the simplest the best, always )
If you write [50,49,51,10] and do a Receive Text in AI2, there is a good chance you will receive your 3 digit number as a piece of text, with no extra markup ("",)
The extra 10 I added at the end if a Line Feed, that can be used like in my Delimiter article to catch a whole message in AI2.
Hi Juan, thanks for your advice. I have tried ur code but so strange that I am getting back some funny output.
if i set the label1.text to global ldr, the output value is "50,49,51";
if i set the label1.text to global decimal, the output value is back to [50,49,51] and
if i set it to global ldrList, the value is [[50,49,51]].. seems like the code will add back the "[" and "]" automatically..
Please englighten. Thanks in advance.
Let's have a contest who has the simplest solution. This is mine:
Add a Webviewer to your design. It does not have to be visible, therefore you do not have to see it.
Now, add this block:
The string in the join is actually this:
window.AppInventor.setWebViewString(String.fromCharCode(
So, instead of waiting for BytesReceived, you wait for WebViewStringChange.
Also add this block:
Here I add the value to a label containing previously received text. You may want to do something different.
The trick is that JavaScript knows how to convert ASCII and AppInventor does not. We have asked for this alreay to be implemented. Keep your fingers crossed.
Great Juan! I have found out I pick some wrong block thus resulting in error. The code works! Tq very much!
Hi Ghica, I'll try ur code out after this to see if it does simplify the process. May I know if the java script actually already built in? Cos i dun see any website address in ur code..
Thanks for your help. Appreciate it.
Hi ABG, microbit have their own Bluetooth extension which I m using. Therefore I can't apply any trick u share on the ClientBluetooth1 block..
Still thanks to ur offer of help.
The block you are running is called RunJavaScript and as input you provide some JavaScript. JavaScript has some handy functionality built-in to convert ASCII to UTF or whatever character set you have. So, what is your problem?
Now that I understand the game, here is the map/reduce version, generalized to all text, based on @Italo's ASCII conversion:
AsciiCHRASCprocedures.aia (4.4 KB)
you can use the following extension:
ConversionAsciiTexte.aix (9.3 KB)
here is a documentation of the extension
https://community.appinventor.mit.edu/t/extension-app-inventor-pour-donner-le-code-ascii-dun-caractere-et-inversement/80397