#include "RTClib.h"
#include "LedControl.h"
#include "binary.h"
#define DIN_PIN 11 //Pino DIN se conecta com a porta digital 11 do arduino
#define CS_PIN 10 //Pino CS se conecta com a porta digital 10 do arduino
#define CLK_PIN 13 //Pino CLK se conecta com a porta digital 13 do arduino
#define A_BTN_PIN 8
#define B_BTN_PIN 9
#define MAX_DEVICES 4
RTC_DS1307 rtc;
LedControl lc = LedControl(DIN_PIN, CLK_PIN, CS_PIN, MAX_DEVICES); //Objeto que passa como parâmetros os pinos do Arduino conectados e o número de displays usados
void desenho() { //Binários que representam o coração
lc.setRow(0, 0, B00000000);
lc.setRow(0, 1, B00100010);
lc.setRow(0, 2, B01010101);
lc.setRow(0, 3, B01001001);
lc.setRow(0, 4, B01000001);
lc.setRow(0, 5, B00100010);
lc.setRow(0, 6, B00010100);
lc.setRow(0, 7, B00001000);
}
String addLeftZero(int number){
if(number < 10){
return "0" + String(number);
}
return String(number);
}
void getCurrentTime() {
DateTime now = rtc.now();
Serial.print("Current time: ");
Serial.print(now.year(), DEC);
Serial.print('/');
Serial.print(now.month(), DEC);
Serial.print('/');
Serial.print(now.day(), DEC);
Serial.print(' ');
Serial.print(now.hour(), DEC);
Serial.print(':');
Serial.print(now.minute(), DEC);
Serial.print(':');
Serial.print(addLeftZero(now.second()));
Serial.println();
}
void setup(){
Serial.begin(115200);
if (! rtc.begin()) {
Serial.println("Couldn't find RTC");
Serial.flush();
abort();
}
pinMode(A_BTN_PIN, INPUT_PULLUP);
pinMode(B_BTN_PIN, INPUT_PULLUP);
lc.shutdown(0, false); //Inicia o módulo
lc.setIntensity(0, 8); //Define a itensidade de brilho do display
lc.clearDisplay(0); //Limpa a tela do display
}
void loop(){
if (digitalRead(A_BTN_PIN) == LOW) {
desenho();
getCurrentTime();
delay(500);
}
if (digitalRead(B_BTN_PIN) == LOW) {
lc.clearDisplay(0);
delay(500);
}
delay(50);
// desenho(); // chamada da função de desenho
// delay(5000); // delay de 5 segundos
// lc.clearDisplay(0); //limpeza do display
// delay(1000); // delay de 1 segundo até que se tenha uma nova repetição
}