I am unable to change Button color according to signal recieved from the Arduino

image
image


based on the click it changes to red but it doesn't change into green or the initial color by comparing the text

Hi

Too many errors to correct your Clock1 Block - I will write a new one for you. Please upload your Project file (.aia)

Export Project

Please do not private message the Power Users directly unless invited to.

  1. We are a small team collectively supporting thousands of Users
  2. The person messaged could be unavailable for days or weeks and the message left unread.
  3. By keeping the discussion on the forum, there are many people from all around the World (different time zones) who can potentially help you, not just the first responder, who may be unavailable. Plus, there is often something that many forum members can learn by reading the posts.

Be sure to use println() at the end of each message to send from the sending device, to signal end of message.

Only use print() in the middle of a message.

Be sure not to println() in the middle of a message, or you will break it into two short messages and mess up the item count after you split the message in AI2.

Do not rely on timing for this, which is unreliable.

In the AI2 Designer, set the Delimiter attribute of the BlueTooth Client component to 10 to recognize the End of Line character.
BlueToothClient1_Properties
Also, return data is not immediately available after sending a request,
you have to start a Clock Timer repeating and watch for its arrival in the Clock Timer event. The repeat rate of the Clock Timer should be faster than the transmission rate in the sending device, to not flood the AI2 buffers.

In your Clock Timer, you should check

  Is the BlueTooth Client still Connected?
  Is Bytes Available > 0?
     IF Bytes Available > 0 THEN
       set message var  to BT.ReceiveText(-1) 

This takes advantage of a special case in the ReceiveText block:

ReceiveText(numberOfBytes)
Receive text from the connected Bluetooth device. If numberOfBytes is less than 0, read until a delimiter byte value is received.

Only do one ReceiveText in the Timer, into a variable.
Use that variable for your if/then tests, instead of asking for more input from Bluetooth.

1 Like

Working on the Blocks of Screen5.

Not sure Why Button 'A' is in the Clock Timer?

Well, comparing words is not the best approach. Modify your Arduino code from "red" "green" "initial" to "1" "2" "3", so that the colours relate to a simple table in the App code:

ButtonColours

Then in the code we can use an "Any Button" Block instead of 8 almost identical Button Blocks.

I haven't checked your entire Project - you have a lot of Screens - it's best to use the absolute minimum necessary. Having used 10 screens, you have hit the maximum. Search this Forum for "switching screens" to ensure your code does so safely, else your App will simply crash after a while.

Your naming of components etc could be better - it is difficult to follow your code :upside_down_face: Most importantly, do not remove the identifier. "A" should be "Button_A", "Connect" should be "ListPicker_Connect" etc. All those unnamed Labels will catch you out later too. Finally, keep an eye on the Show Warnings panel - keep the values at 0-0!

Versabot_1236_edit01.aia removed, see below.

It maybe the case that trying to receive data just after sending data is too soon - if so, the receiving data block should be in a Clock Timer Block:

Versabot_1236_edit02.aia (3.9 MB)

If you would like me to check your Arduino Sketch, upload the .ino file.

All of your images except the app icon need to be optimised for Android. They are part of the reason the Project loads slowly. Large compressed images can crash your phone on App Launch.

See:
https://www.professorcad.co.uk/appinventortips#TipsImages