Fading led light with button

Hello all,

I have a problem and i cant find the fix for it, so i ask you guys.

the project in short is a two channel LED-lamp, the LDD drivers get a PWM-signal from a WEMOS D1 mini. The idea is to have a button in the Blynk app that switches the lamp on, and the lamps ramp up and give a sunrise effect, and switching the button to off should give a sunset.
the maximum level for each channel is determined with a slider. the good news is that those work perfectly.
The bad news, i cant get the lamps to ramp up. if switch the button to on, I get a 1 in the monitor, but the brightness stays 0. where did I screw up, I tried different options but it never seemed to work

so please help?

the code:

// this sketch is supposed to control 2 Meanwell LDD LED drivers trough a PWM signal. 
// it uses Blynk for maximal levels and to switch it on and of.

#define BLYNK_PRINT Serial

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


// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = 


int maxPWM0 = 0; // variable for max PWM value attached to BLYNK Virtual pin.
int maxPWM1 = 0; // variable for max PWM value attached to BLYNK Virtual pin.

int ledpercent0 = 0;
int ledpercent1 = 0;

int button = 0;
int brightness0 = 0;
int brightness1 = 0;


// Pins connected to de drivers:
#define led0 5 //D1 (2700K + HyperRed)
#define led1 4 //D2 (6500K)

BlynkTimer timer;

// get maximum light levels from app.

BLYNK_WRITE(V0) {// slider widget to set the maximum led level from the Blynk App.
  ledpercent0 = param.asInt();// channel 0
  Serial.print (" LEDs 2700K & Hyperred branden op maximaal:"); // for control
  Serial.println (ledpercent0);
  Serial.print ("%");
  
  maxPWM0= map(ledpercent0, 0, 1000, 0, 1023);
}

BLYNK_WRITE(V1) {// slider widget to set the maximum led level from the Blynk App.
  ledpercent1 =  param.asInt();// channel 1
  Serial.print (" LEDs 6500K branden op maximaal:"); // for control 
  Serial.println (ledpercent1);
  Serial.print ("%");

  maxPWM1 = map(ledpercent1, 0, 100, 0, 1023);
}

// get stat of on/off button form app and ramp up/down leds accordingly
BLYNK_WRITE(V2) { // button widget to switch lights on or off, 
  button = param.asInt();// either 0/lOW or 1/HIGH
   Serial.print ("lights are");
   Serial.println (button);
   Serial.print ("1 is on, 0 is off");
}

void light (){
  if(button == 1){
    if (brightness0 << maxPWM0){
    brightness0++;
    analogWrite (led0, brightness0);
     Serial.println (brightness0);
    }
    if (brightness0 >= maxPWM0 && brightness1 << maxPWM1){
    brightness0 = maxPWM0;
    brightness1++; 
    analogWrite (led0, brightness0);
    analogWrite (led1, brightness1);
    Serial.println (brightness0);
    Serial.println (brightness1);
    }
    if (brightness0 >= maxPWM0 && brightness1 >=maxPWM1){
    brightness0 = maxPWM0;
    brightness1 = maxPWM1;
    analogWrite (led0, brightness0);
    analogWrite (led1, brightness1);
    Serial.println (brightness0);
    Serial.println (brightness1);
    }
  }

   if(button == 0)
   if (brightness1 >> 0){
    brightness1--;
    analogWrite (led1, brightness1);
    Serial.println (brightness1);
    }
    if (brightness1 <= 0 && brightness0 >> 0){
    brightness1 =0;
    brightness0--; 
    analogWrite (led0, brightness0);
    analogWrite (led1, brightness1);
    Serial.println (brightness0);
    Serial.println (brightness1);
    }
    if (brightness0 <= 0 && brightness1 <= 0){
    brightness0 = 0;
    brightness1 = 0;
    analogWrite (led0, brightness0);
    analogWrite (led1, brightness1);
    Serial.println (brightness0);
    Serial.println (brightness1);
    }
}

void setup() {
  // put your setup code here, to run once:

Serial.begin(115200);
Blynk.begin(auth, ssid, pass);
timer.setInterval(1000L, light);

analogWrite (led0, brightness0);
analogWrite (led1, brightness1);
}

void loop() {
  // put your main code here, to run repeatedly:
Blynk.run();
timer.run();
}
[/code]

The double “less than” and “greater than” symbols (<< and >>) almost certainly aren’t what you intend to use. These are bitshift operators and almost certainly don’t make any sense when used in an if comparison like this.

You should replace them with < and >

Also, this map command looks a bit odd:

whereas this one looks much more sensible:

Pete.

Thank you! I’m not good in writing code… (but I’ll get better on day)

