 unsigned long secCounter = 0; // count the seconds since start of timelapse
 unsigned long timeSlotCounter = 0; // count the timeslots since start of timelapse
 
+bool displayIsOn = true;
+
 String myIPStr = "";
 
 enum triggerModes { ON = 0, OFF = 1 };

  ANI Camera Remote by Andreas Niggemann, 2017
  Versions:
  20170607 Base functions
	20170613 Shot counter for WebGUI
  20170712 Defining triggerPin, settings
  20170717 Refactoring
  20170720 Bugfix: Restarting timelapse after reconnect removed

  currentTriggerMode =  tMode;
}

#ifdef ESP32
//void setupWiFi() { }
void setupWiFi()
{
  WiFi.mode(WIFI_AP); // AP mode for connections
  WiFi.softAP(ssid, password);
  server.begin();
  IPAddress ip = WiFi.softAPIP();
  myIPStr = String(ip[0]) + '.' + String(ip[1]) + '.' + String(ip[2]) + '.' + String(ip[3]);
}

void displaySetup()
{
  M5.begin();
  onDisplay();
}

void onDisplay()
{
  int actuLine = 0;
  M5.Lcd.fillScreen(TFT_BLACK);
  M5.Lcd.setFreeFont(FF9);
  outLCD(1, prgTitle + " " + prgVersion);
  outLCD(2, "RESET");
  outLCD(3, "Delay to Start: " + String(delayToStart));
  outLCD(4, "Number of Shots: " + String(numberOfShots));
  outLCD(5, "Interval: " + String(delayBetweenShots));
  if (startPin > -1)
    outLCD(6, "Wait for GPIO" + String(startPin));
  outLCD(7, "START");
  outLCD(8, "STOP");
  outLCD(9, "ONE SHOT");
  outLCD(10, "Remaining delay: " + String(currentDelayToStart));
  outLCD(11, "Remaining shots: " + String(currentNShots));
}

void outLCD(int lineNumber, String outStr)
{
  const int lineFactor = 20;
  M5.Lcd.setCursor(0, lineNumber * lineFactor);
  M5.Lcd.printf(outStr.c_str());
}

void processKeyboard()
{
  // Will not work currently because of a glitch in the Arduino ESP32 IDF
  // conflicts between WIFI and Buttons
  // Later version will not need WIFI and will have a complete UI via display and buttons
  if (M5.BtnA.pressedFor(1000)) // 1 second press to engage screen off or on
  {
    if (displayIsOn)
    {
      M5.Lcd.writecommand(ILI9341_DISPOFF);
      M5.Lcd.setBrightness(0);
      displayIsOn = false;
    }
    else
    {
      M5.Lcd.writecommand(ILI9341_DISPON);
      M5.Lcd.setBrightness(50);
      displayIsOn = true;
    }
  }
}
#else
// Methods for ESP8266
void setupWiFi()
{
  WiFi.mode(WIFI_AP); // AP mode for connections
  WiFi.softAP(ssid, password);
  server.begin();
  IPAddress ip = WiFi.softAPIP();
  myIPStr = String(ip[0]) + '.' + String(ip[1]) + '.' + String(ip[2]) + '.' + String(ip[3]);
}
void displaySetup() { }
void onDisplay() { }
void processKeyboard() { }
#endif
