Brightness controll

Hi all,

I am having some problems with my code. I am trying to make a RGB led controller with brightness control. I have managed to change the brightness of each colour individual. But I can’t get the master brightness control (a slider (V0)) to work. Any help would be great.

NodeMCU
Android app


#define BLYNK_PRINT Serial

#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>

char auth[] = "**********";
char ssid[] = "**********";
char pass[] = "**********";

int Red = 5;
int Green = 4;
int Blue = 0;

int BrightData;
int RedData;
int GreenData;
int BlueData;

void setup()
{
  Serial.begin(9600);
  Blynk.begin(auth, ssid, pass);

  pinMode(Red, OUTPUT);
  pinMode(Green, OUTPUT);
  pinMode(Blue, OUTPUT);
}

BLYNK_WRITE(V0) //Brightness 
{
  int BrightData = param.asInt();
}
BLYNK_WRITE(V1) //Red
{
  int RedData = param.asInt();
  analogWrite(Red, RedData);
   
}
BLYNK_WRITE(V2) //Green
{
  int GreenData = param.asInt();
  analogWrite(Green, GreenData);  
}
BLYNK_WRITE(V3) //Blue
{
  int BlueData = param.asInt();
  analogWrite(Blue, BlueData); 
}


void loop()
{
  Blynk.run();
}

This is more a “How to program” then a “How to use Blynk” issue… but…

Probably because your brightness function does nothing but apply a value to a variable that is never used elsewhere in your code.

First, use only global variables, do not reinitialize same variables as local ones.

Second, take your “master” value and mathematically apply it to your individual values. EG brightness of colour = value - mastervalue.

This is untested… I don’t care for doing math in my head, nor spending time writing others code :stuck_out_tongue: but you may need to also compensate for negative values prior to your analogWrite() commands, so test and figure it out on your end.