Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Credits: Simion Logos
- /*ST7735 TFT SPI display pins for Arduino Uno/Nano:
- * LED = 3.3V
- * SCK = 13
- * SDA = 11
- * A0 = 8
- * RESET = 9
- * CS = 10
- * GND = GND
- * VCC = 5V*/
- /* SPI pin names can be confusing. These are the alternative names for the SPI pins:
- MOSI = DIN = R/W = SDO = DI = SI = MTSR = SDA = D1 = SDI
- CS = CE = RS = SS
- DC = A0 = DO = DOUT = SO = MRST
- RESET = RST
- SCLK = CLK = E = SCK = SCL = D0*/
- #include <Adafruit_GFX.h>
- #include <Adafruit_ST7735.h>
- #define TFT_CS 10
- #define TFT_RST 8
- #define TFT_DC 9
- Adafruit_ST7735 tft = Adafruit_ST7735(TFT_CS, TFT_DC, TFT_RST);
- #include <Fonts/FreeSerif18pt7b.h>
- #include <Fonts/FreeSerifBoldItalic12pt7b.h>
- //Temperature sensor data
- #include "DHT.h" // Library for DHT sensors
- #define dhtPin 2 // data pin
- /*
- * Uncomment the correct DHT chip
- */
- #define dhtType DHT11 // DHT 11
- //#define dhtType DHT22 // DHT 22 (AM2302), AM2321
- //#define dhtType DHT21 // DHT 21 (AM2301)
- DHT dht(dhtPin, dhtType); // Initialise the DHT library
- float humidityVal; // humidity
- int tempValC; // temperature in degrees Celcius
- float tempValF; // temperature in degrees Fahrenheit
- float heatIndexC; // windchill in degrees Celcius
- float heatIndexF; // windchill in degrees Fahrenheit
- // Comment this whole code to use without temperature sensor
- String inputString = "";
- String cpuLoadString;
- String cpuTempString;
- String cpuClockString;
- String ramString;
- String gpuTempString;
- String gpuLoadString;
- String ramLoadString;
- String ramPerString;
- char buf[30];
- int cpuLoad;
- int cpuClock;
- int cpuTemp;
- int usedRam;
- int gpuTemp;
- int gpuLoad;
- int ramLoad;
- int ramPer;
- int totalRam = 16;
- int inp=0;
- //String gpuLoadString;
- //String gpuTempString;
- //int gpuLoad;
- //int gpuTemp;
- #define NUM_VAL (12+1)
- int tempTab[NUM_VAL];
- int loadTab[NUM_VAL];
- int clockTab[NUM_VAL];
- int ramTab[NUM_VAL];
- int i,v,ght=60-8-2;
- void setup() {
- // put your setup code here, to run once:
- tft.initR(INITR_BLACKTAB); // Initialize a ST7735S chip, black tab
- tft.fillScreen(ST7735_BLACK); //Fill screen with Black
- tft.setRotation(0); //Set rotation to display. Can be from 0 to 3
- tft.setTextWrap(false); // By default, long lines of text are set to automatically “wrap” back to the leftmost column.
- Serial.begin(9600);
- dht.begin(); // start with reading the DHT sensor //Comment this whole code to use without temperature sensor
- tft.setFont(); //set custom font
- tft.setCursor(20,55); //set position (x,y)
- tft.setTextColor(ST7735_YELLOW); //set color of text
- tft.setTextSize(1); //set text size. Can be from 0 to 20.
- tft.println("Please turn on"); //print the tex
- tft.setFont(); //set custom font
- tft.setCursor(25,65); //set position (x,y)
- tft.setTextColor(ST7735_YELLOW); //set color of text
- tft.setTextSize(1); //set text size. Can be from 0 to 20.
- tft.println("the program"); //print the tex
- delay(5000);
- tft.fillScreen(ST7735_BLACK);
- tft.setFont(); //set custom font
- tft.setCursor(20,55); //set position (x,y)
- tft.setTextColor(ST7735_YELLOW); //set color of text
- tft.setTextSize(1); //set text size. Can be from 0 to 20.
- tft.println("Connecting..."); //print the text
- delay(10000);
- }
- void loop() {
- // put your main code here, to run repeatedly:
- int tMC = digitalRead(2);
- int i = map(tMC, 0, 100,6, 116);
- while (Serial.available()) {
- char ch = (char)Serial.read();
- inputString += ch;
- if(ch == '|') { // full info chunk received
- int st,en;
- st = inputString.indexOf("CHC"); // CPU clock: "CHC1768"
- if(st>=0) {
- en = inputString.indexOf("|", st);
- cpuClockString = inputString.substring(st+3, en);
- cpuClock = cpuClockString.toInt();
- inp=3;
- } else {
- st = inputString.indexOf("R"); // used RAM: "R6.9"
- if(st>=0) {
- en = inputString.indexOf("|", st);
- ramString = inputString.substring(st+1 , en-1);
- st = ramString.indexOf(",");
- if(st>=0) ramString.setCharAt(st,'.');
- usedRam = ramString.toFloat()*1024;
- inp=2;
- }
- int cpuTempStart = inputString.indexOf("C"); // CPU temperature: "C52"
- int cpuLoadStart = inputString.indexOf("c"); // CPU load: "c18%"
- if(cpuLoadStart>=0 && cpuTempStart>=0) {
- en = inputString.indexOf("|");
- cpuTempString = inputString.substring(cpuTempStart+1, cpuLoadStart);
- cpuLoadString = inputString.substring(cpuLoadStart+1, en-1);
- cpuTemp = cpuTempString.toInt();
- cpuLoad = cpuLoadString.toInt();
- inp=1;
- }
- int gt,gr;
- int gpuTempStart = inputString.indexOf("G");
- int gpuLoadStart = inputString.indexOf("c");
- if (gpuLoadStart>=0 && gpuTempStart>=0){
- gt = inputString.indexOf("|");
- gpuTempString = inputString.substring(gpuTempStart+1, gpuLoadStart);
- gpuLoadString = inputString.substring(cpuLoadStart+1, en-1);
- gpuTemp = gpuTempString.toInt();
- gpuLoad = gpuLoadString.toInt();
- inp=1;
- }
- int gy, we;
- int ramLoadStart = inputString.indexOf("R");
- int ramLoadStop = inputString.indexOf("GB");
- if (ramLoadStart>=0 && ramLoadStop>=0){
- gy = inputString.indexOf("|");
- ramLoadString = inputString.substring(ramLoadStart + 1, ramLoadStop );
- ramLoad = ramLoadString.toFloat();
- }
- int re;
- int ramPStart = inputString.indexOf("L");
- int ramPStop = inputString.indexOf("|G");
- if (ramPStart>=0 && ramPStop>=0 ){
- re = inputString.indexOf("|");
- ramPerString = inputString.substring(ramPStart + 1, ramPStop - 2);
- ramPer = ramPerString.toInt();
- }
- inputString = "";
- return 1;
- }
- }
- }
- int percentageRam = (ramLoad*100)/totalRam;
- tft.fillScreen(ST7735_BLACK);
- tft.setFont(&FreeSerif18pt7b); //set custom font
- tft.setCursor(35,34); //set position (x,y)
- tft.setTextColor(ST7735_WHITE); //set color of text
- tft.setTextSize(1); //set text size. Can be from 0 to 20.
- tft.println("CPU"); //print the text
- tft.drawRect(6, 60, 116, 26, ST7735_WHITE); // Draw rectangle (x,y,width,height,color)
- // It draws from the location to down-right
- tft.setFont();
- tft.setCursor(6, 48);
- tft.setTextColor(ST7735_BLUE);
- tft.setTextSize(1);
- tft.println(" TEMPERATURE:");
- tft.setFont();
- tft.setCursor(85, 48);
- tft.setTextColor(ST7735_WHITE);
- tft.setTextSize(1);
- tft.println(cpuTemp);
- tft.fillRect(8, 62, cpuTemp, 22, ST7735_WHITE);
- tft.drawRect(6, 102, 116, 26, ST7735_WHITE);
- tft.setFont();
- tft.setCursor(6, 90);
- tft.setTextColor(ST7735_BLUE);
- tft.setTextSize(1);
- tft.println(" USAGE:");
- tft.setFont();
- tft.setCursor(50, 90);
- tft.setTextColor(ST7735_WHITE);
- tft.setTextSize(1);
- tft.println(cpuLoad);
- tft.fillRect(8, 104, cpuLoad, 22, ST7735_WHITE);
- delay(5000);
- tft.fillScreen(ST7735_BLACK);
- tft.setFont(&FreeSerif18pt7b); //set custom font
- tft.setCursor(35,34); //set position (x,y)
- tft.setTextColor(ST7735_WHITE); //set color of text
- tft.setTextSize(1); //set text size. Can be from 0 to 20.
- tft.println("GPU"); //print the text
- tft.drawRect(6, 60, 116, 26, ST7735_WHITE); // Draw rectangle (x,y,width,height,color)
- // It draws from the location to down-right
- tft.setFont();
- tft.setCursor(6, 48);
- tft.setTextColor(ST7735_BLUE);
- tft.setTextSize(1);
- tft.println(" TEMPERATURE:");
- tft.setFont();
- tft.setCursor(85, 48);
- tft.setTextColor(ST7735_WHITE);
- tft.setTextSize(1);
- tft.println(gpuTemp);
- tft.drawRect(6, 102, 116, 26, ST7735_WHITE);
- tft.fillRect(8, 62, gpuTemp, 22, ST7735_WHITE);
- tft.setFont();
- tft.setCursor(6, 90);
- tft.setTextColor(ST7735_BLUE);
- tft.setTextSize(1);
- tft.println(" USAGE:");
- tft.setFont();
- tft.setCursor(50, 90);
- tft.setTextColor(ST7735_WHITE);
- tft.setTextSize(1);
- tft.println(gpuLoad);
- tft.fillRect(8, 104, gpuLoad, 22, ST7735_WHITE);
- delay(5000);
- tft.fillScreen(ST7735_BLACK);
- tft.setFont(&FreeSerif18pt7b); //set custom font
- tft.setCursor(29,34); //set position (x,y)
- tft.setTextColor(ST7735_WHITE); //set color of text
- tft.setTextSize(1); //set text size. Can be from 0 to 20.
- tft.println("RAM"); //print the text
- tft.drawRect(6, 60, 116, 26, ST7735_WHITE); // Draw rectangle (x,y,width,height,color)
- tft.fillRect(8, 62, percentageRam, 22, ST7735_WHITE); // It draws from the location to down-right
- tft.setFont();
- tft.setCursor(6, 48);
- tft.setTextColor(ST7735_BLUE);
- tft.setTextSize(1);
- tft.println(" USAGE:");
- tft.setFont();
- tft.setCursor(85, 48);
- tft.setTextColor(ST7735_WHITE);
- tft.setTextSize(1);
- tft.println(ramLoadString);
- //tft.drawRect(6, 102, 116, 26, ST7735_WHITE);
- //tft.setFont();
- //tft.setCursor(6, 90);
- //tft.setTextColor(ST7735_BLUE);
- //tft.setTextSize(1);
- //tft.println(" USAGE:");
- delay(5000);
- tft.fillScreen(ST7735_BLACK);
- humidityVal = dht.readHumidity(); // get the humidity from the DHT sensor
- tempValC = dht.readTemperature(); // get the temperature in degrees Celcius from the DHT sensor
- tempValF = dht.readTemperature(true); // get the temperature in degrees Fahrenheit from the DHT sensor
- // Check if all values are read correctly, if not try again and exit loop()
- if (isnan(humidityVal) || isnan(tempValC) || isnan(tempValF)) {
- Serial.println("Reading DHT sensor failed!");
- // end the loop() function
- return;
- }
- // Calculate the windchill in degrees Celcius
- heatIndexC = dht.computeHeatIndex(tempValC, humidityVal, false);
- // Calculate the windchill in degrees Fahrenheit
- heatIndexF = dht.computeHeatIndex(tempValF, humidityVal);
- // Print all values to the serial monitor
- // \t prints a tab character, \n a newline
- Serial.print(humidityVal);
- Serial.print("\t");
- Serial.print(tempValC);
- Serial.print("\n");
- delay(10);
- tft.setFont(&FreeSerif18pt7b); //set custom font
- tft.setCursor(23,34); //set position (x,y)
- tft.setTextColor(ST7735_WHITE); //set color of text
- tft.setTextSize(1); //set text size. Can be from 0 to 20.
- tft.println("CASE"); //print the text
- tft.drawRect(6, 60, 116, 26, ST7735_WHITE); // Draw rectangle (x,y,width,height,color)
- // It draws from the location to down-right
- //tft.drawRect(7, 63, 18, 20, ST7735_WHITE);
- tft.setFont();
- tft.setCursor(6, 48);
- tft.setTextColor(ST7735_BLUE);
- tft.setTextSize(1);
- tft.println(" TEMPERATURE:");
- tft.setFont();
- tft.setCursor(85, 48);
- tft.setTextColor(ST7735_WHITE);
- tft.setTextSize(1);
- tft.println(tempValC);
- tft.fillRect(8, 62, tempValC *3, 22, ST7735_WHITE);
- //tft.setFont();
- //tft.setCursor(85, 64);
- //tft.setTextColor(ST7735_WHITE);
- //tft.setTextSize(1);
- //tft.println(cpuTemp);
- //
- //tft.setFont();
- //tft.setCursor(85, 75);
- //tft.setTextColor(ST7735_WHITE);
- //tft.setTextSize(1);
- //tft.println(cpuLoad);
- //tft.drawRect(6, 102, 116, 26, ST7735_WHITE);
- //tft.setFont();
- //tft.setCursor(6, 90);
- //tft.setTextColor(ST7735_BLUE);
- //tft.setTextSize(1);
- //tft.println(" USAGE:");
- delay(5000);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement