#include <esp_task_wdt.h>

#define oMag 10
#define oRelay 11
#define oPump 12
#define oTimer 13

#define iOff 2
#define iPulse 3
#define iLow 4
#define iHigh 5
#define iPump 6

const int iPot = 8;
const int bLed = 15;

void setup() {
  // put your setup code here, to run once:
  pinMode(oMag, OUTPUT);
  pinMode(oRelay, OUTPUT);
  pinMode(oPump, OUTPUT);
  pinMode(oTimer, OUTPUT);

  pinMode(iOff, INPUT_PULLUP);
  pinMode(iPulse, INPUT_PULLUP);
  pinMode(iLow, INPUT_PULLUP);
  pinMode(iHigh, INPUT_PULLUP);
  pinMode(iPump, INPUT_PULLUP);

  pinMode(iPot, INPUT);
  
  pinMode(bLed, OUTPUT);

  esp_task_wdt_init(10, true); // Initialize watchdog with a timeout of 10 seconds, panic if triggered
}

void loop() {
  esp_task_wdt_reset(); // Reset the watchdog timer

  // Read Potentiometer
  int iPotValue = analogRead(iPot);
  int delayTime = map(iPotValue, 0, 1023, 5000, 45000);

  // Initialize stuff
  int iOffState = digitalRead(iOff);
  int iPulseState = digitalRead(iPulse);
  int iLowState = digitalRead(iLow);
  int iHighState = digitalRead(iHigh);
  int iPumpState = digitalRead(iPump);
  // put your main code here, to run repeatedly:

  digitalWrite(bLed, HIGH);
  delay(500);
  digitalWrite(bLed, LOW);
  delay(delayTime);
}
