Beruflich Dokumente
Kultur Dokumente
Here’s what the clock should look like once you’ve hooked everything up:
A few lines of code have to go in your clock sketch to make things happy.
?
#include <LiquidCrystal.h>
1 #include <Wire.h>
2 #include "RTClib.h"
3
4 // LCD
5 // LCD D4 to Arduino 9
6 // LCD D5 to Arduino 10
// LCD D6 to Arduino 11
7 // LCD D7 to Arduino 12
8 // RS 4 to Arduino 7
9 // EN 6 to Arduino 8
10// RH 5 to GND
11// pin 3 to center pot
LiquidCrystal lcd(7, 8, 9, 10, 11, 12);
12
13// DS1307 RTC
14// SDA pin to Arduino A4
15// SCL pin to Arduino A5
16RTC_DS1307 RTC;
17
void setup() {
18 Serial.begin(57600);
19 Wire.begin();
20 RTC.begin();
21
22 /*
23 if (! RTC.isrunning()) {
Serial.println("RTC is NOT running!");
24 // following line sets the RTC to the date & time this sketch was
25compiled
26 // RTC.adjust(DateTime(10/23/2012, 10:30:00));
27 }
*/
28
29 lcd.begin(16,2); // 16x2 LCD
30 lcd.clear(); // blank the display
31}
32
33void loop() {
34 DateTime now = RTC.now();
lcd.clear();
35 lcd.setCursor(0,0);
36 if (now.day() < 10) {
37 lcd.print("0");
38 }
39
lcd.print(now.month(), DEC);
40 lcd.print("/");
41 if (now.month() < 10) {
42 lcd.print("0");
43 }
44
45 lcd.print(now.day(), DEC);
lcd.print("/");
46 lcd.print(now.year(), DEC);
47 lcd.setCursor(0,1);
48 if (now.hour() < 10) {
lcd.print("0");
49 }
50
51 lcd.print(now.hour(), DEC);
52 lcd.print(":");
53 if (now.minute() < 10) {
lcd.print("0");
54 }
55
56 lcd.print(now.minute(), DEC);
57 lcd.print(":");
58 if (now.second() < 10) {
59 lcd.print("0");
}
60
61 lcd.print(now.second(), DEC);
62 delay(1000);
63}
64
65
66
67
68
69
70
71
72
73
74
If you want to set the time to the time the sketch was compiled, just change this line to:
?
1RTC.adjust(DateTime(__DATE__,__ TIME__));
From that point on, everything will run on its own, and the RTC will keep track of the
time and date even in the event of a power outage. (Using the battery backup.)
You shouldn't have tot set it again for another 8 years; that's how long the RTC battery
backup is supposed to last. However, Daylight savings, etc might cause you to want to
manually tweak the time. That accuracy of the DS1307 is based on the crystal it uses.
Depending on who you ask, some say the clock will lose anywhere from a few seconds
to a few minutes a day. Some say maybe a minute or two a year. So who really knows?
The accuracy of my clock remains to be seen.
In any event, I need to implement a manual time-setting function. The initial command
to set the RTC to the compile time is fine, by forward going, I don’t want to have to pull
the 328 out of the finished product to tweak the time. I also don’t want to put a header
on my finished clock for in-circuit programming. I want it to look clean and finished
and not so much like a test fixture/prototype.
There’s still some more work to be done…..
OUTRO prog:
#include <Wire.h>
#include "RTClib.h"
#include <LiquidCrystal.h>
RTC_DS1307 RTC;
LiquidCrystal lcd (7, 8, 9, 10, 11, 12);
void setup () {
Serial.begin(9600);
lcd.begin(16, 2);
Wire.begin();
RTC.begin();
if (! RTC.isrunning()) {
Serial.println("RTC is NOT running!");
RTC.adjust(DateTime(F(__DATE__), F(__TIME__)));
}
}
void loop () {
DateTime now = RTC.now();
lcd.setCursor(0,0);
lcd.print("TIME: ");
lcd.print(now.hour(), DEC);
lcd.print(":");
lcd.print(now.minute(), DEC);
lcd.print(":");
lcd.print(now.second(), DEC);
lcd.setCursor(0,1);
lcd.print("DATE: ");
lcd.print(now.year(), DEC);
lcd.print("/");
lcd.print(now.month(), DEC);
lcd.print("/");
lcd.print(now.day(), DEC);
delay(1000);
}
Este resistor pode variar de 20k até 150k dependendo do modelo do arduino.
Ou
pinMode(abc, INPUT_PULLUP);
ou
digitalWrite(abc, HIGH);
Para usar com botões e chaves, com o PULL_UP ligado, não é necessário usar
resistor externo,
Com a chave/botão aberto você terá HIGH no pino, e fechando terá LOW no
pino.
Quanto ao resistor de Pull_Down, pelo que me consta não tem nenhum modelo
que os tenha internamente.
Rui