Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <Wire.h>
- #include <Adafruit_GFX.h>
- #include <Adafruit_SH1106.h>
- #include <RTClib.h>
- #include "DHT.h"
- ////////////////////////////////////////////
- #define SCREEN_WIDTH 128 // OLED display width, in pixels
- #define SCREEN_HEIGHT 64 // OLED display height, in pixels
- #define OLED_RESET 4
- Adafruit_SH1106 display(OLED_RESET);
- RTC_DS3231 rtc;
- String timee;
- String dayyy;
- String tem;
- #define DHTPIN 2
- #define DHTTYPE DHT11
- DHT dht(DHTPIN, DHTTYPE);
- const int MPU = 0x69;
- int16_t Tmp, GyX, GyY, GyZ;
- ///////////////////////////////////////////////
- void setup() {
- Serial.begin(9600);
- dht.begin();
- //////////////////
- initRTC();
- display.begin(SH1106_SWITCHCAPVCC, 0x3C);
- display.display();
- delay(2000); // wait for initializing
- ////////////////////
- display.clearDisplay(); // clear display
- delay(2000);
- display.display();
- display.setTextSize(2); // text size
- display.setTextColor(WHITE); // text color
- display.setCursor(0, 10); // position to display
- //////////////////////////
- Wire.begin();
- Wire.beginTransmission(MPU);
- Wire.write(0x6B);
- Wire.write(0);
- Wire.endTransmission(true);
- }
- /////////////////////////////////////////
- void loop() {
- //Gyroscope();
- DateTime now = rtc.now();
- float t = dht.readTemperature();
- //16828
- timee = "";
- timee += now.hour();
- timee += ':';
- timee += now.minute();
- timee += ':';
- timee += now.second();
- dayyy = "";
- dayyy += (now.year());
- dayyy += '/';
- dayyy += (now.month());
- dayyy += '/';
- dayyy += (now.day());
- tem = t ;
- Serial.println(timee);
- Serial.println(dayyy);
- Serial.println(tem);
- display.setTextSize(2); // text size
- display.setTextColor(WHITE); // text color
- // Clear specific areas on the display
- display.fillRect(0, 0, display.width(), display.height(), BLACK);
- display.fillRect(0, 20, display.width(), display.height(), BLACK);
- display.fillRect(30, 40, display.width(), display.height(), BLACK);
- display.display();
- delay(500);
- display.setCursor(0, 0);
- display.println(timee);
- display.setCursor(0, 20);
- display.println(dayyy);
- display.setCursor(30, 40);
- display.println(tem);
- display.display();
- delay(2000);
- /*
- if ( GyX > 3000 && GyX < 7000 ) {
- //oledDisplayCenter(timee, dayyy, tem);
- }
- else {
- //display.clearDisplay();
- display.display();
- delay(1000);
- }
- */
- }
- //////////////////////////////////
- void oledDisplayCenter(String text, String text2 , String text3 ) {
- int16_t x1;
- int16_t y1;
- uint16_t width;
- uint16_t height;
- //oled.setCursor(0, 0);
- //oled.getTextBounds(text, 0, 0, &x1, &y1, oled.width() / 2, oled.height() / 2);
- //oled.println(text);
- // display on horizontal and vertical center
- display.clearDisplay(); // clear display
- display.setCursor(0, 0);
- display.println(text);
- display.setCursor(10, 20);
- display.println(text2);
- display.setCursor(30, 40);
- display.println(text3);
- display.display();
- delay(2000);
- }
- //////////////////////////////////////////
- void initRTC() {
- if (! rtc.begin()) {
- Serial.println("Couldn't find RTC");
- Serial.flush();
- while (1) delay(10);
- }
- if (rtc.lostPower()) {
- Serial.println("RTC lost power, let's set the time!");
- rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
- }
- }
- void Gyroscope() {
- Wire.beginTransmission(MPU);
- Wire.write(0x3B);
- Wire.endTransmission(false);
- Wire.requestFrom(MPU, 12, true);
- GyX = Wire.read() << 8 | Wire.read();
- GyY = Wire.read() << 8 | Wire.read();
- GyZ = Wire.read() << 8 | Wire.read();
- Serial.print("Gyroscope: ");
- Serial.print("X = "); Serial.print(GyX);
- Serial.print(" | Y = "); Serial.print(GyY);
- Serial.print(" | Z = "); Serial.println(GyZ);
- Serial.println(" ");
- delay(333);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement