Not that easy in my case. I have a Aquarium light where there are 4 inputs. I am using an Adafruit 16Channel PWM driver with the frequency set at 1500 hertz
1/ Time when light come on and when light goes off.
2/ Time in seconds for fade up
3/ Time in seconds for fade down
4/ Max intensity of the LED
Code of the LED function
void SetLed(int fpin, //Master channel pin
int fpin2, //Slave channel pin
unsigned long ftime, //Current time in millis
unsigned long fstart, //Start time of LED channel
unsigned long ffadeup, //Fadeup period in millis
unsigned long fperiod, //Total photo period
unsigned long ffadedown, //Fadedown period in millis
unsigned long fstop, //Stop time of LED channel
float fpwm, //Max value of brightness
int Vpin) //Progress bar pin
{
//ON PERIOD//
if (ftime > fstart + ffadeup && ftime <= fstart + fperiod - ffadedown)
{
pwm.setPin(fpin, fpwm, false);
pwm.setPin(fpin2, fpwm, false);
progress = round((fpwm*100)/4096);
Blynk.virtualWrite (Vpin, progress);
}
//FADEUP PERIOD//
else if (ftime > fstart && ftime <= fstart + ffadeup)
{
brightness = map(ftime - fstart, 0, ffadeup, 0, fpwm);
pwm.setPin(fpin, brightness, false);
pwm.setPin(fpin2, brightness, false);
progress = round((fpwm*100)/4096);
Blynk.virtualWrite (Vpin, progress);
}
//FADEDOWN PERIOD//
else if (ftime > fstart + fperiod - ffadedown && ftime <= fstart + fperiod)
{
brightness = map(ftime - fstart - fperiod + ffadedown, 0, ffadedown, fpwm, 0);
pwm.setPin(fpin, brightness, false);
pwm.setPin(fpin2, brightness, false);
progress = round((fpwm*100)/4096);
Blynk.virtualWrite (Vpin, progress);
}
//OFF PERIOD//
else if (ftime > fstop || ftime < fstart)
{
pwm.setPin(fpin, 0, false);
pwm.setPin(fpin2, 0, false);
Blynk.virtualWrite(Vpin, 0);
}
}
It works OK except as expected at low levels the LED will dim to a point then just switch off. How could I incorporate the look up table into my code above?