i am trying to get my arduino LCD to scroll from the date on the first row of the lcd to say "Pet Feeder" in sort of an infinite scroll. (i.e. it looks as if it is continuously scrolling between the two. Id like it to say pet feeder for about 5 seconds before scrolling to the date for another 5 seconds. and continue this 24/7 i tried my hand at just trying to get it to scroll but so far all i did was make it blink and it was completely wrong... here is the code i made, and below that is the original code before i wanted it to scroll.
#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 = 23;
int lastMinute = 59;
bool feedPet = false;
unsigned long feedTime = 0;
unsigned long lastPrintTime = 0;
struct FeedTime {
int hour, minute;
};
FeedTime amFeed = {10, 0}; // i.e. 10:00am
FeedTime pmFeed = {17, 30}; // i.e. 5:30pm
void setup ()
{
pinMode(motorPin, OUTPUT);
Serial.begin(9600);
lcd.begin(16, 2);
Wire.begin();
RTC.begin();
/*{
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;
//lastHour = currentTime.hour; // <<<<<<<<<<<<<<< I removed this
}
lastMinute = currentTime.minute; //<<<<<<<<<<<<< I Forgot This
if (feedPet)
{
turnFeeder();
}
if (millis() - lastPrintTime > 1000UL)
{
{
lcd.setCursor(0, 0);
{
lcd.print(" Pet Feeder ");
delay(1000);
}
// turn off automatic scrolling
lcd.noAutoscroll();
}
lcd.setCursor(0, 0);
char nowDate[24] = "";
sprintf(nowDate, "DATE: %02d/%02d/%d", now.month(), now.day(), now.year());
lcd.print(nowDate);
lcd.setCursor(0, 1);
char nowTime[24] = "";
sprintf(nowTime, "Time: %02d:%02d:%02d", now.hour(), now.minute(), now.second());
lcd.print(nowTime);
lastPrintTime = millis();
}
}
void turnFeeder(void)
{
static bool pinState = true;
if (millis() - feedTime < 50500UL) // 50.5 second(s)
{
if (pinState)
{
digitalWrite(motorPin, HIGH);
pinState = false;
}
}
else
{
digitalWrite(motorPin, LOW);
pinState = true;
feedPet = false;
}
}
original code
#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
void setup ()
{
pinMode(motorPin, OUTPUT);
Serial.begin(9600);
lcd.begin(16, 2);
Wire.begin();
RTC.begin();
/*{
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)
{
lcd.setCursor(0, 0);
char nowDate[24] = "";
sprintf(nowDate, "DATE: %02d/%02d/%d", now.month(), now.day(), now.year());
lcd.print(nowDate);
// 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();
}
}
void turnFeeder(void)
{
static bool pinState = true;
if (millis() - feedTime < 50500UL) // 50.5 second(s)
{
if (pinState)
{
digitalWrite(motorPin, HIGH);
pinState = false;
}
}
else
{
digitalWrite(motorPin, LOW);
pinState = true;
feedPet = false;
}
}