Sending numerical values via bluetooth HC05

Hi,

I have a ball on a canvas that I can drag around from y = 0 to y = 540. I want to send these number to my arduino via HC05 module, then map it to a PWM (0-255) signal. Since 540 won't fit in one byte, I sent it to my arduino by means of 2 bytes. However this resulted in the arduino serial splitting the two bytes as (00001110) 14 and (000000001) 1. Is there anyway I can send or receive the whole number (540 (00000000100001110)).

Thanks

In the Bluetooth settings in AppInventor, select HighByteFirst. You will then receive them in the correct sequence.

Got it, but how do I get the whole number?

Is your Arduino Sketch expecting Integers?

.......you can send a bytes list, or even text. It all depends on how the Sketch is defined.

Another question - how are you mapping a range of 0 - 540 to a range of 0 - 255? Wouldn't it be easier if the canvas range was 0 - 510 (or even 0 - 255) ?

I don't have an Arduino to hand for testing, but try this snippet:

BluetoothSendPwmVal.aia (2.8 KB)

Everything OK now Potter_Rocks?

It works, but my project involves a ball on a canvas. I modified your code to work with the ball and canvas, but how would I send a value larger than 1 byte using the Send a list of bytes method?

You need to create a variable that is a list. You must add all your bytes to this list. Each byte must be an entry in the list.

I would look for a Send a list of Integers method.

Integers are longer than bytes, although that name is highly presumptuous, presuming to be able to hold an infinite number of bits or intentionally vague, not giving you any hint as to actual size in bits (at least 16?)

As I have done - a List of one value.

Edit: May I ask why a Canvas and Ball Sprite is favoured over the Slider Component? You are only sending values for one direction?

I used the ball and canvas method because I wanted to style the app to look more personalized, that is the only reason, and yes I'm only getting the values of the Y direction.

wouldn't that cause my Arduino code to read the integer as two different bytes, and therefore two different integers.

It doesn't work for an integer larger than 255, how would I send, say 510?

... you already said that the Pulse-width modulation range was 0-255?

.... but the single value list method should still work - edit my project and try it.

Yes, I intend to use the 0-510 range for direction and speed control in my Arduino code. I'm going to subtract 255 from the input from my app; the middle value of the range 0-510 would be 255 and that would be converted to 0 because I want the PWM output to be 0 when the ball is in the center...
Here's my app inventor code and screen:

Hope that helps

Did this fail? I see you have incorporated it into your custom code. I don't quit get your description - do you mean the App will also send negative integers (0 to -255)?

I can see a potential App lock-up where you send a Value on drag and then send again on touch-up. Ideally, the only send would be on touch-up.

Is the App only for your own personal use?

Yeah the app is for myself only, and the touch up doesn't interfere.
No, just values from 0-510