Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Date and time functions using a PCF8523 RTC connected via I2C and Wire lib
- #include "SPI.h"
- #include "Adafruit_GFX.h"
- #include "Adafruit_ILI9341.h"
- #define TFT_DC 9
- #define TFT_CS 10
- #define TS_CS 8
- #define ILI9341_BLACK 0x2104
- Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC, TS_CS);
- #include "RTClib.h"
- RTC_PCF8523 rtc;
- char daysOfTheWeek[7][12] = {"Dimanche", "Lundi", "Mardi", "Mercredi", "Jeudi", "Vendredi", "Samedi"};
- void setup () {
- tft.begin();
- tft.setRotation(1);
- tft.fillScreen(ILI9341_BLACK);
- #ifndef ESP8266
- while (!Serial); // wait for serial port to connect. Needed for native USB
- #endif
- if (! rtc.begin()) {
- Serial.println("Couldn't find RTC");
- Serial.flush();
- abort();
- }
- if (! rtc.initialized() || rtc.lostPower()) {
- Serial.println("RTC is NOT initialized, let's set the time!");
- // When time needs to be set on a new device, or after a power loss, the
- // following line sets the RTC to the date & time this sketch was compiled
- //rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
- // This line sets the RTC with an explicit date & time, for example to set
- // January 21, 2014 at 3am you would call:
- // rtc.adjust(DateTime(2014, 1, 21, 3, 0, 0));
- //
- // Note: allow 2 seconds after inserting battery or applying external power
- // without battery before calling adjust(). This gives the PCF8523's
- // crystal oscillator time to stabilize. If you call adjust() very quickly
- // after the RTC is powered, lostPower() may still return true.
- }
- // When time needs to be re-set on a previously configured device, the
- // following line sets the RTC to the date & time this sketch was compiled
- rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
- // This line sets the RTC with an explicit date & time, for example to set
- // January 21, 2014 at 3am you would call:
- // rtc.adjust(DateTime(2014, 1, 21, 3, 0, 0));
- }
- void loop () {
- DateTime now = rtc.now();
- tft.fillRect (0, 0, 320, 80,ILI9341_BLACK);
- tft.setCursor(50, 20);
- tft.setTextColor(ILI9341_WHITE);
- tft.setTextSize(5);
- tft.print(now.hour(), DEC);
- tft.print(':');
- tft.print(now.minute(), DEC);
- tft.print(':');
- tft.print(now.second(), DEC);
- tft.fillRect (0, 100, 320, 70,ILI9341_BLACK);
- tft.setCursor(50, 120);
- tft.setTextSize(4);
- tft.print(daysOfTheWeek[now.dayOfTheWeek()]);
- tft.fillRect (0, 180, 320, 70,ILI9341_BLACK);
- tft.setCursor(50, 200);
- tft.print(now.day(), DEC);
- tft.print('/');
- tft.print(now.month(), DEC);
- tft.print('/');
- tft.print(now.year(), DEC);
- delay(700);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement