I am trying to write a program to control a light and a pump. I will be triggering them with relays, and I would like to be able to set the turn on times and turn off times.
so far I have figured out how to display the current time using a RTC, and move through the alarm settings. I can't quite figure out how to create a variable that can be changed after the project is completed and use that variable to trigger the arduino to bring a pin high or low. I am also at a bit of loss on how to search for help on that particuliar subject. If anyone can point me in the right direction on where to find the answer or even some code that would do this I would be thankful.
Here is the code that I have so far, some is copied, and the rest I wrote from looking at the reference section.
Thanks.
#include <LiquidCrystal.h>
#include <Wire.h>
#include "RTClib.h"
LiquidCrystal lcd(7, 8, 9, 10, 11, 12);
RTC_DS1307 RTC;
int setupbutton = 2, adjustbutton = 3; //Creates a variable connected to pins 2 and 3
int setmode = 0;
void setup () {
lcd.begin(16, 2);
Wire.begin();
RTC.begin();
}
void loop () {
if (digitalRead(setupbutton) == HIGH) //If setbutton is pressed
{
setmode++; //Changes the mode
delay(200); //wait so as not to move through settings too fast
if (setmode == 5) //Resets it if the user has scrolled through all settings
{
setmode = 0;
}
}
if (setmode == 0) // If the user is not in a alarm setting mode
{
lcd.setCursor(0, 0);
lcd.print("Current Time ");
}
if (setmode == 1) // Setting an alarm on
{
lcd.setCursor(0,0);
lcd.print("Setting Sched 1A");
}
if (setmode == 2)
{
lcd.setCursor(0,0);
lcd.print("Setting Sched 1B"); // Setting an alarm off
}
if (setmode == 3)
{
lcd.setCursor(0,0);
lcd.print("Setting Sched 2A"); // Setting an alarm on
}
if (setmode == 4)
{
lcd.setCursor(0,0);
lcd.print("Setting Sched 2B"); // Setting an alarm off
}
DateTime now = RTC.now();
if (now.hour() < 10) //Starts the test to see if a space needs to be inserted before the hours
{
lcd.setCursor(0,1); //Sets the cursor for a blank
lcd.print(" "); //Blanks the first digit
lcd.setCursor(1,1); //Sets the cursor for hour
lcd.print(now.hour(), DEC); //Prints the hour
}
else
{
lcd.setCursor(0,1); //Sets the cursor for hours
lcd.print(now.hour(), DEC); //Prints the hour
}
lcd.setCursor(2,1); //Sets the cursor for first colon
lcd.print(":");
if (now.minute() < 10)
{
lcd.setCursor(3,1); //Sets the cursor for minutes
lcd.print("0");
lcd.setCursor(4,1);
lcd.print(now.minute(), DEC);
}
else
{
lcd.setCursor(3,1);
lcd.print(now.minute(), DEC);
}
lcd.setCursor(5,1); //Sets the cursor for seconds
lcd.print(":");
lcd.setCursor(6,1);
lcd.print(now.second(), DEC);
if (now.second() == 0) // blanks out the space after a single digit "second"
{
lcd.setCursor(7,1);
lcd.print(" ");
}
}