#include "SPI.h"
#include "Adafruit_GFX.h"
#include "Adafruit_ILI9341.h"
#define TFT_DC 2
#define TFT_CS 3
Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC);
volatile int countSec=0;
volatile int Heatlevel=0; // 0 to 5 only
volatile unsigned long lastDebounceTime = 0;
void writeNum(int num, int height)
{
tft.fillRect(24, height, 200, 20, ILI9341_BLACK);
tft.setCursor(24, height);
tft.setTextColor(ILI9341_GREEN);
tft.setTextSize(2);
tft.println(num);
}
bool checkTime()
{
unsigned long currentTime = millis();
if ((currentTime-lastDebounceTime)>150)
{
lastDebounceTime = currentTime;
return 1;
}
return 0;
}
void timebuttonPressed()
{
if (!checkTime()) return;
countSec +=1;
writeNum(countSec,160);
}
void heatbuttonPressed()
{
unsigned long currentTime = millis();
// If enough time has passed since the last button press, consider it a valid press
if (!checkTime()) return;
if(Heatlevel<5)
{
Heatlevel+=1;
writeNum(Heatlevel,200);
}
}
void startbuttonPressed()
{
digitalWrite(A3,Heatlevel*(51));
delay(countSec*1000);
digitalWrite(A3,0);
Serial.println("after sec");
}
void setup() {
Serial.begin(115200);
tft.begin();
tft.setCursor(20, 120);
tft.setTextColor(ILI9341_RED);
tft.setTextSize(3);
tft.println(("Time in sec:"));
pinMode(A0, INPUT_PULLUP);
pinMode(A1, INPUT_PULLUP);
pinMode(A2, INPUT_PULLUP);
pinMode(A3,OUTPUT);
attachInterrupt(digitalPinToInterrupt(A0), timebuttonPressed, RISING);
attachInterrupt(digitalPinToInterrupt(A1), heatbuttonPressed, RISING);
attachInterrupt(digitalPinToInterrupt(A2), startbuttonPressed, RISING);
}
void loop() { delay(10); }