//Panos Papazoglou //Microdev.gr 2023 #include #include #include #include #include #define TFT_CS 10 #define TFT_RST 9 #define TFT_DC 8 #define TFT_CS2 7 #define TFT_RST2 6 #define TFT_DC2 5 #define DHTPIN 4 #define DHTTYPE DHT11 DHT dht(DHTPIN, DHTTYPE); //Left TFT tft[0] //right TFT tft[1] Adafruit_ST7735 tft[]={Adafruit_ST7735(TFT_CS, TFT_DC, TFT_RST), Adafruit_ST7735(TFT_CS2, TFT_DC2, TFT_RST2)}; String labels[2][7]={{"60", "50", "40","30", "20", "10","0"}, {"100", "83", "67","50", "33", "16","0"}}; int rad=55; int rr=5; void setup(void) { //initialize TFTs for(int i=0;i<=1;i++) { tft[i].initR(INITR_144GREENTAB); tft[i].fillScreen(ST7735_BLACK); } //Initialize DHT11 dht.begin(); draw_circle(0,63,120,rad-3,6.28,3.14,-0.02, ST7735_WHITE); draw_circle(1,63,120,rad-3,6.28,3.14,-0.02, ST7735_WHITE); draw_dots(0,63,120,rad-3,6.28,3.14,-0.5); draw_dots(1,63,120,rad-3,6.28,3.14,-0.5); draw_scales(13); draw_labels(0,0,63,120,rad+9,6.28,3.14,-0.5); draw_labels(1,1,63,120,rad+9,6.28,3.14,-0.5); } void draw_scales(int w) { for(int v=1;v<=w;v++) { draw_circle(0,63,120,rad+v,6.28,5.495,-0.005, ST7735_RED); draw_circle(0,63,120,rad+v,5.495,4.71,-0.005, ST7735_YELLOW); draw_circle(0,63,120,rad+v,4.71,3.925,-0.005, ST7735_GREEN); draw_circle(0,63,120,rad+v,3.925,3.14,-0.005, ST7735_BLUE); draw_circle(1,63,120,rad+v,6.28,4.71,-0.005, ST7735_YELLOW); draw_circle(1,63,120,rad+v,4.71,3.14,-0.005, ST7735_GREEN); } } void loop() { float h=dht.readHumidity(); float t=dht.readTemperature(); //left TFT float topx=(t/10)*0.5+3.28; int ntft=0; tft[ntft].drawLine(63,120,63+(rad-rr)*cos(topx), 120+(rad-rr)*sin(topx),ST7735_BLUE); tft[ntft].drawLine(63,120,63+(rad+1-rr)*cos(topx), 120+(rad-rr)*sin(topx),ST7735_BLUE); tft[ntft].drawLine(63,120,63+(rad-1-rr)*cos(topx), 120+(rad-rr)*sin(topx),ST7735_BLUE); mytext(ntft,"MICRODEV.GR",1,32,0,ST7735_GREEN); mytext(ntft,"TEMP",2,40,17,ST7735_YELLOW); mytext(ntft,String(t),2,30,35,ST7735_WHITE); tft[ntft].drawCircle(92,35,2,ST7735_WHITE); mytext(ntft,"C",2,97,35,ST7735_WHITE); //right TFT topx=(h/16.6)*0.5+3.28; ntft=1; tft[ntft].drawLine(63,120,63+(rad-rr)*cos(topx), 120+(rad-rr)*sin(topx),ST7735_BLUE); tft[ntft].drawLine(63,120,63+(rad+1-rr)*cos(topx), 120+(rad-rr)*sin(topx),ST7735_BLUE); tft[ntft].drawLine(63,120,63+(rad-1-rr)*cos(topx), 120+(rad-rr)*sin(topx),ST7735_BLUE); mytext(ntft,"MICRODEV.GR",1,32,0,ST7735_GREEN); mytext(ntft,"HUMI",2,40,17,ST7735_YELLOW); mytext(ntft,String(h),2,30,35,ST7735_WHITE); mytext(ntft,"%",2,95,35,ST7735_WHITE); delay(5000); for(int i=0;i<=1;i++) { tft[i].drawLine(63,120,63+(rad-rr)*cos(topx), 120+(rad-rr)*sin(topx),ST7735_BLACK); tft[i].drawLine(63,120,63+(rad+1-rr)*cos(topx), 120+(rad-rr)*sin(topx),ST7735_BLACK); tft[i].drawLine(63,120,63+(rad-1-rr)*cos(topx), 120+(rad-rr)*sin(topx),ST7735_BLACK); tft[i].fillRect(30,10,100,42,ST7735_BLACK); } } void draw_circle(int ntft, int x, int y, int rad, float from, float to, float step, int color) { for(float i=from;i>=to;i+=step) { float xx=x+rad*cos(i); float yy=y+rad*sin(i); tft[ntft].drawPixel(xx, yy,color); } } void draw_s1(int ntft, int x, int y, int rad, float from, float to, float step) { for(float i=from;i>=to;i+=step) { float xx=x+rad*cos(i); float yy=y+rad*sin(i); tft[ntft].drawPixel(xx, yy,ST7735_WHITE); } } void draw_dots(int ntft, int x, int y, int rad, float from, float to, float step) { for(float i=from;i>=to;i+=step) { float xx=x+rad*cos(i); float yy=y+rad*sin(i); tft[ntft].fillCircle(xx,yy,2,ST7735_WHITE); } } void draw_labels(int ntft, int labn, int x, int y, int rad, float from, float to, float step) { int lab=0; for(float i=from;i>=to;i+=step) { float xx=x+rad*cos(i); float yy=y+rad*sin(i); mytext(ntft,labels[labn][lab],1,xx-5,yy,ST7735_BLACK); lab++; } } void mytext(int ntft, String text, int textsize, int x, int y, int mycolor) { tft[ntft].setTextSize(textsize); tft[ntft].setTextColor(mycolor); tft[ntft].setCursor(x,y); tft[ntft].print(text); }