Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <U8g2lib.h>
- #include <Wire.h>
- #include <RTClib.h> // Installed from github .zip file
- #include <Adafruit_Sensor.h>
- #include <Adafruit_BME280.h>
- #include <Adafruit_Si7021.h>
- #define SEALEVELPRESSURE_HPA (1013.25)
- Adafruit_BME280 bme;
- Adafruit_Si7021 si7021;
- RTC_DS1307 rtc;
- U8G2_SSD1306_128X64_NONAME_1_HW_I2C u8g2(U8G2_R0, /* reset=*/ U8X8_PIN_NONE);
- u8g2_uint_t offset; // current offset for the scrolling text
- u8g2_uint_t width; // pixel width of the scrolling text (must be lesser than 128 unless U8G2_16BIT is defined
- //const char *text = " - - - - - - - - "; // scroll this text from right to left if upper line is scrolling
- const char *text1 = "----------------"; // scroll this text from right to left if upper line is still
- char daysOfTheWeek[7][12] = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};
- void setup(void){
- Serial.begin(9600);
- u8g2.begin();
- delay(3000); // wait for console opening
- if (! rtc.begin()) {
- Serial.println("Couldn't find RTC");
- while (1);
- }
- if (!rtc.isrunning()) {
- Serial.println("RTC lost power, lets set the time!");
- // Comment out below lines once you set the date & time.
- // Following line sets the RTC to the date & time this sketch was compiled
- //rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
- // Following line sets the RTC with an explicit date & time
- // for example to set January 27 2017 at 12:56 you would call:
- rtc.adjust(DateTime(2021, 6, 8, 12, 28, 0));
- }
- si7021.begin();
- if (!bme.begin(0x76)) {
- Serial.println("Could not find a valid BME280 sensor, check wiring!");
- u8g2.setCursor(34, 19);
- u8g2.print("Sensor Error!");
- }
- width = u8g2.getUTF8Width(text1); // calculate the pixel width of the text
- //u8g2.setFontMode(0); // enable transparent mode, which is faster
- u8g2_uint_t offset;
- }
- void loop(void) {
- DateTime now = rtc.now();
- //DAY
- u8g2.setFont(u8g2_font_pressstart2p_8f);
- u8g2.print(now.day(), DEC);
- //MONTH
- u8g2.setFont(u8g2_font_pressstart2p_8f);
- u8g2.print(now.month(), DEC);
- //YEAR
- u8g2.setFont(u8g2_font_pressstart2p_8f);
- u8g2.print(now.year(), DEC);
- // HOURS
- u8g2.setFont(u8g2_font_pressstart2p_8f);
- u8g2.print(now.hour(), DEC);
- // MINUTES
- u8g2.setFont(u8g2_font_pressstart2p_8f);
- u8g2.print(":");
- u8g2.print(now.minute(), DEC);
- // SECONDS
- u8g2.setFont(u8g2_font_pressstart2p_8f);
- u8g2.print(":");
- u8g2.print(now.second(), DEC);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement