WS2812 dimming control truoble with bluetooth

hi im looking for some help with bluetooth and fast led library. I have been trying to get my head around brightness control for the last few day with an arduino uno, hc-05 bluetooth module, the fast led library and im using bluetooth electronics app. I can turn on and off the ws2812 and other simple things but cant get brightness slider to work when i try to use the slider in the app it just reset the ws2812 off state. i tryed a premade sketch by the bluethooth app and the brightness controled work with the ws2812 but the premade skecth is not using the fast led library

#include <FastLED.h>
    #define NUM_LEDS 5
    #define DATA_PIN 8
    #define LED_TYPE WS2812B
    #define COLOR_ORDER GRB
    #define MAX_BRIGHTNESS 155
    #define MIN_BRIGHTNESS 32 
    
    char state;
    int max_bright;
    
    CRGB leds[NUM_LEDS];

   void setup() { 
     FastLED.addLeds<LED_TYPE,DATA_PIN,COLOR_ORDER>(leds, NUM_LEDS).setCorrection(TypicalLEDStrip);
     Serial.begin(9600);
   }

   void loop() {

 if(Serial.available() >0){
    state = Serial.read();
    if(state=='A');
    if(state=='a');
    if(state=='B');
    if(state=='b');
    if(state=='N');
    if(state=='n');
    if(state=='R') max_bright-Serial.parseInt();
    int max_bright = map(analogRead(state), 0, 500, 0, 255);
   FastLED.setBrightness(constrain(max_bright, MIN_BRIGHTNESS, MAX_BRIGHTNESS));
 

 }
      if(state=='a') 
      {
      leds[0] = CRGB( 50, 100, 150);
      leds[1] = CRGB( 176, 244, 66);
      leds[2] = CRGB( 146, 61, 153);
      leds[3] = CRGB( 214, 42, 82);
      leds[4] = CRGB( 193, 142, 32);
      FastLED.show();
      }

      if(state=='b')
      for(int dot = 0; dot < NUM_LEDS; dot++) { 
            leds[dot] = CRGB::Red;
            FastLED.show();
            // clear this led for the next time around the loop
            leds[dot] = CRGB::Blue;
            delay(70);
      }
      
      if (state=='B');
      for(int dot = 0; dot < NUM_LEDS; dot++){
      leds[dot] = CRGB::Black;
      FastLED.show();
    }
    
    }

I don’t understand your code as it is now. If you use a BT module such as HC-05, you should also use SoftwareSerial library, which would enable you to make another ‘virtual’ serial port for bluetooth communication. For example :

#include <SoftwareSerial.h>
SoftwareSerial BTserial(2, 3); // RX | TX

I used the same Android app as you (Bluetooth electronics) and had the sliders work with no problem. Here is what I did :

First initialize the new serial in the setup :

  BTserial.begin(115200);

Then read the serial port in the loop:

  //Process any info coming from the bluetooth serial link
  // if serial data available, process it
  while (BTserial.available () > 0)
    processIncomingByte (BTserial.read ());

The function processIncomingByte is:

void processIncomingByte (const byte inByte)
{
  switch (inByte)
  {
    case '*':   // endmarker
      process_data ();
      receivedNumber = 0;
      break;

    case '0' ... '9':
      receivedNumber *= 10;
      receivedNumber += inByte - '0';
      break;

    default:
      command = inByte;
      receivedNumber = 0;
      break;
  }
}

It assumes that all the bluetooth electronics devices are defined with :

  • Starts with: one distinct letter for each (I used a U for a hue slider)
  • Ends with: *
    The slider uses “Send on slider release”, min 0 and max 255.

Then the process_data function is up to you: it is that function which makes what is expected depending on the command received through the BT liaison. In my case:

void process_data ()
{
  if (DEBUG) Serial << "Commande : " << command << " Valeur : " << receivedNumber << endl ;
  switch (command) {
    case 'N':
      minutes5 = 1;
      BTserial.write("*DMinutes ON \n*");
      break;
    case 'F':
      minutes5 = 0;
      BTserial.write("*DMinutes OFF\n*");
      break;
    case 'O':
      fond = 1;
      couleur_fond = CRGB(200, 200, 200);
      digitalWrite(LED_BUILTIN, HIGH);
      BTserial.write("*DFond ON \n*");
      break;
    case 'E':
      fond = 0;
      digitalWrite(LED_BUILTIN, LOW);
      BTserial.write("*DFond OFF\n*");
      break;
    case 'U':
      {
        numero_hue = receivedNumber;
        BTserial.print("*DCouleur : " + String(numero_hue) + "\n*");
        BTserial.print("*V" + String(numero_hue) + "*");
        CHSV coulHSV = CHSV(numero_hue, 255, 255);
        CRGB coulRGB;
        hsv2rgb_rainbow (coulHSV, coulRGB);
        byte r = coulRGB.red;
        byte g = coulRGB.green;
        byte b = coulRGB.blue;
        BTserial.print("*LR" + String(r) + "G" + String(g) + "B" + String(b) + "*");
      }
      break;
    case 'A':
      anim = receivedNumber;
      BTserial.print("*DAnimation : " + String(anim) + "\n*");
      BTserial.print("*B" + String(anim) + "*");
      break;
    case 'P':
      numero_pal = receivedNumber;
      BTserial.print("*DPalette : " + String(numero_pal) + "\n*");
      BTserial.print("*Q" + String(numero_pal) + "*");
      if (anim == BBR) {
        switch (numero_pal) {
          case 0:
            BTserial.write("*DDrapeau Francais\n*");
            break;
          case 1:
            BTserial.write("*DDrapeau Italien\n*");
            break;
          case 2:
            BTserial.write("*DDrapeau Bulgare\n*");
            break;
          case 3:
            BTserial.write("*DDrapeau Irlandais\n*");
            break;
          case 4:
            BTserial.write("*DDrapeau Roumain\n*");
            break;
        }
      }
      break;
    case 'H':
      heures = receivedNumber % 12;
      secondes = 0;
      BTserial.print("*DHeures : " + String(heures) + "\n*");
      break;
    case 'M':
      minutes = receivedNumber % 60;
      secondes = 0;
      BTserial.print("*DMinutes : " + String(minutes) + "\n*");
      break;
    case 'S':
      secondes = receivedNumber % 60;
      BTserial.print("*DSecondes : " + String(secondes) + "\n*");
      break;
    default:
      BTserial.print("*DCommande non reconnue : " + String(command) + "\n*");
      break;
  }
  delay(10);
}

I even sent texts to a terminal on the Bluetooth Electronics display, using the instructions BTserial.print and receive character ‘D’, the complete text must be between ‘*’.

how i have the bluetooth module connected to the arduino uno is on pin 0 and 1. have stayed away from software serial because i read that it can mess with some of the pins and i try up understand the last part code and what your saying is confusing me

i read that it can mess with some of the pins

You either read something that was wrong or misunderstood what you did read. It only messes with the two pins you designate.

ok thx Grumpy_mike for the info that great to know. but still stuck i have try to make sence lesept last chunk of code and get any thing out of it to help but nothing. im just ready to call it for this project sence its been all but week trying to get dam brightness to work and nothing.

kc101 : sorry, I just wanted to give a broad example of what can be done. From the last chunk of code you just need to use that part :

void process_data ()
{
  byte brightness = receivedNumber;
  FastLED.setBrightness(brightness );
  delay(10);
}

and declare byte receivedNumber = 0;before setup

I hope this helps...

thanks lesept for the help i typ the code at the end of the loop and my ws2812 just flicker on then going off. i also tryed it above the first if command and they just stayed off. im not sure where i have gone wrong with it in :neutral_face:. i have the app set like this Starts with R, Ends with r would this have any thing to do with the trouble. Just to make sure is there any thing i need to remove from my code and very big thx for help ironing this code out

Please post your code so I can try to see more easily what is going wrong (sorry about late answer due to time shift, I'm in France). I may not be able to help you because I'll leave for holidays tomorrow.

here is the up date code with what you side to put in and it understandable with time zone im just happy to have help learning what im doingwrong so then on the next project i know what to do thx to you lesept.
PS if you dont see this till after your holidays hope you had fun

    #include <FastLED.h>
    #define NUM_LEDS 5 //led count 
    #define DATA_PIN 8 // output to ws2812 date 
    #define LED_TYPE WS2812B
    #define COLOR_ORDER GRB
    #define MAX_BRIGHTNESS 155
    #define MIN_BRIGHTNESS 35 

    byte receivedNumber = 0;
    
    char state;
    int max_bright;
    
    CRGB leds[NUM_LEDS];

   void setup() { 
     FastLED.addLeds<LED_TYPE,DATA_PIN,COLOR_ORDER>(leds, NUM_LEDS).setCorrection(TypicalLEDStrip);
     Serial.begin(9600);
   }

   void loop() {

 if(Serial.available() >0){
    state = Serial.read();
     Serial.println(state);
    if(state=='A');
    if(state=='a');
    if(state=='O');
    if(state=='B');
    if(state=='b');
    if(state=='N');
    if(state=='M');
    if(state=='R') max_bright-Serial.parseInt();
    int max_bright =(analogRead(state=='R'), 0, 500, 0, 255);
    FastLED.setBrightness(constrain(max_bright, MIN_BRIGHTNESS, MAX_BRIGHTNESS));
 }

        void process_data ();
      {
        byte max_bright = receivedNumber;
        FastLED.setBrightness(max_bright);
        delay(10);    
      }
 
      if(state=='A')
      {
      leds[0] = CRGB( 50, 100, 150);
      leds[1] = CRGB( 176, 244, 66);
      leds[2] = CRGB( 146, 61, 153);
      leds[3] = CRGB( 214, 42, 82);
      leds[4] = CRGB( 193, 142, 32);
      FastLED.show(); 
      }

       if(state=='a') 
      {
      leds[0] = CRGB( 0, 0, 0);
      leds[1] = CRGB( 0, 0, 0);
      leds[2] = CRGB( 0, 0, 0);
      leds[3] = CRGB( 0, 0, 0);
      leds[4] = CRGB( 0, 0, 0);
      FastLED.show(); 
      }

      if(state=='b')
      for(int dot = 0; dot < NUM_LEDS; dot++) { 
            leds[dot] = CRGB::Red;
            FastLED.show();
            // clear this led for the next time around the loop
            leds[dot] = CRGB::Blue;
            delay(70);
      }

    if (state=='M')
    for(int i = 0; i < NUM_LEDS; i++){
    leds[i].r = 255; 
    leds[i].g = 68; 
    leds[i].b = 221;
    FastLED.show();
    }
    if (state=='N')
    for(int i = 0; i < NUM_LEDS; i++){
    leds[i].r = 34; 
    leds[i].g = 91; 
    leds[i].b = 183;
    FastLED.show();
    }
    if (state=='O')
    for(int i = 0; i < NUM_LEDS; i++){
    leds[i].r = 0; 
    leds[i].g = 0; 
    leds[i].b = 0;
    FastLED.show();
    }
    }

Hi kc101 if interested I uploaded a video controlling my VU-Meter Tower via Bluetooth with Brightness control. Nothing similar to your code but I think you can get the idea. Code in the video's description. Hope it helps! www.youtube.com/watch?v=xfU36Tv937I