Can anybody help me with my arduino and android programming issue?

I have created an arduino gadget that I control via an app on my android phone that was made in app creator.

the "gadget" is an RGB LED that has the RGB levels controlled by red, green and blue up and down arrows.

they communicate via a serial bluetooth adapter, the app sends a letter via bluetooth "A", "a" etc... and the arduino reads them like so:

if (Serial.available() > 0)
incomingByte = Serial.read();
char character = char(incomingByte);
  if (character == 'A')
   redLevel += 20;

and then the R, G and B levels are written using analogWrite. It works but it is not great.

my issues are as follows:

to change a colour level, red for example, I have to tap the red arrow multiple times, basically just sending the serial character over and over to change the analog level by 20 each time. Is there a way to do this where I can hold down the button and the level will fade? I am pretty sure this has to do with the android app rather than the arduino sketch but I could be wrong...

Also, the analog level cycles, that is to say that when the colour is at it's brightest level, pressing the UP arrow again turns that colour off or if not off back to the lower end of the analog values. I am pretty sure this particular issue is in the arduino code. what can I put in my code that keeps the level at 255 if going up and 0 if going down?

any help appreciated and I will give credit where credit is due when I end up turning this into an instructable.
Thank you very much.

bwrussell4 years ago
Not sure what app creator you are talking about but from my experiance with the MIT app inventor (formerly Google app inventor) you have two options with buttons, short click and long click. You could set the long click in the app to send a different command which the arduino code used to slowly fade the color on or off until you long clicked again, or just for a certain amount.

As far as the color values cycling you could put in a check that says:
if redvalue + 20 is > 255 then set redvalue to 255
and of course that can be adapted for the lower limit as well.

Just a suggestion to clean up the code a little, if you want, everyone's coding styles are different. Instead of sending a character which you have to spend an extra line decoding just send a number from the app and write it directly as a byte data type. Again, it doesn't really matter but it means you don't have to mess around with char's which can be ornery at times.