Hi,
I programmed my own Android app to control my neopixels. I have installed a HC-05 Bluetooth module to receive the data that I send from the app.
What works?
The connection is established, data can be sent.
What does not work?
RGB color data are not displayed correctly, although I saw via the serial monitor that the respective values were received.
Java code of the app:
void SendRGB() {
if (btSocket != null) {
//sendSignal("" + (65536 * red.getProgress() + 256 * green.getProgress() + blue.getProgress()));
String redValue = String.format("%03d", red.getProgress());
String greenValue = String.format("%03d", green.getProgress());
String blueValue = String.format("%03d", blue.getProgress());
String signal = redValue + greenValue + blueValue;
sendSignal("s" + signal);
}
}
This code takes 3 values from the respective red, green and blue regulator in my app. Its values are between 0 and 255. What is finally sent looks like this:
Example:
Red: 100
Green: 1
Blue: 40
signal = 100001040
sendSignal = s100001040
Arduino Code: (Comments are made for you in the code)
#include <Adafruit_NeoPixel.h>
#include <SoftwareSerial.h>
int LED_COUNT = 5;//60;
int redValue = 0;
int greenValue = 0;
int blueValue = 0;
bool power = true;
Adafruit_NeoPixel strip(LED_COUNT, 6, NEO_GRB + NEO_KHZ800);
void setup() {
//Serial.begin(38400);
Serial.begin(9600);
//strip.fill(strip.Color(255, 255, 255), 0, LED_COUNT);
strip.begin();
}
void loop(){
char received[10];
if (Serial.available() > 0) {
int i = 0;
while (Serial.available() > 0) {
received[i] = Serial.read();
Serial.write(received[i]); //<-------- This is a proof for me that it receives the data correctly. I've seen it in the Serial Monitor
i++;
}
if (received[0] == 's') { //<-------- This if statement works also fine, because if I click the send button in my App it shows a color but not the color that would show when I mix those 3 values.
redValue = (received[1] << 16) + (received[2] << 8) + received[3]; //<------- Bit shifting here to get (like the example) 100 from single chars (1 0 0)
greenValue = (received[4] << 16) + (received[5] << 8) + received[6]; //<------- Here doing the same
blueValue = (received[7] << 16) + (received[8] << 8) + received[9]; //<------- and here also
strip.fill(strip.Color(redValue, greenValue, blueValue), 0, LED_COUNT);
}
strip.show();
}
}
In my opinion completely understandable, but it doesn't work. I have already tried a direct 32bit color integer. Unfortunately, that didn't work either ...
Thank you in advance for your suggestions.
Regards,
Colin
