#include <Adafruit_MPU6050.h>
#include <Adafruit_Sensor.h>
#include <Wire.h>
#include <SD.h>
#include "DHT.h"
#include "RTClib.h"
#include "lcdgfx.h"
#include "lcdgfx_gui.h"
#define DHT_PIN 5
#define DHT_TYPE DHT22
//#define SDCARD_CS_PIN 10
//#define LCD_CS_PIN 4
//#define LCD_DC_PIN 5
//#define LCD_RST_PIN 3
DHT dht(DHT_PIN, DHT_TYPE);
//RTC_DS1307 rtc;
//DisplayIL9163_128x128x16_SPI display(LCD_RST_PIN, {-1, LCD_CS_PIN, LCD_DC_PIN, 0, -1, -1});
Adafruit_MPU6050 mpu;
void setup() {
Serial.begin(115200);
//pinMode(SDCARD_CS_PIN, OUTPUT);
dht.begin();
if (!mpu.begin(0x69)) {
Serial.println("mpu not found");
Serial.flush();
abort();
}
mpu.setAccelerometerRange(MPU6050_RANGE_8_G);
mpu.setGyroRange(MPU6050_RANGE_2000_DEG);
mpu.setFilterBandwidth(MPU6050_BAND_21_HZ);
// if (!rtc.begin()) {
// Serial.println("Couldn't find RTC");
// Serial.flush();
// abort();
// }
// if (!rtc.isrunning()) {
// //init rtc
// }
// if (!SD.begin()) {
// Serial.println("Failed");
// return;
// }
// File f = SD.open("data.txt", FILE_WRITE);
// f.close();
// display.begin();
// display.fill(0x0000);
// display.setFixedFont(ssd1306xled_font6x8);
// display.setColor(RGB_COLOR16(255, 255, 255));
// display.clear();
}
void loop() {
//DateTime time = rtc.now();
char buf[20], x[20], y[20], z[20];
//sprintf(buf, "%02d:%02d:%02d", time.hour(), time.minute(), time.second());
//display.printFixed(0, 0, buf, STYLE_NORMAL);
float temp = dht.readTemperature();
float hum = dht.readHumidity();
float fah = dht.readTemperature(true);
float heat_index = dht.computeHeatIndex(fah, hum);
dtostrf(temp, 2, 1, x);
dtostrf(hum, 2, 1, y);
dtostrf(heat_index, 2, 1, z);
sprintf(buf, "T%s H%s I%s", x, y, z);
//display.printFixed(0, 59, buf, STYLE_NORMAL);
Serial.println(buf);
// File sd_file = SD.open("data.txt", FILE_WRITE);
// if (sd_file) {
// sd_file.println("");
// sd_file.flush();
// sd_file.close();
// }
sensors_event_t a, g, t;
mpu.getEvent(&a, &g, &t);
dtostrf(a.acceleration.x, 1, 2, x);
dtostrf(a.acceleration.y, 1, 2, y);
dtostrf(a.acceleration.z, 1, 2, z);
sprintf(buf, "A %s %s %s", x, y, z);
//display.printFixed(0, 9, buf, STYLE_NORMAL);
Serial.println(buf);
dtostrf(g.gyro.x, 1, 2, x);
dtostrf(g.gyro.y, 1, 2, y);
dtostrf(g.gyro.z, 1, 2, z);
sprintf(buf, "G %s %s %s", x, y, z);
//display.printFixed(0, 17, buf, STYLE_NORMAL);
Serial.println(buf);
dtostrf(t.temperature, 2, 2, x);
sprintf(buf, "T %s", x);
//display.printFixed(0, 25, buf, STYLE_NORMAL);
Serial.println(buf);
Serial.println();
//lcd_delay(500);
delay(1000);
}