#include "segmentos.h"
#include <DHT.h>
#include <RTClib.h>

int segs[] = { 2, 3, 4, 5 };

uint8_t digits[] = { 6, 7, 8, 9, 10, 12, 13 };

Segments seg1(digits);
DHT dht(11, DHT22);
RTC_DS1307 rtc;

void setup() {
  // seg1.init();
  dht.begin();

  for (int i : segs){
    pinMode(i, OUTPUT);
    digitalWrite(i, 1);
  }

  pinMode(11, INPUT);
  Serial.begin(115200);
}

String setNum(int num){
  char buffer[2];
  sprintf(buffer, "%02d", num);
  return String(buffer);
}

void loop() 
{
  int temp = dht.readTemperature();
  int cd = millis() + 20000;
  String num = setNum(temp);
  Serial.println(temp);

  for (int i = 2; i < 6; i++){
    seg1.showNum(String(num[i - 2]).toInt());
    digitalWrite(i, 0);
    digitalWrite(i, 1);
  }

  if (cd >= millis())
  {
    cd = millis() - 10000;
  }

}
GND5VSDASCLSQWRTCDS1307+