//21/07/2024 14:43
#include <EEPROM.h> //Inclui a biblioteca da memoria EEPROM
#include <Arduino.h>
#include <Button.h>
#include <ACI_10K_an.h>
Button button2(7);  // create ezButton object that attach to pin 7;
Button button5(8);  // create ezButton object that attach to pin 8;
byte LedState1 = LOW;
byte LedState2 = LOW;
Button button1(5); // Connect your button between pin 5 and GND
Button button3(9); // Connect your button between pin 9 and GND
Button button4(6); // Connect your button between pin 6 and GND
// parametrização
int led0 = A4;
int led1 = A3;
int led2 = A2;
int autVent = 0;
int celsius;
int autVeloc = 0;
int VentLador = 0;
int ioniZando = 0;
int ioniZa = 0;
int bomBeamento = 0;
int climaTiz = 0;
long alterVeloc = !0;
int idNiv = 0;
int modoVent = 0 ;
int nivelTanque = 0;
int velVent = 0;
int autLador = 0;
int modVel = 0;
int ionIzar = 0;
int pinNiv = 2 ; // pino nivelTanque
void velocidade();
void autovelocidade();
void bombeamento(void);
void oscilador(void);
void ionizador(void);
volatile int brightness = 0;    // how bright the LED is
volatile int fadeAmount = random(8, 18);    // how many points to fade the LED by
void setup(void) {
  randomSeed(analogRead(A0));//parametro infinito
  pinMode(A1, INPUT_PULLUP);// pino Temperatura
  pinMode(A2, OUTPUT);// pino led VentLador alto
  pinMode(A3, OUTPUT);//pino led VentLador medio
  pinMode(A4, OUTPUT); //pino led VentLador baixo
  pinMode(1, OUTPUT); // pastilha Peltier
  pinMode(2, INPUT_PULLUP); //Nível do tanque
  pinMode(3, OUTPUT); // pino resistencia de aquecimento
  pinMode(4, OUTPUT); // pino alarme temperatura
  pinMode(5, INPUT_PULLUP);//climatizar
  pinMode(6, INPUT_PULLUP);//pino oscilar
  pinMode(7, INPUT_PULLUP); // pino VentLador
  pinMode(8, INPUT_PULLUP); // pino modoVent auto/temp
  pinMode(9, INPUT_PULLUP);// pino ionizar
  pinMode(10, OUTPUT); // pino led bomBeamento
  pinMode(11, OUTPUT); // pino oscilar
  pinMode(12, OUTPUT); //pino ioniZando
  pinMode(13, OUTPUT); // pino led nivelTanque
  //Give the random a random seed from the noise from the ADC of A0
  analogReference(DEFAULT);
  button1.begin();
  button2.begin(); // set debounce time to 50 milliseconds
  button3.begin();
  button4.begin();
  button5.begin(); // set debounce time to 50 milliseconds
}
void loop() {
  velocidade();
  autovelocidade();
  bombeamento();
  oscilador();
  ionizador();
}
void autovelocidade(void) {

  //Temperatura
  Aci_10K an10k; //start an instance of the library
  //Aci_10K an10k(3.3,12);support for 3.3 volt board and/or 12bit analog read resolution

  delayMicroseconds(500);
  celsius = (an10k.getTemp(analogRead(A1)));
  if (button5.pressed())
    (autVeloc = autVeloc + 1);
  if (autVeloc == 1) {
    autVeloc = 1;
    //digitalWrite(3, LOW);
    switch (celsius) {
      case -24 ... 18: {
          digitalWrite(1, LOW);
          digitalWrite(4, !digitalRead(4));
          digitalWrite(3, HIGH);
          delayMicroseconds(50);
          (alterVeloc = 1);
          break;
        }
      case 20 ... 24: {
          digitalWrite(4, !digitalRead(4));
          digitalWrite(3, !digitalRead(3));
          delayMicroseconds(50);
          digitalWrite(1, LOW);
          (alterVeloc = 2);
          break;
        }
      case 26 ... 40: {
          digitalWrite(4, !digitalRead(4));
          digitalWrite(1, !digitalRead(1));
          delayMicroseconds(50);
          digitalWrite(3, LOW);
          (alterVeloc = 3);
          break;
        }
      default: {
          digitalWrite(3, LOW);
          digitalWrite(1, LOW);
          digitalWrite(1, HIGH);
        }
    }
  }
  if (autVeloc >= 2) {
    digitalWrite(4, LOW);
    digitalWrite(3, LOW);
    (autVeloc = 0);
  }
}
void velocidade(void) {
  // instanciando um botão só
  // inicio da parametrização do VentLadordor
  if (button2.pressed())
    (alterVeloc = alterVeloc + 1);
  if (alterVeloc == 1) {
    (alterVeloc = 1);
    analogWrite(led2, 0);
    analogWrite(led1, 0);
    analogWrite(led0, 255);
  }
  if (alterVeloc == 2) {
    (alterVeloc = 2);
    analogWrite(led1, 255);
    analogWrite(led2, 0);
    analogWrite(led0, 0);
  }
  if (alterVeloc == 3) {
    (alterVeloc = 3);
    analogWrite(led0, 0);
    analogWrite(led2, 255);
    analogWrite(led1, 0);
  }
  if (alterVeloc == 4) {
    (alterVeloc = 4);
    analogWrite(led2, 0);
    analogWrite(led1, 0);
    analogWrite(led0, 0);
  }
  if (alterVeloc == 5) {
    (alterVeloc = 5);
    analogWrite(led2, 0);
    analogWrite(led1, 0);
    analogWrite(led0, brightness);

    // change the brightness for next time through the loop:
    brightness = brightness + fadeAmount;
    delay(random(0.5, 1));
    // reverse the direction of the fading at the ends of the fade:
    if (brightness <= 0.9 || brightness >= 255) {
      fadeAmount = -fadeAmount;
    }
    analogWrite(led0, analogRead(led0) ^ !0); //inverte estado do led
    // wait for 30 milliseconds to see the dimming effect
    delay(random(0.5, 1));
  }
  if (alterVeloc == 6) {
    (alterVeloc = 6);
    analogWrite(led2, 0);
    analogWrite(led0, 0);
    analogWrite(led1, brightness);

    // change the brightness for next time through the loop:
    brightness = brightness + fadeAmount;
    delay(random(0.5, 1));
    // reverse the direction of the fading at the ends of the fade:
    if (brightness <= 0.9 || brightness >= 255) {
      fadeAmount = -fadeAmount;
    }
    analogWrite(led1, analogRead(led1) ^ !0); //inverte estado do led
    // wait for 30 milliseconds to see the dimming effect
    delay(random(0.5, 1));
  }
  if (alterVeloc == 7 ) {
    (alterVeloc = 7);
    analogWrite(led0, 0);
    analogWrite(led1, 0);
    analogWrite(led2, brightness);

    // change the brightness for next time through the loop:
    brightness = brightness + fadeAmount;
    delay(random(0.5, 1));
    // reverse the direction of the fading at the ends of the fade:
    if (brightness <= 0.9 || brightness >= 255) {
      fadeAmount = -fadeAmount;
    }
    analogWrite(led2, analogRead(led2) ^ !0); //inverte estado do led
    // wait for 30 milliseconds to see the dimming effect
    delay(random(0.5, 1));
  }
  if ((alterVeloc >= 8))
  {
    (alterVeloc = 1);
  }
}
void bombeamento() {
  pinMode(2, INPUT);
  // inicio da parametrização do bombeamento
  // le o estado sensornivel: ligado (LOW) ou desligado (HIGH)
  nivelTanque = digitalRead(2);
  // noInterrupts();
  switch (nivelTanque) { // escolha caso o nível
    case HIGH: { // quando nível está alto
        digitalWrite(13, LOW); // liga o LED de nível baixo
        if (button1.toggled()) { // inicio da parametrização do climatizador
          if (button1.read() == Button::PRESSED)
            digitalWrite(10, !digitalRead(10));
        }
        break;
      }
    case LOW: {
        digitalWrite(13, HIGH); // desliga o LED de nível baixo
        digitalWrite(10, LOW); // desliga a bomba
        break;
      }
  }
}
void oscilador(void) {
  if (button4.toggled()) { // inicio da parametrização do oscilador
    if (button4.read() == Button::PRESSED)
      digitalWrite(11, !digitalRead(11));
  }
}
void ionizador(void) {
  if (button3.toggled()) {// inicio da parametrização do ionizador
    if (button3.read() == Button::PRESSED)
      digitalWrite(12, !digitalRead(12));
  }
}
$abcdeabcde151015202530354045505560fghijfghij