Advertisement
ScienceGeyser

ArduinoTestCode2

Jun 8th, 2021
977
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <U8g2lib.h>
  2. #include <Wire.h>
  3. #include <RTClib.h> // Installed from github .zip file
  4. #include <Adafruit_Sensor.h>
  5. #include <Adafruit_BME280.h>
  6. #include <Adafruit_Si7021.h>
  7.  
  8. #define SEALEVELPRESSURE_HPA (1013.25)
  9.  
  10. Adafruit_BME280 bme;
  11. Adafruit_Si7021 si7021;
  12.  
  13. RTC_DS1307 rtc;
  14.  
  15. U8G2_SSD1306_128X64_NONAME_1_HW_I2C u8g2(U8G2_R0, /* reset=*/ U8X8_PIN_NONE);
  16.  
  17.  
  18. u8g2_uint_t offset;                     // current offset for the scrolling text
  19. u8g2_uint_t width;                      // pixel width of the scrolling text (must be lesser than 128 unless U8G2_16BIT is defined
  20. //const char *text = " - - - - - - - - ";        // scroll this text from right to left if upper line is scrolling
  21.   const char *text1 = "----------------";        // scroll this text from right to left if upper line is still
  22.  
  23.  
  24. char daysOfTheWeek[7][12] = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};
  25.  
  26.  
  27. void setup(void){
  28.  
  29.   Serial.begin(9600);
  30.   u8g2.begin();
  31.   delay(3000); // wait for console opening
  32.  
  33.   if (! rtc.begin()) {
  34.     Serial.println("Couldn't find RTC");
  35.     while (1);
  36.   }
  37.  
  38.   if (!rtc.isrunning()) {
  39.     Serial.println("RTC lost power, lets set the time!");
  40.  
  41.   // Comment out below lines once you set the date & time.
  42.     // Following line sets the RTC to the date & time this sketch was compiled
  43.     //rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
  44.  
  45.     // Following line sets the RTC with an explicit date & time
  46.     // for example to set January 27 2017 at 12:56 you would call:
  47.      rtc.adjust(DateTime(2021, 6, 8, 12, 28, 0));
  48.  }
  49.    si7021.begin();  
  50.  
  51.   if (!bme.begin(0x76)) {
  52.     Serial.println("Could not find a valid BME280 sensor, check wiring!");
  53.     u8g2.setCursor(34, 19);
  54.     u8g2.print("Sensor Error!");
  55.  
  56.  }  
  57.  
  58. width = u8g2.getUTF8Width(text1);      // calculate the pixel width of the text
  59. //u8g2.setFontMode(0); // enable transparent mode, which is faster
  60. u8g2_uint_t offset;
  61.  
  62. }
  63.  
  64. void loop(void) {
  65.  
  66. DateTime now = rtc.now();
  67.  
  68.                                                                                        //DAY
  69.          u8g2.setFont(u8g2_font_pressstart2p_8f);
  70.          u8g2.print(now.day(), DEC);
  71.  
  72.                                                                                       //MONTH
  73.          u8g2.setFont(u8g2_font_pressstart2p_8f);
  74.          u8g2.print(now.month(), DEC);
  75.  
  76.                                                                                       //YEAR
  77.          u8g2.setFont(u8g2_font_pressstart2p_8f);
  78.          u8g2.print(now.year(), DEC);
  79.  
  80.  
  81.                                                                                      // HOURS  
  82.          u8g2.setFont(u8g2_font_pressstart2p_8f);                                                                                                  
  83.          u8g2.print(now.hour(), DEC);
  84.  
  85.                                                                                     // MINUTES
  86.          u8g2.setFont(u8g2_font_pressstart2p_8f);
  87.          u8g2.print(":");
  88.          u8g2.print(now.minute(), DEC);
  89.  
  90.                                                                                     // SECONDS
  91.          u8g2.setFont(u8g2_font_pressstart2p_8f);
  92.          u8g2.print(":");
  93.          u8g2.print(now.second(), DEC);  
  94.  
  95. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement