Kezdo vagyok a legkezdobbek kozul
Van egy olyan problemam, hogy ha nem az alap karakter keszletet hasznalom akkor nem frissul az ertek az TFT-n hanem rairja magat az elozo ertekre.
Segitseget megkoszonom
Kód: Egész kijelölése
// begin
#include <Adafruit_GFX.h> // include Adafruit graphics library
#include <Adafruit_ST7735.h> // include Adafruit ST7735 TFT library
#include <DHT.h> // include DHT library
#include <Fonts/FreeMonoBoldOblique24pt7b.h>
// define pins nano uno
#define TFT_RST 8 // TFT RST pin is connected to arduino pin 8
#define TFT_CS 9 // TFT CS pin is connected to arduino pin 9
#define TFT_DC 10 // TFT DC/A0 pin is connected to arduino pin 10
// TFT SCK pin is connected to arduino pin 13
// TFT SDA pin is connected to arduino pin 11
// define ledPins
#define ledPin A1
#define ledPinN A2
#define ledPinC A3
#define BLACK 0x0000
#define WHITE 0xFFFF
#define RED 0xF800
#define BLUE 0x001F
#define ORANGE 0xff8000
// initialize ST7735 TFT library
Adafruit_ST7735 tft = Adafruit_ST7735(TFT_CS, TFT_DC, TFT_RST);
#define DHTPIN A0 // DHT11 data pin is connected to Arduino analog pin 1
#define DHTTYPE DHT11 // DHT11 sensor is used
float temp; //Stores temperature value
DHT dht11(DHTPIN, DHTTYPE); // initialize DHT library
void setup(void)
{
pinMode(A1, OUTPUT); // sets the digital pin A1 as output
pinMode(A2, OUTPUT); // sets the digital pin A2 as output
pinMode(A3, OUTPUT); // sets the digital pin A3 as output
tft.initR(INITR_BLACKTAB); // initialize a ST7735S chip, black tab
tft.setRotation(3);
tft.fillScreen(ST7735_BLACK); // fill screen with black color
tft.setCursor(57, 70); // move cursor to position
tft.print("");
delay(5000);
tft.fillScreen(ST7735_BLACK); // fill screen with black color
tft.drawRoundRect(0, 0, 160, 128, 6, ST7735_WHITE); // draw circle
delay(1000);
tft.setTextSize(2); // text size = 1
tft.setTextColor(ST7735_RED, ST7735_BLACK); // set text color to green and black background
tft.setCursor(35, 9); // move cursor to position
tft.print("TEMP");
tft.setTextSize(2); // text size = 2
// initialize DHT11 sensor
dht11.begin();
// initialize serial communications:
Serial.begin(9600);
}
char _buffer[7];
// main loop
void loop()
{
// read humidity
byte humi = dht11.readHumidity();
// read temperature
byte temp = dht11.readTemperature();
// print temperature (in °C)
sprintf(_buffer, "%02u", temp);
tft.setTextColor(ST7735_WHITE, ST7735_BLACK); // set text color to red and black background
tft.setFont(&FreeMonoBoldOblique24pt7b);
tft.setTextSize(2);
tft.setCursor(27, 98);
tft.print(_buffer);
tft.setFont();
tft.setTextSize(1);
tft.drawCircle(147, 93, 1, ST7735_WHITE); // print degree symbol ( ° )
tft.setCursor(149, 95);
tft.print("C");
delay(1000); // wait a second
// print humidity (in %)
sprintf(_buffer, "%02u%%", humi);
tft.setTextColor(ST7735_CYAN, ST7735_BLACK); // set text color to cyan and black background
tft.setTextSize(1);
tft.setCursor(37, 116);
tft.print(_buffer);
tft.setCursor(7, 116);
tft.print("H:");
tft.setTextColor(ST7735_ORANGE, ST7735_BLACK); // set text color to cyan and black background
tft.setTextSize(1);
tft.setCursor(83, 116);
tft.print("E:");
delay(1000); // wait a second
// if the analog value is high enough, turn on the LED:
if (temp >= 33) {
tft.setCursor(125, 116);
tft.setTextSize(1);
tft.setTextColor(ST7735_RED, ST7735_BLACK); // set text color to red and black background
tft.print("HOT");
delay (1000);
digitalWrite(ledPin, LOW);
digitalWrite(ledPinN, HIGH);
digitalWrite(ledPinC, HIGH);
}
else if (temp < 27) {
tft.setCursor(125, 116);
tft.setTextSize(1);
tft.setTextColor(ST7735_BLUE, ST7735_BLACK); // set text color to red and black background
tft.print("COLD");
delay (1000);
digitalWrite(ledPin, HIGH);
digitalWrite(ledPinN, HIGH);
digitalWrite(ledPinC, LOW);
}
else {
tft.setCursor(125, 116);
tft.setTextSize(1);
tft.setTextColor(ST7735_GREEN, ST7735_BLACK); // set text color to red and black background
tft.print("OK ");
delay (1000);
digitalWrite(ledPin, HIGH);
digitalWrite(ledPinN, LOW);
digitalWrite(ledPinC, HIGH);
}
// print the analog value:
Serial.println(_buffer);
delay(1000); // delay in between reads for stability
}
// end of code.