I am referring to use of the glcd and its corresponding library
/*
#include <TFT.h> // Arduino LCD library
#include <SPI.h>
// pin definition for the Uno
#define cs 10
#define dc 9
#define rst 8
// pin definition for the Leonardo
// #define cs 7
// #define dc 0
// #define rst 1
// create an instance of the library
TFT TFTscreen = TFT(cs, dc, rst);
// char array to print to the screen
char sensorPrintout[4];
void setup() {
// Put this line at the beginning of every sketch that uses the GLCD:
TFTscreen.begin();
// clear the screen with a black background
TFTscreen.background(0, 0, 0);
// write the static text to the screen
// set the font color to white
TFTscreen.stroke(255,255,255);
// set the font size
TFTscreen.setTextSize(2);
// write the text to the top left corner of the screen
TFTscreen.text("Sensor Value :\n ",0,0);
// ste the font size very large for the loop
TFTscreen.setTextSize(5);
}
void loop() {
// Read the value of the sensor on A0
String sensorVal = String(analogRead(A0));
// convert the reading to a char array
sensorVal.toCharArray(sensorPrintout, 4);
// set the font color
TFTscreen.stroke(255,255,255);
// print the sensor value
TFTscreen.text(sensorPrintout, 0, 20);
// wait for a moment
delay(250);
// erase the text you just wrote
TFTscreen.stroke(0,0,0);
TFTscreen.text(sensorPrintout, 0, 20);
}
The sketch once uploaded blinks the pot value depending on the delay.
If the delay is removed It will superimpose the value over each other and pixelate 10X10 pixels font size 1 or equivalent 20X20 for 2 etc.
If the colors are inverted the same happens.
I have found some sudo code that could possible work but have been told that the same thing will happen that it will just blink? wrong? Any thoughts??
int current_value, old_value; //set globally
current_value = analogRead(A0); // Read a value from analogpin 0
if(current_value != old_value) // Check to see if anything changed, if it did change show it, otherwise don't.
{
//print(" ", X, Y); // clear that section of the lcd
//print(current_value, X, Y); // show the new value
}
old_value = current_value; // Update old_value
Here is my code i am using with the screen. the blinking is even worse as there is actually code to be done. I put the clear screen before my if statements etc and the write screen after to speed up the blinking. seziure inducing stuff!!
#include "Adafruit_MAX31855.h"
#include <LiquidCrystal.h>
#include <TFT.h> // Arduino LCD library
#include <SPI.h>
int thermoCLK = 7;
int thermoCS = 3;
int thermoDO = 5;
int thermoCS1= 13;
const int diverters = 37; // the number of the relay 17 pin (NORMALLY OPEN SOLINOID)
const int pump = 39; // the number of relay 2 pin 16 (THE PUMP)
const int heater = 6; // The heater relay
const int sensorPin1 = A0; // pressure transducer
const int sensorPin2 = A1; // presseure select by potentiometer
const int buttonPin = 2; // Trigger
const int buttonPinoutside = 43; // 3rd party controll
const int systemreadyLED = 41; // 3rd party controll
const int anloginput = 43; // 3rd party controll
const int tankvalve = 31; //solinoid valve 220 ~ V/AC
const int highlevel = 33;//Float switch N/O
const int lowlevel = 35;//Float switch N/O
unsigned long now = millis (); // time now
//"ALWAYS use unsigned long for timers, not int"
//(variable declaration outside setup and loop, of course)
unsigned long Timer = 3000 ; // number doesnt need to be here ?? makes no difference!!
// Initialize the Thermocouple
Adafruit_MAX31855 thermocouple1(thermoCLK, thermoCS, thermoDO);
Adafruit_MAX31855 thermocouple2(thermoCLK, thermoCS1, thermoDO);
// each of the adafruit thermocouples. Differintialized by the CS PINS
// pin definition for the mega tft
#define cs 10
#define dc 9
#define rst 8
// create an instance of the library
TFT TFTscreen = TFT(cs, dc, rst);
// char array to print to the screen
char tmp[5] ;
int trigger = 0; // variable for reading the trigger status
int fulltank = 0; // initiall states
int emptytank = 0; // initiall states
void setup() {
// Put this line at the beginning of every sketch that uses the GLCD:
TFTscreen.begin();
// clear the screen with a black background
TFTscreen.background(0, 0, 0);
// write the static text to the screen
// set the font color to white
TFTscreen.stroke(0,0,255);
// set the font size
TFTscreen.setTextSize(1);
// write the text to the top left corner of the screen
TFTscreen.text("Pressure =",0,5);
TFTscreen.text("Pressure SP =",0,35);
TFTscreen.text("Block (T) C =",0,65);
TFTscreen.text("Steam (T) C =",0,95);
// ste the font size very large for the loop
TFTscreen.setTextSize(2);
pinMode(diverters, OUTPUT);
pinMode(pump, OUTPUT);
pinMode(heater, OUTPUT); // all of these are stating which of he pins are, ins or outs :)
pinMode(buttonPin, INPUT);
pinMode(highlevel,INPUT);
pinMode(lowlevel,INPUT);
pinMode(tankvalve,OUTPUT);
delay(50);
}
void loop() {
double blocktemperature = thermocouple1.readCelsius(); //storing what is read in a float/double so it can be used
double steamtemperature = thermocouple2.readCelsius(); //storing what is read in a float/double so it can be used
int sensorVal1 = analogRead(sensorPin1);// read the value on AnalogIn pin 0 and store it in a variable
int sensorVal2 = analogRead(sensorPin2);// read the value on AnalogIn pin 1 and store it in a variable
float voltage = (sensorVal1/1024.0) * 5.0; // convert the ADC reading to voltage
float Pressure = ((voltage-0.5)/.45) ;
float voltage2 = (sensorVal2/1024.0) * 5.0; // convert the ADC reading to voltage
float Pressureselect = ((voltage2-0.5)/.45) ;
char P[5];
char PS[5];
char btemp[5];
char stemp[5];
dtostrf(Pressure,1,2,P);
dtostrf(Pressureselect,1,2,PS);
dtostrf(blocktemperature,1,2,btemp);
dtostrf(steamtemperature,1,2,stemp);
String strOut1 = P;
String strOut2 = PS;
String strOut3 = btemp;
String strOut4 = stemp;
strOut1.toCharArray(P, 5);
strOut2.toCharArray(PS, 5);
strOut3.toCharArray(btemp, 5);
strOut4.toCharArray(stemp, 5);
// erase the text you just wrote
TFTscreen.stroke(0,0,0);
TFTscreen.text(P, 90, 0);
TFTscreen.text(PS, 90, 30);
TFTscreen.text(btemp, 90, 60);
TFTscreen.text(stemp, 90, 90);
// read the state of the trigger value:
trigger = digitalRead(buttonPin);
fulltank = digitalRead(highlevel);
emptytank = digitalRead(lowlevel);
#define TEMPSETPOINT 20 // Setting the temperature to a value@ #°C
#define TEMPDEADBAND 100 // 100 refers to 100°C
#define PRESSUREDEADBAND 0 // 1 = 1 BAR etc
if (isnan( blocktemperature)||((trigger == HIGH) && (blocktemperature >= 630 || blocktemperature <674))) // isnan means if ther is nothing present in its brackets it can be used to do something
{
digitalWrite(heater, LOW); // heaters will not turn on
}
else if (blocktemperature < TEMPSETPOINT - TEMPDEADBAND)
{
digitalWrite (heater, HIGH);
//digitalWrite (pinout, HIGH); // this is for when I have more outputs. led or high output for another system
}
else if
( blocktemperature > TEMPSETPOINT)
{
digitalWrite (heater, LOW);
}
if (fulltank == HIGH && emptytank == HIGH) {
digitalWrite (tankvalve, LOW);
}
else if (fulltank == LOW && emptytank == HIGH){
digitalWrite (tankvalve, HIGH);
}
else if (fulltank == LOW && emptytank == LOW){
digitalWrite (tankvalve, HIGH);
}
if (trigger == LOW || (emptytank == LOW)|| isnan(steamtemperature)||(steamtemperature >300)|| ( blocktemperature < 20) ) { //If any of these statements are true. the pump or valve will not activate.
// turn diverters off:
digitalWrite(diverters, LOW); // this is telling pin to go LOW ie. Off
}
else if (trigger == HIGH && (voltage < voltage2 - PRESSUREDEADBAND)){
// turn relay's sequence:
digitalWrite(diverters, HIGH);
digitalWrite (pump, HIGH);
(Timer = millis()); // timer is compared to arduino clock and if greater than before it will allow the timer to start once trigger is low
}
else if ((voltage > voltage2 - PRESSUREDEADBAND)|| isnan(steamtemperature)||(steamtemperature >300)|| ( blocktemperature < 20)||(emptytank == LOW)){
digitalWrite (pump, LOW);
}
if (Timer> 0 && millis () - Timer > 2000 ) // Time is in milliseconds. 1000 = 1 SECOND.
{
digitalWrite (pump, LOW);
}
// set the font color
TFTscreen.stroke(0,0,255);
// print the sensor value's
TFTscreen.text(P, 90, 0);
TFTscreen.text(PS, 90, 30);
TFTscreen.text(btemp, 90, 60);
TFTscreen.text(stemp, 90, 90);
// wait for a moment
delay(5);
}
any insight. Is there a better improved library that better drivers.
Thanks again.