Mini Arduino miljön bildskärm ** uppdatering - lagt till RTC *** (6 / 14 steg)
Steg 6: Sista steget, visar Sensor Data på TFT
Denna skiss skapades med hjälp av koden från både adafruit och virtuabotix prov skisser
Du kan använda någon (4 eller) 5 stift
#define sclk 4
#define mosi 5
#define cs 6
#define dc 7
#define rst 8 / / du kan också ansluta detta till Arduino Återställ
#define ANALOG_IN 0 / / för CD-skivor ljus sensor
#include < Adafruit_GFX.h > / / Core grafik bibliotek
#include < Adafruit_ST7735.h > / / maskinvaruspecifika bibliotek
#include < SPI.h >
#include < dht11.h > / / dht temp luftfuktighet sensor bibliotek
dht11 DHT11;
Adafruit_ST7735 tft = Adafruit_ST7735 (cs, dc, mosi, sclk, rst);
void setup(void) {
DHT11.attach(2); ställa in digital port 2 till känsla dht ingång
Serial.BEGIN(9600);
Serial.Print("Hello!");
tft.initR(INITR_BLACKTAB); initiera en ST7735S chip, svart flik
Serial.println("init");
tft.setRotation(tft.getRotation()+1); avkommentera rotera displayen
få tid att Visa "sensor upp tid"
uint16_t tid = millis();
tft.fillScreen(ST7735_BLACK);
tid = millis() - tid.
Serial.println (tid, DEC);
Delay(500);
Serial.println("Done");
Delay(1000);
tftPrintTest();
Delay(500);
tft.fillScreen(ST7735_BLACK);
Välkomstskärmen för estetiska ändamål endast
optimerad linjer
testfastlines (ST7735_RED, ST7735_BLUE);
Delay(500);
testdrawrects(ST7735_GREEN);
Delay(500);
tft.fillScreen(ST7735_BLACK);
}
void loop() {
tft.invertDisplay(true);
Delay(500);
tft.invertDisplay(false);
tft.setTextColor(ST7735_WHITE);
tft.setCursor(0,0);
TFT.println ("skiss har varit");
TFT.println ("kör för:");
tft.setCursor (50, 20);
tft.setTextSize(2);
tft.setTextColor(ST7735_BLUE);
TFT.Print(Millis() / 1000);
tft.setTextSize(1);
tft.setCursor (40, 40);
tft.setTextColor(ST7735_WHITE);
TFT.println("seconds");
tft.setCursor (0, 60);
tft.drawLine (0, 50, tft.width ()-1, 50, ST7735_WHITE); Rita linjen avgränsare
tft.setTextColor(ST7735_YELLOW);
TFT.Print ("Temperature (C):");
tft.setTextColor(ST7735_GREEN);
TFT.println((float)DHT11.temperature,1);
tft.setTextColor(ST7735_WHITE);
TFT.Print ("luftfuktighet (%):");
tft.setTextColor(ST7735_RED);
TFT.println((float)DHT11.humidity,1);
tft.setTextColor(ST7735_YELLOW);
TFT.Print ("temperatur (F):");
tft.setTextColor(ST7735_GREEN);
TFT.println(DHT11.Fahrenheit(), 1);
tft.setTextColor(ST7735_YELLOW);
TFT.Print ("temperatur (K):");
TFT.Print("");
tft.setTextColor(ST7735_GREEN);
TFT.println(DHT11.Kelvin(), 1);
tft.setTextColor(ST7735_WHITE);
TFT.Print ("Dew Point (C):");
tft.setTextColor(ST7735_RED);
TFT.println(DHT11.dewPoint(), 1);
tft.setTextColor(ST7735_WHITE);
TFT.Print("DewPointFast(C):");
tft.setTextColor(ST7735_RED);
TFT.println(DHT11.dewPointFast(), 1);
tft.drawLine (0, 110, tft.width ()-1, 110, ST7735_WHITE);
tft.setCursor(0,115);
TFT.Print ("ljusstyrka");
int val = analogRead(ANALOG_IN);
tft.setCursor (60, 130);
tft.setTextColor(ST7735_YELLOW);
TFT.println (val, 1);
Delay(2000);
tft.fillScreen(ST7735_BLACK);
}
void tftPrintTest() {
tft.setTextWrap(false);
tft.fillScreen(ST7735_BLACK);
tft.setCursor (0, 60);
tft.setTextColor(ST7735_RED);
tft.setTextSize(2);
TFT.println("temperature");
tft.setTextColor(ST7735_YELLOW);
tft.setTextSize(2);
TFT.println("humidity");
tft.setTextColor(ST7735_GREEN);
tft.setTextSize(2);
TFT.println("Monitor");
tft.setTextColor(ST7735_BLUE);
tft.setTextSize(3);
TFT.Print(3598865);
Delay(500);
}
void testfastlines (uint16_t color1, uint16_t color2) {
tft.fillScreen(ST7735_BLACK);
för (int16_t y = 0; y < tft.height(); y += 5) {
tft.drawFastHLine (0, y, tft.width(), color1);
}
för (int16_t x = 0; x < tft.width(); x+= 5) {
tft.drawFastVLine (x, 0, tft.height(), color2);
}
}
void testdrawrects (uint16_t färg) {
tft.fillScreen(ST7735_BLACK);
för (int16_t x = 0; x < tft.width(); x+= 6) {
tft.drawRect (tft.width () / 2 - x / 2, (tft.height) / 2 - x / 2, x, x, färg);
}
}