Часы на DS1302 и 1″8 TFT LCD Display module ST7735S

IMG_3679

Иногда хочется заняться чем то бесполезными, вот к примеру таким, часы на TFT LCD Display module ST7735S 128×160 и DS1302

 

 

#include <TFT.h>  // Arduino LCD library
#include <SPI.h>
#include <DS1302.h> //https://codeload.github.com/msparks/arduino-ds1302/zip/master
 
#define cs   10
#define dc   9
#define rst  8  

#define kCePin 6  // Chip Enable
#define kIoPin 5  // Input/Output
#define kSclkPin 4  // Serial Clock

 
TFT TFTscreen = TFT(cs, dc, rst);
DS1302 rtc(kCePin, kIoPin, kSclkPin);
  

void setup() {
   pinMode(2, OUTPUT);
   pinMode(3, OUTPUT);
   digitalWrite(2, HIGH);
   digitalWrite(3, LOW);
 
   TFTscreen.begin();
}

String dayAsString(const Time::Day day) {
  switch (day) {
    case Time::kSunday: return "Sunday";
    case Time::kMonday: return "Monday";
    case Time::kTuesday: return "Tuesday";
    case Time::kWednesday: return "Wednesday";
    case Time::kThursday: return "Thursday";
    case Time::kFriday: return "Friday";
    case Time::kSaturday: return "Saturday";
  }
  return "(unknown day)";
}

void loop() {
 
  Time t = rtc.time();

  const String Day = dayAsString(t.day); 

  char time[10];
  char data[11];
  char day[10];
 
  snprintf(time, sizeof(time), "%02d:%02d",           
           t.hr, t.min);
           
  snprintf(data, sizeof(data), "%02d/%02d/%02d",            
           t.date, t.mon, t.yr);
           
  snprintf(day, sizeof(day), "%s", Day.c_str());         
  
  TFTscreen.background(50, 0, 0);
 
  TFTscreen.setTextSize(5);
  TFTscreen.stroke(240, 220, 220);   
  TFTscreen.text(time, 9, 20);  
  
  TFTscreen.setTextSize(2);
  TFTscreen.stroke(200, 150, 150);   
  TFTscreen.text(data, 20, 70);  
  
  TFTscreen.setTextSize(2);
  TFTscreen.stroke(150, 150, 200);   
  TFTscreen.text(day, 25, 100);  
  delay(30000);

}