#include <FirebaseESP32.h>

#define FIREBASE_HOST "https://dsi-p1-fd839-default-rtdb.firebaseio.com/"
#define FIREBASE_AUTH "4g12cTjqF1vvkPwZt3tteuIZ7hxCOxDsbCkTOYEK"
#define WIFI_SSID "Moto G (5) 7890"
#define WIFI_PASSWORD "Levy162711"

#define LED1_PIN 4
#define LED2_PIN 5
#define POT1_PIN 34
#define POT2_PIN 35

FirebaseData firebaseData;
int tempoAmostra = 1000;
bool led2Status = false;

int lerPot1() {
  return analogRead(POT1_PIN);
}

int lerPot2() {
  return analogRead(POT2_PIN);
}

void atualizarSensor1(int valor) {
  Firebase.setInt(firebaseData, "Sensor1", valor);
}

void atualizarSensor2(int valor) {
  Firebase.setInt(firebaseData, "Sensor2", valor);
}

void piscarLeds() {
  for (int i = 0; i < 5; i++) {
    digitalWrite(LED1_PIN, HIGH);
    digitalWrite(LED2_PIN, HIGH);
    delay(500);
    digitalWrite(LED1_PIN, LOW);
    digitalWrite(LED2_PIN, LOW);
    delay(500);
  }
  digitalWrite(LED1_PIN, HIGH);
}

void setup() {
  pinMode(LED1_PIN, OUTPUT);
  pinMode(LED2_PIN, OUTPUT);

  Serial.begin(115200);
  delay(1000);

  WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
  Serial.print("Conectando ao WiFi");
  while (WiFi.status() != WL_CONNECTED) {
    Serial.print(".");
    delay(500);
  }
  Serial.println();
  Serial.println("Conectado ao WiFi!");

  Firebase.begin(FIREBASE_HOST, FIREBASE_AUTH);
  Firebase.reconnectWiFi(true);

  Firebase.getInt(firebaseData, "TempoAmostra");
  if (firebaseData.dataType() == "int") {
    tempoAmostra = firebaseData.intData();
  }

  Firebase.getBool(firebaseData, "Led2");
  if (firebaseData.dataType() == "bool") {
    led2Status = firebaseData.boolData();
    digitalWrite(LED2_PIN, led2Status);
  }
}

void loop() {
  Firebase.getBool(firebaseData, "Start");
  if (firebaseData.dataType() == "bool" && firebaseData.boolData()) {
    piscarLeds();
    digitalWrite(LED1_PIN, HIGH);
    digitalWrite(LED2_PIN, led2Status);
  } else {
    digitalWrite(LED1_PIN, LOW);
    digitalWrite(LED2_PIN, LOW);
  }

  int valorPot1 = lerPot1();
  int valorPot2 = lerPot2();

  atualizarSensor1(valorPot1);
  atualizarSensor2(valorPot2);

  delay(tempoAmostra);
}
$abcdeabcde151015202530fghijfghij