changed that, and also added lots of serial print commands and found that I missed a {.
things are improving. the sunrise is going fine, however if I switch the button to off serial monitor still says the button state is 1, so sunset does not start…

// this sketch is supposed to control 2 Meanwell LDD LED drivers trough a PWM signal. 
// it uses Blynk to get start and stop time and maximal levels.

#define BLYNK_PRINT Serial

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


// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = ";

// Your WiFi credentials. Set password to "" for open networks.
char ssid[] = "


int maxPWM0 = 0; // variable for max PWM value attached to BLYNK Virtual pin.
int maxPWM1 = 0; // variable for max PWM value attached to BLYNK Virtual pin.

int ledpercent0 = 0;
int ledpercent1 = 0;

int button = 0;
int brightness0 = 0;
int brightness1 = 0;


// Pins connected to de drivers:
#define led0 5 //D1 (2700K + HyperRed)
#define led1 4 //D2 (6500K)

BlynkTimer timer;

// get maximum light levels from app.

BLYNK_WRITE(V0) {// slider widget to set the maximum led level from the Blynk App.
  ledpercent0 = param.asInt();// channel 0
  Serial.print (" LEDs 2700K & Hyperred branden op maximaal:"); // for control
  Serial.println (ledpercent0);
  Serial.print ("%");
  
  maxPWM0= map(ledpercent0, 0, 100, 0, 1023);
}

BLYNK_WRITE(V1) {// slider widget to set the maximum led level from the Blynk App.
  ledpercent1 =  param.asInt();// channel 1
  Serial.print (" LEDs 6500K branden op maximaal:"); // for control 
  Serial.println (ledpercent1);
  Serial.print ("%");

  maxPWM1 = map(ledpercent1, 0, 100, 0, 1023);
}

// get stat of on/off button form app and ramp up/down leds accordingly
BLYNK_WRITE(V2) { // button widget to switch lights on or off, 
  button = param.asInt();// either 0/lOW or 1/HIGH
   Serial.print ("lights are");
   Serial.println (button);
   Serial.print ("1 is on, 0 is off");
}

void setup() {
  // put your setup code here, to run once:

Serial.begin(115200);
Blynk.begin(auth, ssid, pass);
timer.setInterval(1000L, light);

analogWrite (led0, brightness0);
analogWrite (led1, brightness1);
}

void loop() {
  // put your main code here, to run repeatedly:
Blynk.run();
timer.run();
}

void light (){
  if(button == 1){
    Serial.print("button status is");
    Serial.println (button);
    Serial.print (" maxPWM0 is: ");
    Serial.println (maxPWM0);
    Serial.print (" maxPWM1 is: ");
    Serial.println (maxPWM1);
    if (brightness0 < maxPWM0){
    brightness0 = brightness0 + 1;
    analogWrite (led0, brightness0);
    Serial.print ("Brightness 0 is: ");
    Serial.println (brightness0);
    }
    if (brightness0 >= maxPWM0 && brightness1 < maxPWM1){
    brightness0 = maxPWM0;
    brightness1++; 
    analogWrite (led0, brightness0);
    analogWrite (led1, brightness1);
    Serial.print ("Brightness 0 is: ");
    Serial.println (brightness0);
    Serial.print ("Brightness 1 is: ");
    Serial.println (brightness1);
    }
    if (brightness0 >= maxPWM0 && brightness1 >=maxPWM1){
    brightness0 = maxPWM0;
    brightness1 = maxPWM1;
    analogWrite (led0, brightness0);
    analogWrite (led1, brightness1);
    Serial.print ("Brightness 0 is: ");
    Serial.println (brightness0);
    Serial.print ("Brightness 1 is: ");
    Serial.println (brightness1);
    }
  }

   if(button == 0){
    Serial.print("Button status is ");
    Serial.println (button);
    Serial.print("something goes wrong");
    Serial.print (" maxPWM0 is: ");
    Serial.println (maxPWM0);
    Serial.print (" maxPWM1 is: ");
    Serial.println (maxPWM1);
   if (brightness1 > 0){
    brightness1--;
    analogWrite (led1, brightness1);
    Serial.print ("Brightness 1 is: ");
    Serial.println (brightness1);
    }
    if (brightness1 <= 0 && brightness0 > 0){
    brightness1 =0;
    brightness0--; 
    analogWrite (led0, brightness0);
    analogWrite (led1, brightness1);
    Serial.print ("Brightness 0 is: ");
    Serial.println (brightness0);
    Serial.print ("Brightness 1 is: ");
    Serial.println (brightness1);
    }
    if (brightness0 <= 0 && brightness1 <= 0){
    brightness0 = 0;
    brightness1 = 0;
    analogWrite (led0, brightness0);
    analogWrite (led1, brightness1);
    Serial.print ("Brightness 0 is: ");
    Serial.println (brightness0);
    Serial.print ("Brightness 1 is: ");
    Serial.println (brightness1);
    }
   }
}

found it, fixed it, works fine.

thnx again!