// A = d11 B=d8 C=d9 D=d10 E=d7 F=d12 G=d13  LED1=d4 Led2=d5 ledext=d6
#include "SevSeg.h"
SevSeg sevseg; //Instantiate a seven segment controller object

//NTC
const float BETA = 3950; // should match the Beta Coefficient of the thermistor
const float constB = 1.0 / 298.15; // should match the Beta Coefficient of the thermistor

//23 a 27  - 5 por conta
//28 a 30 - 4 por conta
//31 a 35 - 3 por conta
//Acima de 36 - 2 por conta

void setup() {
  byte numDigits = 3;
  byte digitPins[] = {5, 4, 6};
  byte segmentPins[] = {11,8,9,10,7,12,13};
  bool resistorsOnSegments = false; // 'false' means resistors are on digit pins
  byte hardwareConfig = COMMON_CATHODE; // See README.md for options
  bool updateWithDelays = false; // Default 'false' is Recommended
  bool leadingZeros = false; // Use 'true' if you'd like to keep the leading zeros
  bool disableDecPoint = true; // Use 'true' if your decimal point doesn't exist or isn't connected

  sevseg.begin(hardwareConfig, numDigits, digitPins, segmentPins, resistorsOnSegments,
  updateWithDelays, leadingZeros, disableDecPoint);
  sevseg.setBrightness(90);

  Serial.begin(9600);
}

void loop() {
  static unsigned long timer = millis();
  static int deciSeconds = 0;

sevseg.refreshDisplay(); // Must run repeatedly
  int  analogValue = analogRead(A0);
  sevseg.refreshDisplay(); 
  float celsius = 1 / (log(1 / (1023. / analogValue - 1)) / BETA + constB) - 273.15;
  if (celsius<0.1) celsius = 500;
  else if (celsius<27.1) celsius = celsius + 500;
  else if (celsius<30.1) celsius = celsius + 400;
  else if (celsius<35.9) celsius = celsius + 300;
  else  celsius = celsius + 200;


  sevseg.setNumber(celsius);
  sevseg.refreshDisplay(); // Must run repeatedly

}

/// END ///