|
本帖最后由 wo116114 于 2021-10-12 16:23 编辑
以下是代码- <font _mstmutation="1">#include <Adafruit_GFX.h> // Core graphics library
- #include <Adafruit_ST7735.h>
- #include <SPI.h>
- #include <DHT.h>
- #define DHTPIN 12
- #define TFT_CS D1
- #define TFT_RST D2
- #define TFT_DC D3
- #define DHTTYPE DHT22
- DHT dht(DHTPIN, DHTTYPE);
- Adafruit_ST7735 tft = Adafruit_ST7735(TFT_CS, TFT_DC, TFT_RST);
- #define TFT_SCLK 13 // set these to be whatever pins you like!
- #define TFT_MOSI 11
- unsigned char quan[] = {0x00,0x00,0x00,0x44,0xA4,0xA8,0xA8,0xB0,0x54,0x1A,0x2A,0x2A,0x4A,0x44,0x00,0x00};
- unsigned char zhou[] = {0x10,0x04,0x10,0x84,0x10,0x84,0x10,0x84,0x10,0x84,0x54,0xA4,0x52,0x94,0x52,0x94,0x90,0x84,0x10,0x84,0x10,0x84,0x10,0x84,0x20,0x84,0x20,0x84,0x40,0x04,0x80,0x04};
- unsigned char wen[] = {0x00,0x00,0x23,0xF8,0x12,0x08,0x12,0x08,0x83,0xF8,0x42,0x08,0x42,0x08,0x13,0xF8,0x10,0x00,0x27,0xFC,0xE4,0xA4,0x24,0xA4,0x24,0xA4,0x24,0xA4,0x2F,0xFE,0x00,0x00};
- unsigned char du[] = {0x01,0x00,0x00,0x80,0x3F,0xFE,0x22,0x20,0x22,0x20,0x3F,0xFC,0x22,0x20,0x22,0x20,0x23,0xE0,0x20,0x00,0x2F,0xF0,0x24,0x10,0x42,0x20,0x41,0xC0,0x86,0x30,0x38,0x0E};
- unsigned char shi[] = {0x00,0x00,0x27,0xF8,0x14,0x08,0x14,0x08,0x87,0xF8,0x44,0x08,0x44,0x08,0x17,0xF8,0x11,0x20,0x21,0x20,0xE9,0x24,0x25,0x28,0x23,0x30,0x21,0x20,0x2F,0xFE,0x00,0x00};
- unsigned char wendu[] = {0x60,0x00,0x91,0xF4,0x96,0x0C,0x6C,0x04,0x08,0x04,0x18,0x00,0x18,0x00,0x18,0x00,0x18,0x00,0x18,0x00,0x18,0x00,0x08,0x00,0x0C,0x04,0x06,0x08,0x01,0xF0,0x00,0x00};
- unsigned char re[] = {0x10,0x40,0x10,0x40,0x10,0x40,0xFD,0xF8,0x10,0x48,0x10,0x48,0x1C,0xC8,0x30,0x48,0xD0,0xAA,0x10,0xAA,0x51,0x06,0x22,0x02,0x00,0x00,0x48,0x88,0x44,0x44,0x84,0x44};
- unsigned char zhi[] = {0x11,0x00,0x11,0x04,0x11,0x38,0x11,0xC0,0xFD,0x02,0x11,0x02,0x10,0xFE,0x14,0x00,0x19,0xFC,0x31,0x04,0xD1,0x04,0x11,0xFC,0x11,0x04,0x11,0x04,0x51,0xFC,0x21,0x04};
- unsigned char shu[] = {0x08,0x20,0x49,0x20,0x2A,0x20,0x08,0x3E,0xFF,0x44,0x2A,0x44,0x49,0x44,0x88,0xA4,0x10,0x28,0xFE,0x28,0x22,0x10,0x42,0x10,0x64,0x28,0x18,0x28,0x34,0x44,0xC2,0x82};
- void setup() {
- // put your setup code here, to run once:
- tft.initR(INITR_144GREENTAB);
- //tft.fillScreen(ST7735_BLACK);
- Serial.println("init");
- Serial.begin(9600);
- Serial.println(F("DHTxx test!"));
- dht.begin();
- }
- void printChinese(uint x,uint y,unsigned char *Hz_code)
- {
- int tbl_size=sizeof(Hz_code)/sizeof(char);
- short int temp_code=0;
- int i,j,k;
- for(i=0;i<16;i++)
- for(j=0;j<2;j++)
- for(k=0;k<8;k++)
- if(((Hz_code[i*2+j]>>(7-k))&0x1)!=NULL)
- //}
- tft.drawPixel(x+8*j+k,y+i, ST7735_RED);
- }
- void loop() {
- delay(2000);
- /*tft.setCursor(39,20);
- tft.setTextPadding();
- tft.setCursor(39,0);
- tft.setTextPadding();
- tft.setCursor(55,40);
- tft.setTextPadding();*/
- // tft.setTextWrap(true);
- tft.fillScreen(ST7735_BLACK);
- // Reading temperature or humidity takes about 250 milliseconds!
- // Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)
- float h = dht.readHumidity();
- // Read temperature as Celsius (the default)
- float t = dht.readTemperature();
- // Read temperature as Fahrenheit (isFahrenheit = true)
- float f = dht.readTemperature(true);
- // Check if any reads failed and exit early (to try again).
- if (isnan(h) || isnan(t) || isnan(f)) {
- Serial.println(F("Failed to read from DHT sensor!"));
- return;
- }
- float hif = dht.computeHeatIndex(f, h);
- // Compute heat index in Celsius (isFahreheit = false)
- float hic = dht.computeHeatIndex(t, h, false);
- tft.setTextColor(ST7735_GREEN);
- tft.setTextSize(2);
- Serial.print(F("Humidity: "));
- Serial.print(h);
- Serial.print(F("% Temperature: "));
- Serial.print(t);
- Serial.print(F("°C "));
- Serial.print(f);
- Serial.print(F("°F Heat index: "));
- Serial.print(hic);
- Serial.print(F("°C "));
- Serial.print(hif);
- Serial.println(F("°F"));
- tft.setCursor(39,20);
- tft.print(h);
- tft.setCursor(39,0);
- tft.print(t);
- tft.setCursor(101,20);
- tft.print("%");
- tft.setCursor(55,40);
- tft.print(hic);
- // Serial.println(tft.getRotation(), DEC);
- //tft.WindowMax(0,30,16,46);
- tft.setCursor(0, 0);
- printChinese(4,0,wen);
- printChinese(20,0,du);
- printChinese(4,20,shi);
- printChinese(20,20,du);
- printChinese(100,0,wendu);
- printChinese(4,40,re);
- printChinese(20,40,zhi);
- printChinese(36,40,shu);
- printChinese(114,40,wendu);</font>
- }
复制代码 目前无法解决屏幕数字重影只能用黑色背景覆盖求解决另外dht22温湿度传感器无法显示负温度会溢出
大神们是怎么写的
|
|