HELP! why the app only works with the first conditional

38 views
Skip to first unread message

AbiiSl

unread,
May 1, 2019, 6:22:46 PM5/1/19
to MIT App Inventor Forum
Hi there I need someone to help me out on this one, as you can see in the picture I have and if where its supposed to get a letter d then it will do a little work with the labels, it works just  fine  for the first If where it gets the letter d but it never works for the  letter c and the letter b, I have tried a few things like  add a new clock but it doesn't work and I'm getting frustrated so if anyone of you guys could help me id be thankful
Screen Shot 2019-05-01 at 5.12.31 PM.png

Chris Ward

unread,
May 1, 2019, 6:51:45 PM5/1/19
to MIT App Inventor Forum
Hello AbiiSl

What is sending the data? A microcontroller such as an Arduino? We need to see the Script/Sketch.

The comparison method you use in the Blocks is incorrect - read into a text variable and then use that for text comparison, and since you are not receiving all three values at once, you should read once only and then branch-off using If - Else.




Chris Ward

unread,
May 1, 2019, 7:06:32 PM5/1/19
to MIT App Inventor Forum
Blocks:

Blocks_BluetoothReceiveChar.png


AbiiSl

unread,
May 1, 2019, 7:30:54 PM5/1/19
to MIT App Inventor Forum
Yes its an Arduino I'm using a Bluetooth connection to send the data, as you can see in the picture, I have 3 ultrasonic Sensors every time they detect something each sensor send a character it could be an 'A' , 'B', or  'C' ,and could you explain the use of the delimiter please?
and so instead of having everything in the same place, I should use Procediments, right?
Screen Shot 2019-05-01 at 6.24.21 PM.png

Chris Ward

unread,
May 1, 2019, 7:47:47 PM5/1/19
to MIT App Inventor Forum
Hi

Attach your .ino file, not an image of a portion of it. I can then show how the delimiter works on the Arduino side.
 

Chris Ward

unread,
May 1, 2019, 7:54:28 PM5/1/19
to MIT App Inventor Forum
....concerning the App Inventor side, the main point of my code example is that you should read the data sent by Arduino, then see what you have got.

AbiiSl

unread,
May 1, 2019, 8:02:27 PM5/1/19
to MIT App Inventor Forum
there is the .ino file,  talking about the App inventor code why the first if that  I have works? 
Two_ultrasonic_sensors.ino

AbiiSl

unread,
May 1, 2019, 8:07:45 PM5/1/19
to MIT App Inventor Forum
 so, should  I try to use the blocks in the way you used it ?

Chris Ward

unread,
May 1, 2019, 8:15:15 PM5/1/19
to MIT App Inventor Forum
Yes :)

Chris Ward

unread,
May 1, 2019, 8:50:31 PM5/1/19
to MIT App Inventor Forum
The Sketch, it's from a tutorial? There are a things that could be better.

Currently, the Arduino could output any of 8 possible values  "a", "b", "c", "d", "n", "w", "x", "y", but your App Inventor Blocks are only checking for three.

I note that the Sketch is expecting to receive some data from the App - but are you going to send data from the App to the Arduino? If so, the order of the Sketch functions will need to change.

Arduino Send must be slower than App Receive, to prevent the data overwriting itself. Therefore, the delay values in the Sketch should, for now, be increased from 400 to 1000. If necessary, the delay can be tweaked by trial and error later - we just want to get it working at this stage.

After each Serial.print(), follow with an "empty" Serial.println() - This is the Character 10 = Ascii LF = End Of Data that the App code is expecting

For example:

Serial.print("d");
Serial.println();
delay(1000);

Setup Clock 1 Timer in your Blocks:

SetTimer.png


When the App is Exited, tidy-up:


ExitApp.png







AbiiSl

unread,
May 1, 2019, 10:25:41 PM5/1/19
to mitappinv...@googlegroups.com
well actually the picture i have here only shows three sensors but I have four,  and I assigned a character to each sensor so in the given case they detect something they are either going to send a character lets say "A" or keep waiting for the right character so I decided to use an IF to find the A once it finds it it will change the labels I have and that's how all the sensors and app are supposed to work , Im going to use the blocks the same way you showed me first I hope it works Thank you so much!

Chris Ward

unread,
May 2, 2019, 5:12:15 AM5/2/19
to MIT App Inventor Forum
Hi

If you were working with all 8 values in the App, we would possibly need an even more efficient method to process them. All depends on what your Project actually does :)
Reply all
Reply to author
Forward
0 new messages