#include "segs.h"
#include <DHT.h>
#include <RTClib.h>
uint8_t segs[] = { 6, 7, 8, 9, 10, 11, 12 };
uint8_t digits[] = { 2, 3, 4, 5 };
long ms = 10000;
String minute, num;
bool displayTime;
Segments segments(segs, digits);
DHT dht(13, DHT22);
RTC_DS1307 rtc;
void setup()
{
segments.init();
dht.begin();
rtc.begin();
}
String setNum(int num)
{
char buffer[4];
sprintf(buffer, "%04d", num);
return String(buffer);
}
void loop()
{
int temp = dht.readTemperature();
if (rtc.now().minute() < 10)
{
minute = "0" + String(rtc.now().minute());
}
else
{
minute = String(rtc.now().minute());
}
String _time = String(rtc.now().hour() + minute);
int time = _time.toInt();
if (millis() <= ms)
{
displayTime = true;
}
else if (millis() > ms && millis() <= ms + 3000)
{
displayTime = false;
}
else
{
ms = millis() + 10000;
}
if (displayTime)
{
num = setNum(time);
}
else
{
num = setNum(temp);
}
for (int i : digits)
{
segments.showNum(String(num[i - 2]).toInt());
digitalWrite(i, 0);
digitalWrite(i, 1);
}
}