2X BLUNO BEETLE BLUETOOTH CONNECTION + WS2812B + DELAY

Hi!

I successfully connected two Bluno Beetle together wirelessly.
One have connected potentiometer
Second one have 80LEDS ws2812b strip (neopixel).
I'm on Arduino 1.8.1, Bluno Beetle's are updated.
I'm sending data from potentiometer to second Bluno to wirelessly change hue of the strip.
Everything works great if i have 4-5 LEDS but with 80 leds connected the Serial Buffer somehow gets filled and data sending becomes laggish.
The only think i found to solve this problem is to create delay on master Bluno but i would like the refreshment of the LEDS to be immediate. I do not know how to clear buffer or where i make an mistake?
Cannot solve this problem alone... Big thanks for help!!!

MASTER CODE

int sensorPin = 3; 

void setup()
{
Serial.begin(115200);

}

void loop()
{
int sensorValue = map(analogRead(sensorPin),0,1023,0,255);

Serial.write(sensorValue);

delay(350);
}

SLAVE CODE

#include "FastLED.h"

#define NUM_LEDS 80
#define CHIPSET WS2812B
#define COLOR_ORDER GRB
#define LED_PIN 5
#define MAX_BRIGHTNESS 165 // Thats full on, watch the power!
#define MIN_BRIGHTNESS 4
#define KOLOR_GORA Candle;

CRGB leds[NUM_LEDS];

void setup()
{
Serial.begin(115200);
FastLED.addLeds<CHIPSET, LED_PIN, COLOR_ORDER>(leds, NUM_LEDS).setCorrection( TypicalLEDStrip);
FastLED.setBrightness(MAX_BRIGHTNESS);
FastLED.setDither( 0 );
}

void loop()
{

if (Serial.available())
{

int inbyte = Serial.read();



Serial.println(inbyte);

if(inbyte > 0){

// FastLED.setBrightness(constrain(inbyte, MIN_BRIGHTNESS, MAX_BRIGHTNESS));
turn_hue(inbyte);

}
else {


turn_off();





}

//
}


}

int turn_hue(int x) {

for (int i=40; i > 0 ; --i){
leds[i].setHSV( x+i*0.5, 200, MAX_BRIGHTNESS);
FastLED.show();
leds[80-i].setHSV( x+i*0.5, 200, MAX_BRIGHTNESS);
FastLED.show();

}
}
void turn_off() {

for (int i=40; i > 0 ; --i){
leds[i]= CRGB(0,0,0);
FastLED.show();
leds[80-i]= CRGB(0,0,0);
FastLED.show();

}
}

any help with that?

int sensorValue = map(analogRead(sensorPin),0,1023,0,255);

Or

byte sensorValue = analogRead(sensorPin) / 4;
Serial.write(sensorValue);

Passing an int to a function that expects a byte is generally not a good idea. Making sensorValue the proper type (since all the values that it can hold fit in a byte) IS.

Comparing the current value to the last value sent, and only sending when there is a different value to send, is also a good idea. The sensor, whatever kind of generic sensor you have, will be more responsive, too, since the delay() can be relegated to the bit bucket.

int inbyte = Serial.read();

Stupid. Stupid. Stupid.

inbyte's type is NOT byte. If you KNOW (and you do) that there is data to read, use byte to hold the output.

But do NOT then use int or float of char in the damned name.

if(inbyte > 0){

Why? Why is 0 not a valid value? Why did you send it if it is not a valid value?

for (int i=40; i > 0 ; --i){
leds[i].setHSV( x+i*0.5, 200, MAX_BRIGHTNESS);
FastLED.show();
leds[80-i].setHSV( x+i*0.5, 200, MAX_BRIGHTNESS);
FastLED.show();

}

How long does this loop take to execute? How many bytes will have arrived in the serial buffer during that time?

Typically, one sets ALL the LEDs and then calls show().

Typically, one does NOT use magic numbers in for loops. 40? What the heck does that mean?