Hello im trying to figure out how to keep my TFT LCD from blinking with my delay settings in my sketch.
/* Evan S Gray
*
*/
// Libraries to include
#include "SPI.h"
#include "Adafruit_GFX.h"
#include "Adafruit_ILI9341.h"
#include "DHT.h"
// Define pins For the Adafruit TFT shield, these are the default.
#define TFT_DC 9
#define TFT_CS 10
// what pin DHT sensor is connected to
#define DHTPIN 30
// what type of DHT sensor
#define DHTTYPE DHT11 // DHT 11
DHT dht(DHTPIN, DHTTYPE);
// Color definitions
#define BLACK 0x0000
#define BLUE 0x001F
#define RED 0xF800
#define GREEN 0x07E0
#define CYAN 0x07FF
#define MAGENTA 0xF81F
#define YELLOW 0xFFE0
#define WHITE 0xFFFF
// Use hardware SPI (on Uno, #13, #12, #11) and the above for CS/DC
Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC);
// If using the breakout, change pins as desired
// Fan relay pin
const byte fanPin = 31;
// Water relay pin
const byte waterPin = 32;
void setup() {
// Begin Serial Comm
Serial.begin(9600);
// Begin DHT11
dht.begin();
// Begin TFT
tft.begin();
// Set the pinMode to output for the Fan relay control pin
pinMode(fanPin, OUTPUT);
// Set the pinMode to output for the Water relay control pin
pinMode(waterPin, OUTPUT);
//set screen rotation
tft.setRotation(1);
//fill screen black
tft.fillScreen(BLACK);
//set text wrap
tft.setTextWrap(true);
// Display text
tft.setCursor(0, 0);
tft.setTextColor(WHITE);
tft.setTextSize(1);
tft.println("Hello World!");
tft.setTextColor(RED);
tft.setTextSize(2);
tft.println("Welcome to the first");
tft.setTextColor(GREEN);
tft.setTextSize(3);
tft.println("Version of our Watering");
tft.setTextColor(BLUE);
tft.setTextSize(4);
tft.println("System");
delay(4000);
tft.fillScreen(BLACK);
}
// the loop routine runs over and over again forever:
void loop()
{
// Reading temperature or humidity takes about 250 milliseconds!
// Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)
int h = dht.readHumidity();
int t = dht.readTemperature();
// check if returns are valid, if they are NaN (not a number) then something went wrong!
if (isnan(t) || isnan(h)) {
Serial.println("Failed to read from DHT");
} else {
// Uncomment these lines if you prefer to use the Fahrenheit scale
// instead of Celsius. Remember to change line 44 so that the
// symbol is "F" instead of "C"
int fahrenheitTemp = t * 9.0/5.0+32.0;
if (fahrenheitTemp >= 80)
{
digitalWrite(fanPin, HIGH); // turn on relay
}
else if (fahrenheitTemp <= 75)
{
digitalWrite(fanPin, LOW); // turn off relay
}
Serial.print("Temperature: ");
Serial.print(fahrenheitTemp);
Serial.println(" F");
Serial.print("Humidity: ");
Serial.print(h);
Serial.print(" %\t");
// read the input on analog pin 10
int sensorValue = analogRead(A10); //get current sensorValue between 0-1000
int Voltage = sensorValue*(5.0/1024.0); //convert sensorValue to voltage 0-5v
float pH = (Voltage*3.56)-1.889; //convert voltage to pH
// Read the input on analog pin 15
int waterSensor = analogRead(A15);
// Water sensor relay control
if (waterSensor <= 1000)
{
digitalWrite(waterPin, HIGH); // turn on relay
}
else if (waterSensor >= 500)
{
digitalWrite(waterPin, LOW); // turn off relay
}
// print out the value for pH
Serial.println("pH");
Serial.println(pH);
Serial.println("Voltage");
Serial.println(Voltage);
Serial.println("Sensor");
Serial.println(sensorValue);
Serial.println("Water Sensor");
Serial.println(waterSensor);
// print header
tft.setCursor(1,0);
tft.setTextSize(3);
tft.setTextColor(WHITE);
tft.println("GrayMatter");
tft.setCursor(25,25);
tft.println("Growers");
tft.drawRoundRect(210,10,90,45,25,WHITE);
tft.setCursor(230,15);
tft.setTextSize(2);
tft.setTextColor(WHITE);
tft.println("pH =");
tft.setCursor(230,33);
tft.println(pH); // print pH value 0-14
tft.drawRoundRect(210,65,90,45,25,WHITE);
tft.setCursor(230,70);
tft.setTextSize(2);
tft.setTextColor(WHITE);
tft.println("Temp");
tft.setCursor(245,88);
tft.println(fahrenheitTemp); // print temp value F
tft.drawRoundRect(210,120,90,45,25,WHITE);
tft.setCursor(230,125);
tft.setTextSize(2);
tft.setTextColor(WHITE);
tft.println("Hum ");
tft.setCursor(230,143);
tft.println(h); // print Humidity value %
tft.setCursor(260,143);
tft.println("%");
tft.drawRoundRect(210,175,90,45,25,WHITE);
tft.setCursor(230,180);
tft.setTextSize(2);
tft.setTextColor(WHITE);
tft.println("cO2 =");
tft.setCursor(230,198);
tft.println(pH); // print cO2 value ppm
delay(10000); // delay in between reads for stability
tft.fillScreen(BLACK);
}
}