SHARE
TWEET

Untitled




Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
- #include <Adafruit_GFX.h> //graphix library for drawing
- #include <Adafruit_ILI9341.h> //LCD library to drive screen
- //#include <DS1307.h>
- //#include <RTClib.h>
- #include "RTClib.h"
- //#include <SD.h>
- #include "SPI.h"
- #include <Adafruit_BMP280.h>
- #include <TouchScreen.h>
- #include <Wire.h>
- #include <SdFat.h>
- #include <Adafruit_SPIFlash.h> // SPI / QSPI flash library
- #include <Adafruit_ImageReader.h> // Image-reading functions
- #include <avr/sleep.h>
- // Comment out the next line to load from SPI/QSPI flash instead of SD card:
- #define USE_SD_CARD
- #if defined(USE_SD_CARD)
- SdFat SD; // SD card filesystem
- Adafruit_ImageReader reader(SD); // Image-reader object, pass in SD filesys
- #endif
- RTC_DS1307 rtc;
- File czujnik;
- int lastMinute=0;
- #define Addr 0x44 //sht
- #define Addr2 0x68 //ds1307
- //#define Addr3 0x77 //bmp280
- #define Addr4 0x45
- #define Addr5 0x50
- #define ILI9341_GRAY 0x7BEF
- //kalibracja lewy górny, prawy dolny
- //#define XMIN 221
- //#define YMIN 147
- //#define XMAX 835
- //#define YMAX 895
- #define TFT_DC 9
- #define TFT_RST -1 // You can also connect this to the Arduino reset in which case, set this #define pin to -1!
- #define TFT_CS 10
- #define SD_CS 4
- #define XMIN 154
- #define YMIN 123
- #define XMAX 918
- #define YMAX 945
- #define MINPRESSURE 10
- #define MAXPRESSURE 1000
- char strona;
- float TEMP, TEMP2, f, h ,f2, h2;
- Adafruit_BMP280 bmp;
- #define YP A3 // must be an analog pin, use "An" notation!
- #define XM A2 // must be an analog pin, use "An" notation!
- #define YM 6
- // can be a digital pin
- #define XP 5 // can be a digital pin
- //unsigned long lastDay = 0;
- Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC, TFT_RST);
- TouchScreen ts = TouchScreen(XP, YP, XM, YM, 298);
- int linie[] = {50, 70, 90, 110, 130, 150, 170, 190, 210, 230};
- int wartosc[] = {100, 90, 80, 70, 60, 50, 40, 30, 20, 10};
- float tempMax = 0;
- float tempMin = 999;
- float tempMax2 = 0;
- float tempMin2 = 999;
- void setup() {
- tft.begin();
- tft.setRotation(1);
- Wire.begin();
- Serial.begin(9600);
- drawHome();
- strona = '0';
- bmp.setSampling(Adafruit_BMP280::MODE_NORMAL, /* Operating Mode. */
- Adafruit_BMP280::SAMPLING_X2, /* Temp. oversampling */
- Adafruit_BMP280::SAMPLING_X16, /* Pressure oversampling */
- Adafruit_BMP280::FILTER_X16, /* Filtering. */
- Adafruit_BMP280::STANDBY_MS_500); /* Standby time. */
- // rtc.begin();
- bmp.begin();
- // Data i czas z momentu kompilacji
- rtc.adjust(DateTime(__DATE__, __TIME__));
- rtc.begin();
- }
- void loop()
- {
- //delay(5000);//wait 5 seconds before going to sleep. In real senairio keep this as small as posible
- // Going_To_Sleep();
- //dt = clock.getDateTime();
- DateTime now = rtc.now();
- labview();
- TSPoint p = ts.getPoint();
- pinMode(XM, OUTPUT);
- pinMode(YP, OUTPUT);
- if(strona == '0')
- {
- if (p.z > MINPRESSURE && p.z < MAXPRESSURE)
- {
- p.x = map(p.x, YMIN, YMAX, 0, tft.height());
- p.y = map(p.y, XMIN, XMAX, 0, tft.width());
- int y = tft.height() - p.x;
- int x = p.y;
- if(x>=45 && x<=230 && y>=80 && y<=130)
- {
- strona = '2';
- tft.fillScreen(ILI9341_WHITE);
- datetime();
- BMP();
- SHTindoor();
- SHToutdoor();
- Anemometer();
- delay(3000);
- }
- if(x>=45 && x<=230 && y>=130 && y<=180)
- {
- strona= '1';
- for(int j=50;j<320;j++)
- {
- tft.fillScreen(ILI9341_WHITE);
- Graph();
- }
- }
- if(x>=45 && x<=230 && y>=180 && y<=230)
- {
- strona = '3';
- tft.fillScreen(ILI9341_WHITE);
- logger();
- }
- }
- }
- if(strona == '1')
- {
- Graph();
- if (p.z > MINPRESSURE && p.z < MAXPRESSURE) {
- p.x = map(p.x, YMIN, YMAX, 0, tft.height());
- p.y = map(p.y, XMIN, XMAX, 0, tft.width());
- int y = tft.height() - p.x;
- int x = p.y;
- //back
- if((x>=20 && x<=70 && y>=15 && y<=40))
- {
- tft.fillScreen(ILI9341_WHITE);
- strona = '0';
- drawHome();
- }
- }
- }
- if(strona == '2')
- {
- datetime();
- BMP();
- SHTindoor();
- SHToutdoor();
- Anemometer();
- if (p.z > MINPRESSURE && p.z < MAXPRESSURE) {
- p.x = map(p.x, YMIN, YMAX, 0, tft.height());
- p.y = map(p.y, XMIN, XMAX, 0, tft.width());
- int y = tft.height() - p.x;
- int x = p.y;
- //back
- if((x>=20 && x<=70 && y>=20 && y<=40))
- {
- tft.fillScreen(ILI9341_WHITE);
- strona = '0';
- drawHome();
- }
- }
- }
- if(strona == '3')
- {
- logger();
- zapis1();
- if (p.z > MINPRESSURE && p.z < MAXPRESSURE) {
- p.x = map(p.x, YMIN, YMAX, 0, tft.height());
- p.y = map(p.y, XMIN, XMAX, 0, tft.width());
- int y = tft.height() - p.x;
- int x = p.y;
- //back
- if((x>=20 && x<=70 && y>=20 && y<=40))
- {
- tft.fillScreen(ILI9341_WHITE);
- strona = '0';
- drawHome();
- }
- if(x>=130 && x<=100 && y>=45 && y<=40)
- {
- zapis1();
- tft.fillScreen(ILI9341_WHITE);
- strona = '0';
- drawHome();
- }
- }
- }
- }
- /*
- void zapis2()
- {
- DateTime now = rtc.now();
- czujnik= SD.open("Dane", FILE_WRITE);
- if(now.minute() % 5 == 0 && now.second() == 0)
- {
- czujnik.print(now.hour(), DEC); czujnik.print(":");
- czujnik.print(now.minute(), DEC); czujnik.print(":");
- czujnik.print(now.second(), DEC); czujnik.print("");
- czujnik.print('\t');
- czujnik.print(F("Temperature "));
- czujnik.print(f);
- czujnik.print('\t');
- czujnik.print(F("Humidity "));
- czujnik.print(h);
- czujnik.print('\t');
- czujnik.print(F("Pressure "));
- // czujnik.print(pressure);
- czujnik.print('\t');
- czujnik.print(F("Temperature 2 " ));
- czujnik.print(f2);
- czujnik.print('\t');
- czujnik.print(F("Humidity 2 "));
- czujnik.print(h2);
- czujnik.print('\t');
- czujnik.close();
- }
- }*/
- void zapis1()
- {
- DateTime now = rtc.now();
- czujnik= SD.open("Dane", FILE_WRITE);
- if (now.minute() != lastMinute)
- {
- if (now.minute() % 15 == 0) // if divisible by 15
- {
- czujnik.print(now.hour(), DEC); czujnik.print(":");
- czujnik.print(now.minute(), DEC); czujnik.print(":");
- czujnik.print(now.second(), DEC); czujnik.print("");
- czujnik.print('\t');
- SHTindoor();
- czujnik.print(F("Temperature "));
- czujnik.print(f);
- czujnik.print('\t');
- czujnik.print(F("Humidity "));
- czujnik.print(h);
- czujnik.print('\t');
- czujnik.print(F("Pressure "));
- int pressure = ((bmp.readPressure()/100)+14);
- czujnik.print(pressure);
- czujnik.print('\t');
- czujnik.print(F("Temperature2 " ));
- czujnik.print(f2);
- czujnik.print('\t');
- czujnik.print(F("Humidity 2 "));
- czujnik.print(h2);
- czujnik.print('\t');
- czujnik.close();
- lastMinute = now.minute();
- }
- // if(now.minute() % 10 == 0 && now.second() == 0)
- // {
- }
- }
- void logger()
- {
- zapis1();
- TSPoint p = ts.getPoint(); //Get touch point
- pinMode(XM, OUTPUT);
- pinMode(YP, OUTPUT);
- //tft.fillRoundRect(10,10, 70, 36, 5,ILI9341_RED);
- //tft.drawRoundRect(10,10,70,36,5,ILI9341_WHITE);
- tft.setCursor(20,20);
- tft.setTextColor(ILI9341_BLACK);
- tft.setTextSize(3);
- tft.print(F("<-"));
- if(SD.begin(SD_CS))
- {
- czujnik= SD.open("Dane", FILE_WRITE);
- tft.setTextSize(2);
- tft.setCursor(10,210);
- tft.fillRect(10,210, 120, 30, ILI9341_WHITE);
- tft.print(F("SD..."));
- // SHT();
- // czujnik.close();
- }
- else{
- // czujnik= SD.open("Dane", FILE_WRITE);
- tft.setTextSize(2);
- tft.setCursor(10,210);
- tft.fillRect(10,210, 120, 30, ILI9341_WHITE);
- tft.print(F("No SD Card"));
- }
- //tft.drawRoundRect(100,40,140,50,5,ILI9341_BLACK);
- //tft.setCursor(110,50);
- tft.fillRoundRect(130,45, 100, 40,5, ILI9341_WHITE);
- tft.drawRoundRect(130,45,100,40,5,ILI9341_BLACK);
- tft.setCursor(140,55);
- tft.setTextColor(ILI9341_BLACK);
- tft.setTextSize(2);
- tft.print("15min");
- tft.fillRoundRect(130,95, 100, 40,5, ILI9341_WHITE);
- tft.drawRoundRect(130,95,100,40,5,ILI9341_BLACK);
- tft.setCursor(140 ,105);
- tft.setTextColor(ILI9341_BLACK);
- tft.setTextSize(2);
- tft.print(F("30min"));
- tft.fillRoundRect(130,145, 100, 40,5, ILI9341_WHITE);
- tft.drawRoundRect(130,145,100,40,5,ILI9341_BLACK);
- tft.setCursor(140 ,155);
- tft.setTextColor(ILI9341_BLACK);
- tft.setTextSize(2);
- tft.print(F("1h"));
- tft.fillRoundRect(130,195, 100, 40,5, ILI9341_WHITE);
- tft.drawRoundRect(130,195,100,40,5,ILI9341_BLACK);
- tft.setCursor(140 ,205);
- tft.setTextColor(ILI9341_BLACK);
- tft.setTextSize(2);
- tft.print(F("5h"));
- }
- /*
- tft.drawRoundRect(100,90,70,36,5,ILI9341_BLACK);
- tft.setCursor(110,100);
- tft.setTextColor(ILI9341_BLACK);
- tft.setTextSize(2);
- tft.print("30min");
- tft.drawRoundRect(100,140,70,36,5,ILI9341_BLACK);
- tft.setCursor(110,150);
- tft.setTextColor(ILI9341_BLACK);
- tft.setTextSize(2);
- tft.print("1h");
- tft.drawRoundRect(100,190,70,36,5,ILI9341_BLACK);
- tft.setCursor(110,200);
- tft.setTextColor(ILI9341_BLACK);
- tft.setTextSize(2);
- tft.print("5h");
- */
- void BMP()
- {
- ImageReturnCode stat; // Status from image-reading functions
- // Load full-screen BMP file 'purple.bmp' at position (0,0) (top left).
- // Notice the 'reader' object performs this, with 'tft' as an argument.
- // Serial.print(F("Loading purple.bmp to screen..."));
- stat = reader.drawBMP("/wi-barometer.bmp", tft, 165, 150);
- reader.printStatus(stat); // How'd we do?
- int pressure = ((bmp.readPressure()/100)+14);
- tft.setTextSize(2);
- tft.setCursor(205,160);
- tft.print("Pressure");
- tft.fillRect(205, 190, 110, 40, ILI9341_WHITE);
- tft.setCursor(205, 190);
- tft.setTextColor(ILI9341_BLACK);
- tft.print(pressure);
- tft.setCursor(240,190);
- tft.println(F(" hPa"));
- //Serial.print(pressure);
- /*
- czujnik= SD.open("Dane", FILE_WRITE);
- czujnik.print(F(" Pressure"));
- czujnik.println(p);
- czujnik.close();
- */
- }
- void Anemometer()
- {
- ImageReturnCode stat; // Status from image-reading functions
- // Load full-screen BMP file 'purple.bmp' at position (0,0) (top left).
- // Notice the 'reader' object performs this, with 'tft' as an argument.
- //Serial.print(F("Loading purple.bmp to screen..."));
- tft.setTextSize(2);
- stat = reader.drawBMP("/wi-strong-wind.bmp", tft,30, 145);
- tft.setCursor(50, 160);
- tft.print("Wind Speed");
- reader.printStatus(stat); // How'd we do?
- tft.fillRect(50, 190, 110, 40, ILI9341_WHITE);
- tft.setCursor(50, 190);
- tft.println(F(" 0 m/s"));
- }
- void datetime()
- {
- DateTime now = rtc.now();
- Wire.beginTransmission(Addr2);
- Wire.endTransmission();
- tft.setTextSize(2);
- tft.setTextColor(ILI9341_BLACK);
- tft.fillRect(180,15,95,30,ILI9341_WHITE);
- tft.setCursor(180,15);
- tft.drawLine(180,35,290,35, ILI9341_BLACK);
- tft.print(now.hour(), DEC); tft.print(":");
- tft.print(now.minute(), DEC); tft.print(":");
- tft.print(now.second(), DEC); tft.println("");
- //delay(10);
- /* czujnik= SD.open("Dane", FILE_WRITE);
- czujnik.print(now.hour(), DEC); czujnik.print(":");
- czujnik.print(now.minute(), DEC); czujnik.print(":");
- czujnik.print(now.second(), DEC); czujnik.print("");
- czujnik.print('\t');
- czujnik.close();*/
- }
- void labview()
- {
- DateTime now = rtc.now();
- unsigned int data[6];
- // Start I2C Transmission
- Wire.beginTransmission(Addr);
- // Send 16-bit command byte
- Wire.write(0x2C);
- Wire.write(0x06);
- // Stop I2C transmission
- Wire.endTransmission();
- delay (300);
- // Start I2C Transmission
- Wire.beginTransmission(Addr);
- // Stop I2C Transmission
- Wire.endTransmission();
- // Request 6 bytes of data
- Wire.requestFrom(Addr, 6);
- // Read 6 bytes of data
- // temp msb, temp lsb, temp crc, hum msb, hum lsb, hum crc
- if (Wire.available() == 6)
- {
- data[0] = Wire.read();//MSB
- data[1] = Wire.read();//LSB
- data[2] = Wire.read();//CHECKSUM
- data[3] = Wire.read();
- data[4] = Wire.read();
- data[5] = Wire.read();
- }
- float TEMP = (data[0] * 256.0) + data[1];
- float f= -45.0 + (175.0 * TEMP / 65535.0);
- float h = ((100.0 * ((data[3] * 256.0) + data[4])) / 65535.0);
- unsigned int data1[6];
- Wire.beginTransmission(Addr4);
- Wire.write(0x2C);
- Wire.write(0x06);
- Wire.endTransmission();
- delay (300);
- // Start I2C Transmission
- Wire.beginTransmission(Addr4);
- // Stop I2C Transmission
- Wire.endTransmission();
- Wire.requestFrom(Addr4, 6);
- // Read 6 bytes of data
- // temp msb, temp lsb, temp crc, hum msb, hum lsb, hum crc
- if (Wire.available() == 6)
- {
- data1[0] = Wire.read();
- data1[1] = Wire.read();
- data1[2] = Wire.read();
- data1[3] = Wire.read();
- data1[4] = Wire.read();
- data1[5] = Wire.read();
- }
- TEMP2 = (data1[0] * 256.0) + data1[1];
- f2 = -45.0 + (175.0 * TEMP2 / 65535.0);
- h2= ((100.0 * ((data1[3] * 256.0) + data1[4])) / 65535.0);
- //char buffer[50];
- //sprintf(buffer, "%f,%f,%f,%f\n", f, h, f2, h2);
- int pressure = ((bmp.readPressure()/100)+14);
- /// Serial.write(buffer);
- Serial.print(f);
- Serial.print('\t');
- Serial.print(h);
- Serial.print('\t');
- Serial.print(f2);
- Serial.print('\t');
- Serial.print(h2);
- Serial.print('\t');
- Serial.print(pressure);
- Serial.print('\t');
- }
- void SHTindoor()
- {
- /* ImageReturnCode stat; // Status from image-reading functions
- // Load full-screen BMP file 'purple.bmp' at position (0,0) (top left).
- // Notice the 'reader' object performs this, with 'tft' as an argument.
- //Serial.print(F("Loading purple.bmp to screen..."));
- stat = reader.drawBMP("/wi-humidity.bmp", tft, 30, 75);
- reader.printStatus(stat); // How'd we do?
- */
- //ImageReturnCode stat; // Status from image-reading functions
- // Load full-screen BMP file 'purple.bmp' at position (0,0) (top left).
- // Notice the 'reader' object performs this, with 'tft' as an argument.
- //Serial.print(F("Loading purple.bmp to screen..."));
- // stat = reader.drawBMP("/wi-cloud.bmp", tft, 0, 230);
- //reader.printStatus(stat); // How'd we do?
- //tft.fillRoundRect(10,10, 70, 36, 5,ILI9341_RED);
- //tft.drawRoundRect(10,10,70,36,5,ILI9341_WHITE);
- tft.setCursor(20,20);
- tft.setTextColor(ILI9341_BLACK);
- tft.setTextSize(3);
- tft.print(F("<-"));
- unsigned int data[6];
- // Start I2C Transmission
- Wire.beginTransmission(Addr);
- // Send 16-bit command byte
- Wire.write(0x2C);
- Wire.write(0x06);
- // Stop I2C transmission
- Wire.endTransmission();
- delay (300);
- // Start I2C Transmission
- Wire.beginTransmission(Addr);
- // Stop I2C Transmission
- Wire.endTransmission();
- // Request 6 bytes of data
- Wire.requestFrom(Addr, 6);
- // Read 6 bytes of data
- // temp msb, temp lsb, temp crc, hum msb, hum lsb, hum crc
- if (Wire.available() == 6)
- {
- data[0] = Wire.read();//MSB
- data[1] = Wire.read();//LSB
- data[2] = Wire.read();//CHECKSUM
- data[3] = Wire.read();
- data[4] = Wire.read();
- data[5] = Wire.read();
- }
- TEMP = (data[0] * 256.0) + data[1];
- f= -45.0 + (175.0 * TEMP / 65535.0);
- h = ((100.0 * ((data[3] * 256.0) + data[4])) / 65535.0);
- /* czujnik= SD.open("Dane", FILE_WRITE);
- czujnik.print(F("Temperature "));
- czujnik.print(f);
- czujnik.print(F("Humidity "));
- czujnik.print(h);
- czujnik.close();*/
- //nowtime = milis();
- //if (time - lastDay >= day)
- //{
- //tempMin=0;
- // tempMax=0;
- // lastDay = time;
- //}
- tft.setTextSize(2);
- tft.setCursor(50,50);
- tft.setTextColor(ILI9341_BLACK);
- tft.print("Outdoor");
- tft.setTextSize(2);
- tft.setCursor(50,75);
- tft.fillRect(50,75,110,20,ILI9341_WHITE);
- tft.setTextColor(ILI9341_BLACK);
- tft.print(f, 2);
- tft.setCursor(115,70);
- tft.println(F("o"));
- tft.setCursor(130,75);
- tft.println(F("C"));
- tft.setCursor(50,115);
- tft.fillRect(50,115,110,30,ILI9341_WHITE);
- tft.setTextColor(ILI9341_BLACK);
- tft.print(h, 2);
- tft.println(F("%"));
- //delay(1000);
- if (f > tempMax)
- {
- tempMax = f;
- tft.setCursor(50,98);
- tft.fillRect(50,98, 30, 15, ILI9341_WHITE);
- tft.setTextColor(ILI9341_RED);
- tft.setTextSize(1);
- tft.print(tempMax,2);
- tft.setCursor(79,95);
- tft.println("o");
- tft.setCursor(85,98);
- tft.println("C");
- }
- else if( f < tempMin)
- {
- tempMin = f;
- tft.setCursor(100,98);
- tft.fillRect(100,98, 30, 15, ILI9341_WHITE);
- tft.setTextColor(ILI9341_BLACK);
- tft.setTextSize(1);
- tft.print(tempMin,2);
- tft.setCursor(129,95);
- tft.println("o");
- tft.setCursor(135,98);
- tft.println("C");
- }
- }
- void SHToutdoor()
- {
- unsigned int data1[6];
- Wire.beginTransmission(Addr4);
- Wire.write(0x2C);
- Wire.write(0x06);
- Wire.endTransmission();
- delay (300);
- // Start I2C Transmission
- Wire.beginTransmission(Addr4);
- // Stop I2C Transmission
- Wire.endTransmission();
- Wire.requestFrom(Addr4, 6);
- // Read 6 bytes of data
- // temp msb, temp lsb, temp crc, hum msb, hum lsb, hum crc
- if (Wire.available() == 6)
- {
- data1[0] = Wire.read();
- data1[1] = Wire.read();
- data1[2] = Wire.read();
- data1[3] = Wire.read();
- data1[4] = Wire.read();
- data1[5] = Wire.read();
- }
- TEMP2 = (data1[0] * 256.0) + data1[1];
- f2 = -45.0 + (175.0 * TEMP2 / 65535.0);
- h2= ((100.0 * ((data1[3] * 256.0) + data1[4])) / 65535.0);
- //OUTDOOR
- tft.setTextSize(2);
- tft.setCursor(205,50);
- tft.setTextColor(ILI9341_BLACK);
- tft.print("Indoor");
- tft.setTextSize(2);
- tft.setCursor(205,75);
- tft.fillRect(205,75,110,20,ILI9341_WHITE);
- tft.setTextColor(ILI9341_BLACK);
- tft.print(f2, 2);
- tft.setCursor(270,70);
- tft.println(F("o"));
- tft.setCursor(285,75);
- tft.println(F("C"));
- tft.setCursor(205,115);
- tft.fillRect(205 ,115,110,30,ILI9341_WHITE);
- tft.setTextColor(ILI9341_BLACK);
- tft.print(h2, 2);
- tft.println(F("%"));
- if (f2 > tempMax2)
- {
- tempMax2 = f2;
- tft.setCursor(205,98);
- tft.fillRect(205,98, 30, 15, ILI9341_WHITE);
- tft.setTextColor(ILI9341_RED);
- tft.setTextSize(1);
- tft.print(tempMax2,2);
- tft.setCursor(234,95);
- tft.println("o");
- tft.setCursor(240,98);
- tft.println("C");
- }
- if( f2 < tempMin2)
- {
- tempMin2 = f2;
- tft.setCursor(255,98);
- tft.fillRect(255,98, 30, 15, ILI9341_WHITE);
- tft.setTextColor(ILI9341_BLACK);
- tft.setTextSize(1);
- tft.print(tempMin2,2);
- tft.setCursor(289,95);
- tft.println("o");
- tft.setCursor(294,98);
- tft.println("C");
- }
- //delay(1000);
- /* czujnik= SD.open("Dane", FILE_WRITE);
- czujnik.print(F("Temperature2 "));
- czujnik.print(f2);
- // czujnik.print(F("Humidity2 "));
- czujnik.print(h2);*/
- }
- void Graph()
- {
- tft.setCursor(20,15);
- tft.setTextColor(ILI9341_BLACK);
- tft.setTextSize(3);
- tft.print(F("<-"));
- DateTime now = rtc.now();
- tft.setCursor(230, 232);
- tft.setTextSize(1);
- tft.print("Time");
- //tft.fillRect(270,232,50,20,ILI9341_WHITE);
- tft.setTextSize(1);
- tft.setTextColor(ILI9341_BLACK);
- tft.setCursor(270,232);
- tft.print(now.hour(),DEC);
- tft.print(":");
- tft.print(now.minute(), DEC);
- //tft.fillRoundRect(30,10, 70, 36, 5,ILI9341_BLACK);
- // tft.drawRoundRect(30,10,70,36,5,ILI9341_WHITE);
- for(int i = 0; i < 10; i++)
- {
- tft.drawLine(40, linie[i], 50, linie[i], ILI9341_WHITE);
- }
- //pomocnicze
- for(int i = 0; i < 9; i++)
- {
- tft.drawLine(40, linie[i]+10, 50, linie[i]+10, ILI9341_WHITE);
- }
- for(int i = 0; i < 10; i++)
- {
- tft.setCursor(25, (linie[i]- 3));
- tft.setTextColor(ILI9341_BLACK);
- tft.setTextSize(1);
- tft.println(wartosc[i]);
- }
- //tft.setCursor(30, 5);
- // tft.print("Temperature/Humidity");
- for(int pix=50; pix<320; pix++){
- unsigned int data[6];
- // Start I2C Transmission
- Wire.beginTransmission(Addr4);
- // Send 16-bit command byte
- Wire.write(0x2C);
- Wire.write(0x06);
- // Stop I2C transmission
- Wire.endTransmission();
- delay(100);
- Wire.beginTransmission(Addr4);
- Wire.endTransmission();
- // Request 6 bytes of data
- Wire.requestFrom(Addr4, 6);
- // temp msb, temp lsb, temp crc, hum msb, hum lsb, hum crc
- if (Wire.available() == 6)
- {
- data[0] = Wire.read();//MSB
- data[1] = Wire.read();//LSB
- data[2] = Wire.read();//CHECKSUM
- data[3] = Wire.read();
- data[4] = Wire.read();
- data[5] = Wire.read();
- }
- float TEMP = (data[0] * 256.0) + data[1];
- float f = -45.0 + (175.0 * TEMP / 65535.0);
- float h = ((100.0 * ((data[3] * 256.0) + data[4])) / 65535.0);
- tft.setTextColor(ILI9341_RED);
- tft.setCursor(220, 10);
- tft.setTextSize(1);
- tft.print("Temp: ");
- tft.setTextColor(ILI9341_RED);
- tft.print(f);
- tft.print("C");
- tft.setCursor(220, 25);
- tft.setTextColor(ILI9341_BLACK);
- tft.setTextSize(1);
- tft.print("Humidty: ");
- tft.setTextColor(ILI9341_BLACK);
- tft.print(h);
- tft.print("%");
- delay(1000);
- tft.fillRect(220, 10, 110, 50, ILI9341_GRAY);
- // int Gf = map(f, 0, 50, 0, tft.height);
- // int Gh = map(h, 0, 100, 0, tft.height-10);
- //int Gf = map(f, 0, 200, 0, 100);
- //int Gh = map(
- // tft.drawPixel(pix+1, 197-f, ILI9341_RED);
- // tft.drawPixel(pix+1, 187-h, ILI9341_GREEN);
- tft.drawPixel(pix+1, 251-(2*f), ILI9341_RED);
- tft.drawPixel(pix+1, 251-(2*h), ILI9341_BLACK);
- for (int i = 50; i < 320; i = i + 30)
- {
- tft.drawFastVLine(i, 50, 180, ILI9341_WHITE);
- }
- for (int i = 50; i < 320; i = i + 20)
- {
- tft.drawFastHLine(50, i, 320, ILI9341_WHITE);
- }
- }
- }
- void drawHome()
- {
- DateTime now = rtc.now();
- tft.fillScreen(ILI9341_WHITE);
- // put your setup code here, to run once:
- //Draw white frame
- tft.drawRect(0,0,319,240,ILI9341_BLACK);
- tft.setTextColor(ILI9341_BLACK);
- tft.setCursor(170,5);
- tft.setTextSize(2);
- tft.fillRect(80,5,95,30,ILI9341_WHITE);
- tft.print(now.year(),DEC);
- tft.print("/");
- tft.print(now.month(), DEC);
- tft.print("/");
- tft.print(now.day(), DEC);
- tft.drawLine(45,60,220,60, ILI9341_BLACK);
- tft.setCursor(45,40);
- tft.print(F("Data Logger"));
- //pomiary
- tft.fillRoundRect(45,80, 230, 40,5, ILI9341_WHITE);
- tft.drawRoundRect(45,80,230,40,5,ILI9341_BLACK);
- tft.setCursor(50 ,90);
- tft.setTextColor(ILI9341_BLACK);
- tft.setTextSize(3);
- tft.print(F("Measurements"));
- //wykres
- tft.fillRoundRect(45,130, 230, 40,5, ILI9341_WHITE);
- tft.drawRoundRect(45,130,230,40,5,ILI9341_BLACK);
- tft.setCursor(120,135);
- tft.setTextColor(ILI9341_BLACK);
- tft.setTextSize(3);
- tft.print(F("Graph"));
- //SD on/off
- tft.fillRoundRect(45,180, 230, 40,5, ILI9341_WHITE);
- tft.drawRoundRect(45,180,230,40,5,ILI9341_BLACK);
- tft.setCursor(100,190);
- tft.setTextColor(ILI9341_BLACK);
- tft.setTextSize(3);
- tft.print(F("SD Card"));
- }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy.