I want to be able to control multiple LED strip via bluetooth with one arduino. I coded my own android app and everything work fine with one or two led strip with few pixel. But as soon as I had to many pixel data send by BT is missing a few byte (ex "colfff5dff" instead of "color fff5dff"). It doen't happen every time but it's unrealiable. I feel like sending data to the led strip take so many time that it skip some letter.
I'm ussing dsd tech hc-05 with an arduino UNO R3 and a esp8266 led strip.
#include <Adafruit_NeoPixel.h>
#include <SoftwareSerial.h>
#ifdef __AVR__
#include <avr/power.h>
#endif
//SoftwareSerial blueTooth(13,12);
#define PIN 5
#define SIZE 200
#define BRIGHTNESS 200
enum MODE {FIXED, LOOP_RGB, RUNNING, RAINBOW};
enum MODE mode = FIXED;
Adafruit_NeoPixel strip(SIZE, PIN, NEO_RGB + NEO_KHZ800);
int lastTime;
uint32_t color;
char Incoming_value = 0;
char bufferStr[100];
int bufferIndex = 0;
void setup() {
Serial.begin(9600); //open the serial port
Serial.setTimeout(10);
strip.begin();
strip.show();
strip.setBrightness(50);
color = Adafruit_NeoPixel::Color(0, 255 ,0 );
}
void loop() {
if(Serial.available() > 0)
{
String s = Serial.readString();
Serial.print(s);
//I've tried some other way like read(); readString(); readBytes(); readBytesUntil();
/*
* ---- not needed for the issue
*/
}
switch (mode){
case FIXED : fixedMode(); break;
case RUNNING : runningLights(); break;
case RAINBOW : rainbow(); break;
}
showAll();
}
void parseBlueTooth(){
//---- not needed for the issue
}
void fixedMode(){
setAll(color);
showAll();
}
void rainbow(){
//---- not needed for the issue
}
void runningLights() {
//---- not needed for the issue
}
void setAll(byte r, byte g, byte b) {
setAll(Adafruit_NeoPixel::Color(r,g,b));
}
void setAll(uint32_t color) {
strip.fill(color, 0, SIZE);
}
void showAll(){
long curTime = millis();
if(curTime - lastTime >16){
if(strip.canShow()) {
strip.show();
}
lastTime = curTime;
}
}