//ttgo display ST7789V IPS LCD Resolution: 135 x 240
#include "Free_Fonts.h"
#include <TFT_eSPI.h>
#include <SPI.h> // this is needed for display
// The display also uses hardware SPI, plus #9 & #10
#define TFT_CS 15
#define TFT_DC 2
#define TFT_MOSI 23
#define TFT_SCLK 18
float dispTemp = 22.3;
TFT_eSPI tft = TFT_eSPI(); // Invoke custom library with default width and height
void setup(void) {
tft.begin();
tft.setRotation(1);
tft.fillScreen(TFT_BLACK);
//tft.setFreeFont(FMB18);
//80x60pix digiGauge(xpos,ypos,onlyvalue,value,minvalue,maxvalue,minwarn,maxwarn,label,units,valuesample,valuetype,accuracy)
digiGauge(0, 0, false, dispTemp,dispTemp-10,dispTemp+10,dispTemp+5, dispTemp+15, "TEMP", "`C", 1);
//digiGauge(0, 66, false, dispTemp, "XTEMP", "`F", "88.88", "temp", 1);
//digiGauge(120, 0, false, dispTemp, "TEMP", "`C", "888", "temp", 0);
//digiGauge(120,66, false, dispTemp, "TEMP", "`C", "88.88", "temp", 2);
tft.drawRect(0,0,239,134,TFT_WHITE);
}
void loop() {
for(int index = 0; index <= 100; index++)
{
digiGauge(0, 0, true, index,index-10,index+10,dispTemp+5, dispTemp+15, "TEMP", "`C", 1);
/*
digiGauge(0, 0, true, index, "TEMP", "`C", "888.8", "temp", 1);
digiGauge(0, 66, true, index, "XTEMP", "`F", "88.88", "temp", 1);
digiGauge(120, 0, true, index, "TEMP", "`C", "888", "temp", 0);
digiGauge(120,66, true, index, "TEMP", "`C", "88.88", "temp", 2); */
}
delay(150);
}
void digiGauge(unsigned int xpos, unsigned int ypos,boolean onlyvalue, float value, float minvalue, float maxvalue,float minwarn,float maxwarn,const String& label, const String& units, unsigned int accuracy) {
int yPad = 1;
int xsize = 240;
int ysize = 132;
int fontheight = tft.fontHeight(FONT4);
unsigned int bgcolor = TFT_BLACK;
unsigned int labelcolor = TFT_YELLOW;
unsigned int valuecolor = TFT_WHITE;
int padding = tft.textWidth(String(value, accuracy), FONT8);
if (!onlyvalue) {
tft.fillRect(xpos, ypos, xsize, ysize, bgcolor);
tft.drawRect(xpos, ypos, xsize, ysize, labelcolor);
tft.setTextColor(labelcolor, bgcolor);
tft.setTextDatum(TL_DATUM);
tft.drawString(label, xpos + 2, ypos + 2, FONT4);
tft.setTextDatum(TR_DATUM);
tft.drawString(units, xsize + xpos -2, ypos + 2, FONT4);
}
ypos += fontheight + yPad;
if (onlyvalue) {
tft.fillRect(xpos +1, ypos, xsize - 2, tft.fontHeight(FONT8)+ fontheight, TFT_GREEN);
}
tft.setTextColor(valuecolor, bgcolor);
tft.setTextDatum(BL_DATUM);
tft.drawFloat(minvalue, accuracy, xpos + 2, ypos + ysize - fontheight - 2, FONT4);
tft.setTextDatum(BR_DATUM);
tft.drawFloat(maxvalue, accuracy, xpos + xsize - 2, ypos + ysize - fontheight - 2, FONT4);
tft.setTextColor(valuecolor, bgcolor);
if (value < minwarn || value> maxwarn) {
tft.setTextColor(bgcolor, valuecolor);
}
tft.setTextDatum(TL_DATUM);
tft.setTextPadding(padding);
tft.drawFloat(value, accuracy, xpos+(xsize - padding) / 2, ypos, FONT8);
tft.setTextPadding(0);
delay(100);
}
void digiGauge4(unsigned int xpos, unsigned int ypos,boolean onlyvalue, float value, const String& label, const String& units, const String& valueSample, const String& valueType, unsigned int accuracy) {
int yPad = 1;
int xsize = 120;
int ysize = 66;
unsigned int bgcolor = TFT_BLACK;
unsigned int labelcolor = TFT_YELLOW;
unsigned int valuecolor = TFT_WHITE;
int padding = tft.textWidth(String(value, accuracy), FONT6);
if (!onlyvalue) {
tft.fillRect(xpos, ypos, xsize, ysize, bgcolor);
tft.drawRect(xpos, ypos, xsize, ysize, labelcolor);
tft.setTextColor(labelcolor, bgcolor);
tft.setTextDatum(TL_DATUM);
tft.drawString(label, xpos + 2, ypos + 2, FONT2);
tft.setTextDatum(TR_DATUM);
tft.drawString(units, xsize + xpos -2, ypos + 2, FONT2);
}
ypos += tft.fontHeight(FONT2) + yPad;
if (onlyvalue) {
tft.fillRect(xpos +1, ypos, xsize - 2, tft.fontHeight(FONT6), TFT_GREEN);
}
tft.setTextColor(valuecolor, bgcolor);
tft.setTextDatum(TL_DATUM);
tft.setTextPadding(padding);
tft.drawFloat(value, accuracy, xpos+(xsize - padding) / 2, ypos, FONT6);
tft.setTextPadding(0);
delay(100);
}
void digiGauge80x60(unsigned int xpos, unsigned int ypos,boolean onlyvalue, float value, const String& label, const String& units, const String& valueSample, const String& valueType, unsigned int accuracy) {
int yPad = 10;
int xsize = 80;
int ysize = 60;
unsigned int bgcolor = TFT_BLACK;
unsigned int labelcolor = TFT_YELLOW;
unsigned int valuecolor = TFT_WHITE;
int padding = tft.textWidth(String(value, accuracy), FONT4);
if (!onlyvalue) {
tft.fillRect(xpos, ypos, xsize, ysize, bgcolor);
tft.drawRect(xpos, ypos, xsize, ysize, labelcolor);
tft.setTextColor(labelcolor, bgcolor);
tft.setTextDatum(TL_DATUM);
tft.drawString(label, xpos + 2, ypos + 2, FONT2);
tft.setTextDatum(TR_DATUM);
tft.drawString(units, xsize + xpos -2, ypos + 2, FONT2);
}
ypos += tft.fontHeight(FONT4) / 2 + yPad;
if (onlyvalue) {
tft.fillRect(xpos +1, ypos + 1, xsize - 2, tft.fontHeight(FONT4), TFT_GREEN);
}
tft.setTextColor(valuecolor, bgcolor);
tft.setTextDatum(TL_DATUM);
tft.setTextPadding(padding);
tft.drawFloat(value, accuracy, xpos+(xsize - padding) / 2, ypos, FONT4);
tft.setTextPadding(0);
delay(100);
}