forked from rweather/arduinolibs
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Reading the temperature from a DS3232 chip
- Loading branch information
Showing
5 changed files
with
112 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
/* | ||
This example demonstrates how to read time, date, and other information | ||
from the DS3232 realtime clock chip. | ||
This example is placed into the public domain. | ||
*/ | ||
|
||
#include <SoftI2C.h> | ||
#include <DS3232RTC.h> | ||
|
||
SoftI2C i2c(A4, A5); | ||
DS3232RTC rtc(i2c); | ||
|
||
const char *months[] = { | ||
" Jan ", " Feb ", " Mar ", " Apr ", " May ", " Jun ", | ||
" Jul ", " Aug ", " Sep ", " Oct ", " Nov ", " Dec " | ||
}; | ||
|
||
void setup() { | ||
Serial.begin(9600); | ||
|
||
RTCAlarm alarm; | ||
for (byte alarmNum = 0; alarmNum < RTC::ALARM_COUNT; ++alarmNum) { | ||
rtc.readAlarm(alarmNum, &alarm); | ||
Serial.print("Alarm "); | ||
Serial.print(alarmNum + 1, DEC); | ||
Serial.print(": "); | ||
if (alarm.flags & 0x01) { | ||
printDec2(alarm.hour); | ||
Serial.print(':'); | ||
printDec2(alarm.minute); | ||
Serial.println(); | ||
} else { | ||
Serial.println("Off"); | ||
} | ||
} | ||
Serial.println(); | ||
} | ||
|
||
void loop() { | ||
RTCTime time; | ||
RTCDate date; | ||
rtc.readTime(&time); | ||
rtc.readDate(&date); | ||
|
||
Serial.print("Time: "); | ||
printDec2(time.hour); | ||
Serial.print(':'); | ||
printDec2(time.minute); | ||
Serial.print(':'); | ||
printDec2(time.second); | ||
Serial.println(); | ||
|
||
Serial.print("Date: "); | ||
Serial.print(date.day, DEC); | ||
Serial.print(months[date.month - 1]); | ||
Serial.print(date.year); | ||
Serial.println(); | ||
|
||
Serial.print("Temp: "); | ||
int temp = rtc.readTemperature(); | ||
if (temp != RTC::NO_TEMPERATURE) { | ||
Serial.print(temp / 4.0); | ||
Serial.println(" celcius"); | ||
} else { | ||
Serial.println("not available"); | ||
} | ||
|
||
Serial.println(); | ||
|
||
delay(1000); | ||
} | ||
|
||
void printDec2(int value) | ||
{ | ||
Serial.print((char)('0' + (value / 10))); | ||
Serial.print((char)('0' + (value % 10))); | ||
} |