#include <Adafruit_GFX.h>    // Core graphics library
#include <Adafruit_ST7735.h> // Hardware-specific library
#include <SPI.h>

#include <OneWire.h>
OneWire ds(3); // Создаем объект OneWire для шины 1-Wire


#define TFT_SCLK 13
#define TFT_MOSI 11
#define TFT_CS   10
#define TFT_RES  9  
#define TFT_RS   8

Adafruit_ST7735 tft = Adafruit_ST7735(TFT_CS,  TFT_RS, TFT_RES);

float p = 3.1415926;
 int s=0;
 int m=0;
 int Pin0 = 4;
 int Pin = 5; 
 int in = 0;
 int in1 = 0;
 int flag = 0;
 unsigned long timing;
 

#include <DallasTemperature.h>
#define ONE_WIRE_BUS 3 // wire ot t
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors1(&oneWire);
 

void setup(void) {
  Serial.begin(9600);
  Serial.print("Hello! ST7735 TFT Test");  // Use this initializer if you're using a 1.8" TFT
  tft.initR(INITR_BLACKTAB);   // initialize a ST7735S chip, black tab
  Serial.println("Initialized");
  
}


void loop() { 

 sensors1.requestTemperatures(); // request from t unit

  in = digitalRead (Pin);
  in1 = digitalRead (Pin0);
  
  if(in == HIGH) { tft.fillScreen(ST7735_BLACK); tft.setCursor(20,50); tft.setTextSize(2); s=0; m=0; tft.print(" Restart "); delay (2000); }
  if(in1 == HIGH&flag == 0) { tft.fillScreen(ST7735_RED); tft.setTextSize(3); tft.setCursor(20,40); tft.print(" PAUSE "); flag = 1; delay (1000); in1 = LOW; delay (1000);}
  if(in1 == HIGH&flag == 1) { tft.fillScreen(ST7735_YELLOW); tft.setTextSize(3); tft.setCursor(20,40); tft.print(" PLAY "); flag = 0; delay (2000); }

  
  if (s==0&m<1) {
    tft.setRotation(1); 
    tft.fillScreen(ST7735_MAGENTA);
    tft.setTextSize(3);
    tft.setCursor(40,40);
    tft.println("START");
    delay (1000);
     };

  if (m<13&(millis() - timing > 1000)&flag == 0) {
  tft.setRotation(1);  
  tft.fillScreen(ST7735_CYAN);
  tft.setTextColor(ST7735_BLACK);
  tft.setCursor(20,30);
  tft.setTextSize(1);
  tft.print("MIN ");
  tft.setTextSize(3);
  tft.print(m);
  tft.setCursor(70,30);
  tft.setTextSize(1);
  tft.print("SEC ");
  tft.setTextSize(3);
  tft.println(s); 
  tft.setCursor(20,70);
  tft.setTextSize(2);
  tft.print("Temp ");
  tft.print(sensors1.getTempCByIndex(0));
  timing = millis();
  s=s+1;
  };

  if (m>=13&m<15&(millis() - timing > 1000)&flag == 0) {
  tft.setRotation(1);  
  tft.fillScreen(ST7735_RED);
  tft.setCursor(20,30);
  tft.setTextSize(1);
  tft.print("MIN ");
  tft.setTextSize(3);
  tft.print(m);
  tft.setCursor(70,30);
  tft.setTextSize(1);
  tft.print("SEC ");
  tft.setTextSize(3);
  tft.println(s); 
  tft.setCursor(20,70);
  tft.setTextSize(2);
  tft.print("Temp ");
  tft.print(sensors1.getTempCByIndex(0));
  timing = millis();
  s=s+1;
  };

  
  if (m>=15&(millis() - timing > 1000)&flag == 0) {
    tft.fillScreen(ST7735_BLUE);
    tft.setTextSize(2);
    tft.setCursor(20,30);
    tft.println("FINISH");
    //time
    tft.setCursor(20,50);
    tft.setTextSize(1);
    tft.print("MIN ");
    tft.setTextSize(2);
    tft.print(m);
    tft.setCursor(70,50);
    tft.setTextSize(1);
    tft.print("SEC ");
    tft.setTextSize(2);
    tft.println(s); 
    timing = millis();
    s=s+1;
      
}

if (s==60) {s=0; m=m+1;}

}
