Having trouble with my code not blinking the (0,0) row of my 16x2 lcd screen right. I want it to blink each lcd.print("") command for 5 seconds each, however it is only blinking the date for 5 seconds right now, and then the lcd.print("lena feeder"); only prints for 1 second, also the time seems to be affected by this since it only updates every 6 seconds now. can someone spot my problem? and help me get what i want.
#include <Wire.h>
#include "RTClib.h"
#include <LiquidCrystal.h>
#include <TimeAlarms.h>
#include <Time.h>
RTC_DS1307 RTC;
LiquidCrystal lcd(8, 13, 9, 4, 5, 6, 7);
//int motorPin = 2;
int lastHour = 24;
int lastMinute = 60;
bool feedPet = false;
unsigned long feedTime = 0;
unsigned long lastPrintTime = 0;
struct FeedTime {
int hour, minute;
};
FeedTime amFeed = {9, 30}; // i.e. 9:30am
FeedTime pmFeed = {17, 30}; // i.e. 5:30pm
//sets up motor 1
//int pinI1 = 8;
int pinI2 = 12;
int speedpin1 = 10;
//sets speed of motor
int speed = 255;
void setup ()
{
//pinMode(motorPin, OUTPUT);
Serial.begin(9600);
lcd.begin(16, 2);
Wire.begin();
RTC.begin();
//pinMode (pinI1, OUTPUT);
pinMode (pinI2, OUTPUT);
pinMode (speedpin1, OUTPUT);
/*{
lcd.println("RTC NOT Running!");
RTC.adjust(DateTime((__DATE__), (__TIME__)));
}*/
}
void loop ()
{
DateTime now = RTC.now();
FeedTime currentTime;
currentTime.hour = now.hour();
currentTime.minute = now.minute();
if ((currentTime.minute != lastMinute) && (((currentTime.hour == amFeed.hour) && (currentTime.minute == amFeed.minute)) || ((currentTime.hour == pmFeed.hour) && (currentTime.minute == pmFeed.minute))))
{
feedTime = millis();
feedPet = true;
}
lastMinute = currentTime.minute;
if (feedPet)
{
turnFeeder();
}
if (millis() - lastPrintTime > 1000UL)
{
// display the date
lcd.setCursor(0, 0);
char nowDate[24] = "";
sprintf(nowDate, "DATE: %02d/%02d/%d", now.month(), now.day(), now.year());
lcd.print(nowDate);
// set the blink rate
delay(5000);
lcd.clear();
lcd.print("Lena Feeder v3.0");
// display the time
lcd.setCursor(0, 1);
char nowTime[24] = "";
sprintf(nowTime, "Time: %02d:%02d:%02d", now.hour(), now.minute(), now.second());
lcd.print(nowTime);
lastPrintTime = millis();
}
analogWrite(speedpin1, speed);
}
void turnFeeder(void)
{
static bool pinState = true;
if (millis() - feedTime < 15000UL) //15.0 second(s)
{
if (pinState)
{
//digitalWrite(motorPin, HIGH);
digitalWrite(pinI2, HIGH); //motorshield code
pinState = false;
}
}
else
{
//digitalWrite(motorPin, LOW);
digitalWrite(pinI2, LOW); //motorshieild code
pinState = true;
feedPet = false;
}
}