Hi all, I have a problem with my code. The problem is on the display, everything shows and is working fine until I unplug and plug back in. The time, temp, M: (for moon lights) all come back on with the exception of L: (lights). the symbol shows but the on or off will not display. If some one could take a look and point me in the right direction it would be appreciated. Thanks for the help, Jim
void onesecond() //function that runs once per second while program is running
{
byte second, minute, hour, dayOfWeek, dayOfMonth, month, year;
getDateDs1307(&second, &minute, &hour, &dayOfWeek, &dayOfMonth, &month, &year);
lcd.setCursor(0, 0);
if(hour>0)
{
if(hour<=12)
{
lcd.print(hour, DEC);
}
else
{
lcd.print(hour-12, DEC);
}
}
else
{
lcd.print("12");
}
lcd.print(":");
if (minute < 10) {
lcd.print("0");
}
lcd.print(minute, DEC);
//lcd.print(":");
//if (second < 10) {
// lcd.print("0");
//}
//lcd.print(second, DEC);
if(hour<12)
{
lcd.print("am");
}
else
{
lcd.print("pm");
}
//lcd.print(" ");
delay(1000);
}
/*||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| D E F I N E : MOON L I G H T O N |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||*/
void MoonOn()
{
digitalWrite(moon, HIGH);
lcd.setCursor(13,1);
lcd.print("On ");
}
/*||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| D E F I N E : F U G E L I G H T O F F |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||*/
void MoonOff()
{
digitalWrite(moon, LOW);
lcd.setCursor(13,1);
lcd.print("Off");
delay(1000);
}
/*||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| D E F I N E : R E L A Y 1 |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||*/
void relay1() //FUNCTION TO TURN ON AND OFF RELAY 1.
{
unsigned long currentMillis = millis();
if(currentMillis - previousMillis1 > interval1)
{
previousMillis1 = currentMillis;
if (ledState1 == LOW)
ledState1 = HIGH;
else
ledState1 = LOW;
digitalWrite(ledPin1, ledState1);
}
}
/*||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| S E T U P |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||*/
void setup() {
pinMode(ledPin1, OUTPUT); // set the digital pin as output:
pinMode(moon, OUTPUT); // Set analog pin 1 as a output
sensors.begin(); // Start up the DS18B20 Temp library
/*||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| S E T U P - D I S P L A Y |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||*/
byte second, minute, hour, dayOfWeek, dayOfMonth, month, year;
Wire.begin();
// Change these values to what you want to set your clock to.
// You probably only want to set your clock once and then remove
// the setDateDs1307 call.
second = 00;
minute = 48;
hour = 6;
dayOfWeek = 4; // Sunday is 0
dayOfMonth = 12;
month = 1;
year = 12;
//Use the next line for setting the clock
// setDateDs1307(second, minute, hour, dayOfWeek, dayOfMonth, month, year);
analogWrite(blue, bluemin);
analogWrite(white, whitemin);
lcd.begin(16, 2); // set up the LCD's number of rows and columns:
lcd.setCursor(10, 1);
lcd.print("M:");
lcd.setCursor(0, 1);
lcd.print("L:");
}
/*||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| L O O P |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||*/
void loop()
{
onesecond();
relay1();
/*||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| 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 (daybyminute >= (ontime*60))
{
if (daybyminute <= ((ontime*60) + blueramptime + (whiteramptime/10*9))) //if time is in range of fade in, start fading in + (whiteramptime/10*9)
{
MoonOff();
for (int i = 1; i <= 10; i++) // setting ib value for 10% increment. Start with 0%
{
analogWrite(blue, bluepercent[i]);
int countdown = ((bluerampup*60)/10); // calculates seconds to next step
while (countdown>0)
{
onesecond(); // updates clock once per second
countdown--;
relay1();
delay(1000);
}
}
// 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(4, 1);
lcd.print("ON ");
int countdown = ((whiterampup*60)/10); // calculates seconds to next step
while (countdown>0)
{
onesecond(); // updates clock once per second
countdown--;
relay1();
delay(1000);
}
}
}
}
/*||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| L O O P - M A X V A L U E |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||*/
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
{
MoonOff();
analogWrite(blue, 255);
analogWrite(white, 255);
lcd.setCursor(4, 1);
lcd.print("ON ");
}
}
/*||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| L O O P - F A D E O U T |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||*/
if (((ontime * 60) + photoperiod + blueramptime + whiteramptime) <= daybyminute)
{
if (((ontime * 60) + photoperiod + whiteramptime + 2*blueramptime + (blueramptime/10*9)) >= daybyminute)
{
MoonOff();
// fade white LEDs out from max to min in increments of 1 point:
for (int i = 10; i >= 0; i--) // setting i value for 10% increment. Start with 10%
{
analogWrite(blue, 255);
analogWrite(white, whitepercent[i]);
lcd.setCursor(4, 1);
lcd.print("OFF ");
int countdown = ((whiterampdown*60)/10); // calculates seconds to next step
while (countdown>0)
{
onesecond(); // updates clock once per second
countdown--;
relay1();
delay(1000);
}
}
// fade blue LEDs out from max to min in increments of 1 point:
for (int i = 10; i >= 0; i--) // setting i value for 10% increment. Start with 10%
{
analogWrite(blue, bluepercent[i]);
int countdown = ((bluerampdown*60)/10); // calculates seconds to next step
while (countdown>0)
{
onesecond(); // updates clock once per second
countdown--;
relay1();
delay(1000);
}
}
}
}
// DS18B20 display
sensors.requestTemperatures(); // Send the command to get temperatures
// set the cursor to column 0, line 1
// (note: line 1 is the second row, since counting begins with 0):
lcd.setCursor(9, 0);
lcd.print(sensors.getTempFByIndex(0));
lcd.print((char)223);
lcd.print("F ");
delay(500);
//*||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| Night Time |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||*/
if (((ontime * 60) + photoperiod + (2 * blueramptime) + (2 * whiteramptime)) < daybyminute)
{
MoonOn();
}
if (daybyminute < (ontime*60))
{
}
} // END LOOP