I'm trying to create an app to change the color and brightness of a neopixel strip, via Bluetooth. I used a canvas and a ball to create a color wheel, and a slider for brightness, every time I drag the ball I change the RGB values.
I write the values in some Labels and then send the text written in them as a string to Arduino.
The problem is that when dragging the ball on the canvas, or dragging the slider, this happens in Arduino:
I can put a trailing separator for the data and only read the first or last block of values, but I want to change the state of the neopixel strip in parallel (or a sort of) with the change of the canvas or slider.
For now, I'm just trying to see that the data is received correctly, I haven't added anything about the neopixels yet.
#include <SoftwareSerial.h>
String mainString;
SoftwareSerial mySerial(10, 11); // RX, TX
void setup() {
Serial.begin(9600);
mySerial.begin(38400);
}
void loop() {
if(mySerial.available()) {
mainString = mySerial.readString();
Serial.println(mainString);
byte firstIndex = mainString.indexOf('+');
byte secondIndex = mainString.indexOf('+',firstIndex + 1);
byte thirdIndex = mainString.indexOf('+',secondIndex + 1);
byte fourthdIndex = mainString.indexOf('+',thirdIndex + 1);
String RED = mainString.substring(0,firstIndex);
String GREEN = mainString.substring(firstIndex + 1, secondIndex);
String BLUE = mainString.substring(secondIndex + 1, thirdIndex);
String LIGHT = mainString.substring(thirdIndex + 1, fourthdIndex);
String MODE = mainString.substring(fourthdIndex + 1);
int r = RED.toInt();
int g = GREEN.toInt();
int b = BLUE.toInt();
int l = LIGHT.toInt();
int m = MODE.toInt();
}
}