#include<EEPROM.h>
#include <OneWire.h>
#include <DallasTemperature.h>
#include <SPI.h>
#include<EEPROM.h>
#include "Adafruit_GFX.h"
#include "Adafruit_HX8357.h"
#include "MCUFRIEND_kbv.h"
#include "TouchScreen.h"
#define YP A2 // must be an analog pin, use "An" notation!
#define XM A3 // must be an analog pin, use "An" notation!
#define YM 7 // can be a digital pin
#define XP 8 // can be a digital pin
// This is calibration data for the raw touch data to the screen coordinates
#define TS_MINX 110
#define TS_MINY 80
#define TS_MAXX 900
#define TS_MAXY 940
#define MINPRESSURE 10
#define MAXPRESSURE 1000
// The display uses hardware SPI, plus #9 & #10
#define TFT_CS 10
#define TFT_DC 9
#define TFT_RST -1
Adafruit_HX8357 tft = Adafruit_HX8357(TFT_CS, TFT_DC, TFT_RST);
TouchScreen ts = TouchScreen(XP, YP, XM, YM, 300);
#define ONE_WIRE_BUS 3 //temp sensor
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
int potPin =A5; //potentiometer for setting temp
//int relay0 = ;
int relay1 = 4; //relay swich
const int stsp = A0; //start stop
const int inc = A1;
const int dec = A2;
const int set = A3;
const int buzz = 6;
int tempval = 0;
int val = 0;
int hrs = 0;
int Min = 0;
int sec = 0;
unsigned int check_val = 50;
int add_chk = 0;
int add_hrs = 1;
int add_min = 2;
bool RUN = true;
bool min_flag = true;
bool hrs_flag = true;
void setup()
{
Serial.begin(9600);
tft.begin();
tft.setRotation(1);
tft.setTextSize(4);
tft.fillScreen(HX8357_BLACK);
tft.setCursor(0, 0);
tft.print("ELECTRONIC ");
tft.print("by kakou");
pinMode(stsp, INPUT_PULLUP);
pinMode(inc, INPUT_PULLUP);
pinMode(dec, INPUT_PULLUP);
pinMode(set, INPUT_PULLUP);
pinMode(buzz, OUTPUT);
pinMode(relay1, OUTPUT);
if (EEPROM.read(add_chk) != check_val)
{
EEPROM.write(add_chk, check_val);
EEPROM.write(add_hrs, 0);
EEPROM.write(add_min, 1);
}
else
{
hrs = EEPROM.read(add_hrs);
Min = EEPROM.read(add_min);
}
delay(1500);
INIT();
}
void loop()
{
if (digitalRead(stsp) == LOW)
{
tft.fillScreen(HX8357_BLACK);
delay(250);
RUN = true;
while (RUN)
{
if (digitalRead(stsp) == LOW)
{
delay(1000);
if (digitalRead(stsp) == LOW)
{
tft.fillScreen(HX8357_BLACK);
tft.setCursor(0, 0);
tft.print(" TIMER STOPPED");
tft.setCursor(0, 1);
tft.print("----------------");
delay(2000);
RUN = false;
break;
}
}
sec = sec - 1;
delay(1000);
if (sec == -1)
{
sec = 59;
Min = Min - 1;
}
if (Min == -1)
{
Min = 59;
hrs = hrs - 1;
}
if (hrs == -1) hrs = 0;
tft.setCursor(0,0);
tft.print(" ");
val = analogRead(potPin);
tempval = val/10;
Serial.print("The set temp is: ");
Serial.print( val/10);
Serial.println(" ...DONE");
Serial.print(" Requesting temperatures...");
sensors.requestTemperatures(); // Send the command to get temperature readings
Serial.println("DONE");
Serial.print("Temperature is: ");
Serial.print(sensors.getTempCByIndex(0));
delay(1000);
Serial.println("");
Serial.println("");
if(sensors.getTempCByIndex(0) > tempval+1)
{
digitalWrite(relay1,LOW);
}
if(sensors.getTempCByIndex(0) < tempval)
{
digitalWrite(relay1,HIGH);
}
tft.fillScreen(HX8357_BLACK);
tft.setCursor(0, 0);
tft.print("SET TEMP: ");
tft.println(tempval );
tft.print(" Water temp:");
tft.println(sensors.getTempCByIndex(0));
tft.print(" ");
if (hrs <= 9)
{
tft.print('0');
}
tft.print(hrs);
tft.print(':');
if (Min <= 9)
{
tft.print('0');
}
tft.print(Min);
tft.print(':');
if (sec <= 9)
{
tft.print('0');
}
tft.print(sec);
if (hrs == 0 && Min == 0 && sec == 0)
{
RUN = false;
for (int i = 0; i < 20; i++)
{
digitalWrite(buzz, HIGH);
delay(100);
digitalWrite(buzz, LOW);
digitalWrite(relay1, LOW);
delay(100);
}
INIT();
}
}
}
if (digitalRead(set) == LOW)
{
delay(100);
while (min_flag)
{
tft.setCursor(0, 0);
tft.print("SET MINUTE: ");
tft.print(Min);
delay(100);
tft.fillScreen(HX8357_BLACK);
if (digitalRead(inc) == LOW)
{
Min = Min + 1;
if (Min >= 60) Min = 0;
delay(100);
}
if (digitalRead(dec) == LOW)
{
Min = Min - 1;
if (Min <= -1) Min = 0;
delay(100);
}
if (digitalRead(set) == LOW)
{
min_flag = false;
delay(250);
}
}
while (hrs_flag)
{
tft.fillScreen(HX8357_BLACK);
tft.setCursor(0, 0);
tft.print("SET HOUR: ");
tft.print(hrs);
delay(100);
if (digitalRead(inc) == LOW)
{
hrs = hrs + 1;
if (hrs > 23) hrs = 0;
delay(100);
}
if (digitalRead(dec) == LOW)
{
hrs = hrs - 1;
if (hrs <= -1) hrs = 0;
delay(100);
}
if (digitalRead(set) == LOW)
{
hrs_flag = false;
delay(250);
}
}
if (hrs == 0 && Min == 0)
{
tft.fillScreen(HX8357_BLACK);
tft.setCursor(0, 0);
tft.print(" INVAID TIME");
delay(2000);
}
else
{
EEPROM.write(add_hrs, hrs);
EEPROM.write(add_min, Min);
}
INIT();
}
}
void INIT()
{
hrs = EEPROM.read(add_hrs);
Min = EEPROM.read(add_min);
sec = 0;
tft.fillScreen(HX8357_BLACK);
tft.setCursor(0, 0);
tft.println("Start / Set Time");
if (hrs <= 9)
{
tft.print('0');
}
tft.print(hrs);
tft.print(':');
if (Min <= 9)
{
tft.print('0');
}
tft.print(Min);
tft.print(':');
if (sec <= 9)
{
tft.print('0');
}
tft.print(sec);
min_flag = true;
hrs_flag = true;
delay(500);
}
I have an 3.5'' 480x320 tft lcd touchscreen from adafruit in spi mode on my arduino uno with a simple temp sensor and a relay swich
i want to put touch buttons instead of normal ones for the functions of
const int stsp = A0; //start stop
const int inc = A1; // increasing time
const int dec = A2; //decreasing time
const int set = A3; //set time
i dont want anything fancy just ordinary square buttons for each function
do u know where should i start ,any sources or some examples that i could learn how to do it
p.s sorry for bad english and i know my code isnt optimal i yet have to learn a lot of things any help is welcome even unrelated