This shows you the differences between two versions of the page.
|
digispark:tutorials:rtc [2013/05/30 02:19] digistump created |
digispark:tutorials:rtc [2016/06/09 12:03] |
||
|---|---|---|---|
| Line 1: | Line 1: | ||
| - | <code> | ||
| - | #include <TinyWireM.h> // I2C Master lib for ATTinys which use USI - comment this out to use with standard arduinos | ||
| - | #include <LiquidCrystal_I2C.h> // for LCD w/ GPIO MODIFIED for the ATtiny85 | ||
| - | #include <TinyRTClib.h> | ||
| - | |||
| - | RTC_DS1307 RTC; | ||
| - | #define GPIO_ADDR 0x27 // (PCA8574A A0-A2 @5V) typ. A0-A3 Gnd 0x20 / 0x38 for A - 0x27 is the address of the Digispark LCD modules. | ||
| - | |||
| - | |||
| - | LiquidCrystal_I2C lcd(GPIO_ADDR,16,2); // set address & 16 chars / 2 lines | ||
| - | |||
| - | |||
| - | void setup(){ | ||
| - | | ||
| - | TinyWireM.begin(); // initialize I2C lib - comment this out to use with standard arduinos | ||
| - | RTC.begin(); | ||
| - | |||
| - | if (! RTC.isrunning()) { | ||
| - | // following line sets the RTC to the date & time this sketch was compiled only for the first run | ||
| - | RTC.adjust(DateTime(__DATE__, __TIME__)); | ||
| - | } | ||
| - | | ||
| - | lcd.init(); // initialize the lcd | ||
| - | lcd.backlight(); // Print a message to the LCD. | ||
| - | lcd.print("Digispark!"); | ||
| - | delay(1000); | ||
| - | } | ||
| - | |||
| - | |||
| - | void loop(){ | ||
| - | DateTime now = RTC.now(); | ||
| - | |||
| - | | ||
| - | lcd.home(); | ||
| - | | ||
| - | lcd.print(now.year(), DEC); | ||
| - | lcd.print('/'); | ||
| - | if(now.month()<10) | ||
| - | lcd.print("0"); | ||
| - | | ||
| - | lcd.print(now.month(), DEC); | ||
| - | | ||
| - | lcd.print('/'); | ||
| - | | ||
| - | if(now.day()<10) | ||
| - | lcd.print("0"); | ||
| - | | ||
| - | lcd.print(now.day(), DEC); | ||
| - | | ||
| - | lcd.setCursor(0, 1); | ||
| - | | ||
| - | if(now.hour()<10) | ||
| - | lcd.print("0"); | ||
| - | | ||
| - | lcd.print(now.hour(), DEC); | ||
| - | lcd.print(':'); | ||
| - | | ||
| - | if(now.minute()<10) | ||
| - | lcd.print("0"); | ||
| - | | ||
| - | lcd.print(now.minute(), DEC); | ||
| - | lcd.print(':'); | ||
| - | | ||
| - | if(now.second()<10) | ||
| - | lcd.print("0"); | ||
| - | | ||
| - | lcd.print(now.second(), DEC); | ||
| - | | ||
| - | delay(1000); | ||
| - | } | ||
| - | </code> | ||
| - | |||
| - | |||
| - | <code> | ||
| - | |||
| - | #include <TinyWireM.h> // I2C Master lib for ATTinys which use USI - comment this out to use with standard arduinos | ||
| - | #include <DigiUSB.h> | ||
| - | #include <TinyRTClib.h> | ||
| - | |||
| - | RTC_DS1307 RTC; | ||
| - | |||
| - | void setup(){ | ||
| - | | ||
| - | TinyWireM.begin(); // initialize I2C lib - comment this out to use with standard arduinos | ||
| - | RTC.begin(); | ||
| - | |||
| - | if (! RTC.isrunning()) { | ||
| - | // following line sets the RTC to the date & time this sketch was compiled only for the first run | ||
| - | RTC.adjust(DateTime(__DATE__, __TIME__)); | ||
| - | } | ||
| - | | ||
| - | DigiUSB.begin(); | ||
| - | } | ||
| - | |||
| - | |||
| - | void loop(){ | ||
| - | DateTime now = RTC.now(); | ||
| - | DigiUSB.print(now.hour(), DEC); | ||
| - | DigiUSB.print(":"); | ||
| - | DigiUSB.print(now.minute(), DEC); | ||
| - | DigiUSB.print(':'); | ||
| - | DigiUSB.println(now.second(), DEC); | ||
| - | DigiUSB.delay(1000); | ||
| - | } | ||
| - | </code> | ||