how to apply if statement on a 0|0|0|0 string data statement in ai2

26 views
Skip to first unread message

Abdullah Alvi

unread,
Apr 5, 2019, 1:21:25 AM4/5/19
to MIT App Inventor Forum
my string values are shown in this format 0|0|0|0 i want to perform this operation



if (ValueOfString >= 366 || ValueOfString <= 5) 

this it show a msg

 

Serial.print("Out of Range");

 i using four ultrasonic distance sensor and there values are shown in  0|0|0|0 this format

Capture.PNG
Capture.PNG

BodyMindPower

unread,
Apr 5, 2019, 2:31:22 AM4/5/19
to MIT App Inventor Forum
What are the variables status, status2, ... which are not used here and what should be done exactly? What should be the displayed result (q│x│y│z) and from where those get their values?

Anke

Ghica

unread,
Apr 5, 2019, 4:42:36 AM4/5/19
to MIT App Inventor Forum
Post your .ino file.
And, there is some really strange coding here: you are looking at the width (in pixels) of lblFront. What is that supposed to mean? How would that be determined? You could have its width set to automatic, but still, its font size would be a factor in the width, not just the length of your text.

What is the value of 0|0|0|0 ?

And, use ABG's delimiter advice:
Delimiter advice:

Use println() to separate messages when you transmit.
Set Delimiter = 10 in BlueTooth Designer.
Check for Bytes Available > 0 in blocks,
but then request -1 bytes to get only full  messages.

Cheers, Ghica.

Abdullah Alvi

unread,
Apr 5, 2019, 5:48:44 AM4/5/19
to MIT App Inventor Forum
these values are from ultrasonic sensors u can check my attachments 
trythisAPP1_1.aia
frd.ino

Abdullah Alvi

unread,
Apr 5, 2019, 5:53:25 AM4/5/19
to MIT App Inventor Forum
these value are coming from ultrasonic sensor and when i used Text it was showing error and when i used Width the error has gone i want that the values which are coming from the sensor are in this form like 10|20|30|40 , i want that if any one of these sensor value is between ValueOfString >= 366 || ValueOfString <= 5, it show some text "Out of Range"
my ino and aia files are attached.
trythisAPP1_1.aia
frd.ino

TimAI2

unread,
Apr 5, 2019, 6:30:56 AM4/5/19
to MIT App Inventor Forum
Something like this:

BLOCKS

blocksoutofrange.png



SCREEN

screenoutofrange.png


Chris Ward

unread,
Apr 5, 2019, 7:42:14 AM4/5/19
to MIT App Inventor Forum

Chris Ward

unread,
Apr 5, 2019, 7:56:27 AM4/5/19
to MIT App Inventor Forum
...it is the same project!

If you need the "out of range" message to show for every sensor (direction), you just have to copy - paste the blocks I defined for the front value!

However your "trythisAPP1_1" has undone a lot of best practice that I wrote in for you and dumps the result string into one label........ horse to water.

Big question: Does the app now receive the data via your HC-05?


Chris Ward

unread,
Apr 5, 2019, 8:01:14 AM4/5/19
to MIT App Inventor Forum
Other Power Users, 

Please see the previous forum post Ultrasonic_Dist.aia and Ultrasonic.ino files that I defined.

Abdullah Alvi

unread,
Apr 5, 2019, 8:02:25 AM4/5/19
to MIT App Inventor Forum
yes its showing values in ai2, file that i have uploaded,
but unfortunately, it was not showing in your app :( 

Abdullah Alvi

unread,
Apr 5, 2019, 8:04:24 AM4/5/19
to MIT App Inventor Forum
brother , it tried your code again and again but it was not working :(
so i tried to do it in my self now its showing values in w|x|y|z format but i just want to perform the if else on these w|x|y|z values

TimAI2

unread,
Apr 5, 2019, 8:15:48 AM4/5/19
to MIT App Inventor Forum
Which is what my example blocks do for you...

Chris Ward

unread,
Apr 5, 2019, 10:52:38 AM4/5/19
to MIT App Inventor Forum
Right.

Firstly, the App Inventor code should work fine, it is working fine for other Users, and the format was already val|val|val|val - changing the variable name does not affect the receipt of the data nor the processing of it.

Secondly, my code already does perform an if-else on the front values which you can copy-paste for the other 3 values. 

When you say you tried my code - did you try the file or did you copy bits of my code and add it to your original file? I ask because your current effort still contains mistakes that my file corrected. There is also a couple of new mistakes in the .ino file now.

I think I have done all I can to help you.


Abdullah Alvi

unread,
Apr 5, 2019, 10:57:00 AM4/5/19
to MIT App Inventor Forum
thanks Dear :)
really appreciated,
May God bless you <3 

Abdullah Alvi

unread,
Apr 5, 2019, 11:00:05 AM4/5/19
to MIT App Inventor Forum
Hi what block of this code, exactly do ?
like is it hard coded value ? or coming from sensors ? 
Capture.PNG

TimAI2

unread,
Apr 5, 2019, 11:12:13 AM4/5/19
to MIT App Inventor Forum
um, this represents the data coming back from the arduino, as you indicated it came back
(because I do not have the hardware to replicate)
Reply all
Reply to author
Forward
0 new messages