#include "SevSeg.h"
#include <EEPROM.h>
#include <neotimer.h> // Biblioteca temporizadores

#define  EEPROM_SIZE 10    // Numero de bytes locados

SevSeg sevseg;
Neotimer clock_01, clock_02, clock_03, clock_04, clock_05, clock_06;

//#define ONE_WIRE_BUS 23
const int potPin = 4;

#define Botao_Motor 34
#define Botao_Aque 35
#define Botao_Down 36
#define Botao_Up 39

boolean motor, aquec, btdw, btup, Apresentou, anuciou,
        contbtdw, contbtup, ajSetTempm, ajSetTemp, ajSetTemH;

int brilho, setTempe, valsetTempe = 490, setTempo, valsetTempo = 100,
                      temRest, valtemRest = 2000, setTemIn, valsetTemIn = 35;

int led_Moto = 5;
int led2 = 22;
int led_Aque = 21;

int Rele_Motor = 17;
int Rele_Aque1 = 16;
//int Rele_Aque2 = 4;

int buzzer = 19, valorContH;

bool BombaEstado, AquecEstado, ajInter, ajTempe, ajFabri, resetPr;
byte ValorNumH = 5, contaSetTeMo;

#define MAX_NUMBER_STRINGS 11
#define MAX_STRING_SIZE 8
char testStrings[MAX_NUMBER_STRINGS][MAX_STRING_SIZE];

#define PATTERN_CHANGE_TIME 1000
unsigned long timer = millis() - PATTERN_CHANGE_TIME;
byte testStringsPos = 0;

static uint8_t taskCoreZero = 0, taskCoreOne = 1;

void superDelay(unsigned long tempoDeEspera) {
  unsigned long inicio = millis();             // ANOTA O TEMPO QUE INICIOU A FUNÇÃO
  while (millis() - inicio < tempoDeEspera) {  // LAÇO PARA O ARDUINO ESPERAR O TEMPO PASSAR
  }
}
void setup() {
  // put your setup code here, to run once:
  Serial.begin(115200);
  clock_01.set(20);
  clock_02.set(50);
  clock_03.set(125);
  clock_04.set(250);
  clock_05.set(500);
  clock_06.set(1000);
  //Serial.println("Hello, ESP32!");
  pinMode(potPin, INPUT);
  pinMode(Botao_Motor, INPUT_PULLUP);
  pinMode(Botao_Aque, INPUT_PULLUP);
  pinMode(Botao_Down, INPUT_PULLUP);
  pinMode(Botao_Up, INPUT_PULLUP);
  pinMode(buzzer, OUTPUT);
  pinMode(led_Moto, OUTPUT);
  pinMode(Rele_Motor, OUTPUT);
  pinMode(led_Moto, OUTPUT);
  pinMode(led_Aque, OUTPUT);
  pinMode(Rele_Aque1, OUTPUT);
  //pinMode(Rele_Aque2, OUTPUT);
  digitalWrite(buzzer, LOW);
  pinMode(led2, OUTPUT);
  digitalWrite(led_Moto, LOW);
  digitalWrite(Rele_Motor, LOW);
  digitalWrite(led2, LOW);
  digitalWrite(Rele_Aque1, LOW);
  byte numDigits = 3;
  byte digitPins[] = {32, 18, 2};
  byte segmentPins[] = {12, 15, 27, 25, 33, 13, 14, 26};
  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 = false; // Use 'true' if your decimal point doesn't exist or isn't connected. Then, you only need to specify 7 segmentPins[]

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

  // Adiciona um conjunto de strings de teste com pontos em vários lugares
  strcpy(testStrings[0],  "   " );
  strcpy(testStrings[1],  "8.8.8.");
  strcpy(testStrings[2],  "02.0");
  strcpy(testStrings[3],  "H-"  );
  strcpy(testStrings[4],  "H "  );
  strcpy(testStrings[5],  "E-"  );
  strcpy(testStrings[6],  "E "  );
  strcpy(testStrings[7],  "  0" );
  strcpy(testStrings[8],  "FAb" );
  strcpy(testStrings[9],  "rEt" );
  strcpy(testStrings[10], "SEt" );

  setTempo = valsetTempo;
  setTemIn = valsetTemIn;
  setTempe = valsetTempe;

  //creation des tâches
  xTaskCreatePinnedToCore(cTask0, "cTask0", 10000, NULL, 1, NULL, taskCoreZero);
  xTaskCreatePinnedToCore(cTask1, "cTask1", 10000, NULL, 2, NULL, taskCoreOne);
  xTaskCreatePinnedToCore(cTask2, "cTask2", 10000, NULL, 4, NULL, taskCoreZero);
}
void loop() {

  bool presbtdw, presbtup;
  int valorPot = analogRead(potPin);

  brilho = map(valorPot, 0, 4095, 0, 500);

  motor = digitalRead(Botao_Motor);
  aquec = digitalRead(Botao_Aque);
  btdw = digitalRead(Botao_Down);
  btup = digitalRead(Botao_Up);

  if (Apresentou) {
    if (!anuciou) {
      tone(buzzer, 1000, 100);// freqencia / tempo
      superDelay(800);
      noTone(buzzer);
      anuciou = true;
    }
  } else {
    if (!ajInter && !ajTempe && !ajFabri) { // Inicia programa
      tone(buzzer, 200, 20);// freqencia / tempo
      superDelay(1400);
      noTone(buzzer);
    }
  }
  if (!btdw && !presbtdw) {
    tone(buzzer, 2000, 20);// freqencia / tempo
    superDelay(800);
    noTone(buzzer);
    presbtdw = true;
  } else {
    presbtdw = false;
  }
  if (!btup && !presbtup) {
    tone(buzzer, 2000, 20);// freqencia / tempo
    superDelay(800);
    noTone(buzzer);
    presbtup = true;
  } else {
    presbtup = false;
  }

  delay(10);
  /*
  */
}

NOCOMNCVCCGNDINLED1PWRRelay Module
NOCOMNCVCCGNDINLED1PWRRelay Module
NOCOMNCVCCGNDINLED1PWRRelay Module