Advertisement
learnelectronics

TFT-LCD .96in test

Oct 5th, 2019
6,585
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.07 KB | None | 0 0
  1. #include <UTFT.h>                                       //TFT library
  2. #include <Wire.h>                                       //I2C library
  3. #include <Adafruit_Sensor.h>                            //"Tweaked" sensor library
  4. #include <Adafruit_BME280.h>                            //"tweaked" bme sensor library
  5.  
  6. extern uint8_t SmallFont[];                             //set font size for the display
  7. #define SEALEVELPRESSURE_HPA (1013.25)                  //set local pressure
  8.  
  9. UTFT myGLCD(ST7735S_4L_80160,11,13,10,8,9);             //initialize the TFT
  10. Adafruit_BME280 bme;                                    //initialize the bme sensor
  11.  
  12. void setup()
  13. {
  14.  
  15.   myGLCD.InitLCD();                                     //begin the tft
  16.   myGLCD.setFont(SmallFont);                            //set font size
  17.   bme.begin();                                          //begin the bme
  18. }
  19.  
  20.  
  21. void loop()
  22. {
  23.  
  24. String tmp = (bme.readTemperature());                   //get the temp string from the sensor
  25. String prs = (bme.readPressure() / 100.0F);             // get pressure string
  26. String hum = (bme.readHumidity());                      // get hunidity string
  27.  
  28.     myGLCD.clrScr();                                    //clear the screen
  29.  
  30.     myGLCD.fillScr(0, 0, 0);                            //fill the screen black as my ex-wife's soul
  31.   myGLCD.setColor(255, 0, 0);                           //set color red
  32.   myGLCD.fillRoundRect(10, 17, 149, 72);                //draw a box w/ round corners from 10,17 to 149,72
  33.  
  34.   myGLCD.setColor(255, 255, 255);                       //set text color WHITE
  35.   myGLCD.setBackColor(255, 0, 0);                       // set BKG color RED
  36.   myGLCD.print(tmp, CENTER, 20);                        //print the temperatue in white with red bkg, centered on line 20
  37.   myGLCD.setColor(0, 255, 0);
  38.   myGLCD.setBackColor(255, 0, 0);
  39.   myGLCD.print(prs , CENTER, 45);
  40.   myGLCD.setColor(0, 0, 255);
  41.   myGLCD.setBackColor(255, 0, 0);
  42.   myGLCD.print(hum, CENTER, 57);
  43.  
  44.  
  45.  
  46.   delay (5000);                                         //wait 5 seconds and do it again
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement