What I am doing, is trying to build a clock using this device. I want to pull the date, the hours, and the minutes and have corresponding LED's light up depending on the time. I have the clock up and working, but I am unsure of what code to use to specify "if the month is November, then this group of LED's light up", or "if the hour is 1pm, then this LED should light up", and so on so forth.
Like I mentioned, I am using the DS1307 real time clock with an Arduino Mega 2560. So far the only code I have is for having the real time clock read the correct time which can be seen in the serial monitor:
// Date and time functions using a DS1307 RTC connected via I2C and Wire lib
#include <Wire.h>
#include "RTClib.h"
RTC_DS1307 rtc;
void setup () {
Serial.begin(57600);
#ifdef AVR
Wire.begin();
#else
Wire1.begin(); // Shield I2C pins connect to alt I2C bus on Arduino Due
#endif
rtc.begin();
if (! rtc.isrunning()) {
Serial.println("RTC is NOT running!");
// following line sets the RTC to the date & time this sketch was compiled
rtc.adjust(DateTime(__DATE__, __TIME__));
}
}
void loop () {
DateTime now = rtc.now();
Serial.print(now.year(), DEC);
Serial.print('/');
Serial.print(now.month(), DEC);
Serial.print('/');
Serial.print(now.day(), DEC);
Serial.print(' ');
Serial.print(now.hour(), DEC);
Serial.print(':');
Serial.print(now.minute(), DEC);
Serial.print(':');
Serial.print(now.second(), DEC);
Serial.println();
Serial.println();
delay(1000);
}
If anyone can help, I would greatly appreciate it! Thanks!
My next step would be to get the LEDs to display some sort of number (eg. 42). That gets the LED part working. Then connect up the clock part to the display part.
I actually am not using any sort of LED display part. I am using individual LED lights to represent certain times. Therefore, I cannot really get anything to display a number (such as 42). I am unsure of what code is needed to pull from the data from the real time clock to tell the LED to light up when I need it to.
In theory I want to say something like If the real time clock is at 3:00pm, I want the LED in pin 13 to light up. Does that make sense? I'm trying to find out how to code something along those lines but am unsure how to write the code for the DS1307 real time clock to understand.
You use conditions based on the values of the fields of the DateTime "now"...
Of course you want to run update this DateTime with a call to rtc.now() on a regular
basis, perhaps about once a second (which can be done using the sort of technique
in the BlinkWithoutDelay example.
In my code, I'm using an old $1 universal control (Sony-ish) to set the clock, but you can do it the more traditional (and annoying way, too) by using variables in the set-time program and then load your code for interrogation ...
Now what I am unsure of is how to code is if I have a range. For example. I have a bunch of LED lights in the back of my clock that I want to be dim. However, when the minute time range of the current time is between 0min-5min (for example 5:00pm-5:05pm) I want a specific group of LED lights attached to pin 12 to become brighter than the LED lights that are attached to let's say pin 11.
I am unsure how to indicate a range with the Arduino. Any help is appreciated!