Hehe I know, I noticed the comment after I posted.. I was too lazy and copied another function and then edited...
The backlight functions get called very often, more like always.. So when I serial.write from the raspberry the change is done "instantly"... The function works properly, it goes in to the "if" it needs to, maybe printing out the inByte will give a heads up! Thanks
Here is the code, without all the functions, since its a bit long:
/* ******************************************************************************************************************** */
/* * * */
/* * L O O P * */
/* * * */
/* ******************************************************************************************************************** */
void loop()
{
onesecond();
backlight();
relay1();
lcd.setCursor(0, 1);
lcd.print("Blue:");
lcd.setCursor(8, 1);
lcd.print("White:");
//discoverOneWireDevices();
/* ******************************************************************************************************************** */
/* * * */
/* * L O O P - D I M F U N C T I O N * */
/* * * */
/* ******************************************************************************************************************** */
byte second, minute, hour, dayOfWeek, dayOfMonth, month, year;
getDateDs1307(&second, &minute, &hour, &dayOfWeek, &dayOfMonth, &month, &year);
int daybyminute = ((hour * 60) + minute); //converts time of day to a single value in minutes
int bluerampup;
if (daybyminute >= (ontime*60))
bluerampup = (((ontime*60) + blueramptime) - daybyminute);
else
bluerampup = blueramptime;
int whiterampup;
if (daybyminute >= (ontime*60 + blueramptime))
whiterampup = (((ontime*60) + blueramptime + whiteramptime) - daybyminute);
else
whiterampup = whiteramptime;
int whiterampdown;
if (((ontime * 60) + photoperiod + blueramptime + whiteramptime) <= daybyminute)
whiterampdown = (((ontime*60) + photoperiod + blueramptime + 2*whiteramptime) - daybyminute);
else
whiterampdown = whiteramptime;
int bluerampdown;
if (((ontime * 60) + photoperiod + blueramptime + 2*whiteramptime) <= daybyminute)
bluerampdown = (((ontime*60) + photoperiod + 2*blueramptime + 2*whiteramptime) - daybyminute);
else
bluerampdown = blueramptime;
/* ******************************************************************************************************************** */
/* * * */
/* * L O O P - F A D E I N * */
/* * * */
/* ******************************************************************************************************************** */
if ((tempC_led < mt_led) && (tempC_led != 85.00)){
if (daybyminute >= (ontime*60))
{
if (daybyminute <= ((ontime*60) + blueramptime + (whiteramptime - 1))) //if time is in range of fade in, start fading in + (whiteramptime/10*9)
{
digitalWrite(relay_1, LOW);
digitalWrite(relay_2, LOW);
digitalWrite(relay_3, LOW);
// fade blue LEDs in from min to max.
lcd.setCursor(14,0);
lcd.print(" ");
lcd.print("RISE");
for (int i = 1; i <= 10; i++) // setting ib value for 10% increment. Start with 0%
{
analogWrite(blue, bluepercent[i]);
analogWrite(var, varpercent[i]);
lcd.setCursor(5, 1);
lcd.print(i);
lcd.print(" ");
lcd.setCursor(14, 1);
lcd.print("0");
blueglobal = bluepercent[i];
whiteglobal = whitepercent[0];
/*Serial.print("Blue_: ");
Serial.println(bluepercent[i]);
Serial.print("White: ");
Serial.println(whitepercent[0]);
*/
int countdown = ((bluerampup*60)/10); // calculates seconds to next step
while (countdown>0)
{
onesecond(); // updates clock once per second
backlight();
countdown--;
relay1();
}
}
// fade white LEDs in from min to max.
for (int i = 1; i <= 10; i++) // setting i value for 10% increment. Start with 0%
{
analogWrite(white, whitepercent[i]);
lcd.setCursor(14, 1);
lcd.print(i);
lcd.print(" ");
lcd.setCursor(5, 1);
lcd.print("10");
blueglobal = bluepercent[10];
whiteglobal = whitepercent[i];
/*
Serial.print("Blue_: ");
Serial.println(bluepercent[10]);
Serial.print("White: ");
Serial.println(whitepercent[i]);
*/
int countdown = ((whiterampup*60)/10); // calculates seconds to next step
while (countdown>0)
{
onesecond(); // updates clock once per second
backlight();
countdown--;
relay1();
}
}
}
}
}
/* ******************************************************************************************************************** */
/* * * */
/* * L O O P - M A X V A L U E * */
/* * * */
/* ******************************************************************************************************************** */
if ((tempC_led < mt_led) && (tempC_led != 85.00)){
if (daybyminute >= ((ontime * 60) + blueramptime + whiteramptime))
{
if ( daybyminute <= ((ontime * 60) + blueramptime + whiteramptime + photoperiod)) // if time is in range of photoperiod, turn lights on to maximum fade value
{
digitalWrite(relay_1, LOW);
digitalWrite(relay_2, LOW);
digitalWrite(relay_3, LOW);
lcd.setCursor(14,0);
lcd.print(" ");
lcd.print(" ");
lcd.print("MAX");
analogWrite(blue, bluepercent[10]);
analogWrite(var, varpercent[10]);
lcd.setCursor(5, 1);
lcd.print(10);
lcd.print(" ");
analogWrite(white, whitepercent[10]);
lcd.setCursor(14, 1);
lcd.print(10);
lcd.print(" ");
blueglobal = bluepercent[10];
whiteglobal = whitepercent[10];
/*
Serial.print("Blue_: ");
Serial.println(bluepercent[10]);
Serial.print("White: ");
Serial.println(whitepercent[10]);
*/
backlight();
}
}
}
I notice the problem, mostly at night since the lights wont turn off...