My code only lasts for a while before getting stuck

I have a project I have coded. The main program logs data and saves it to an SD card. Code keeps saving logs to the SD card. It also allows remote access through it's on hotspot or Ethernet connection, but the menu and information on the display freezes.

Hardware:
-Adafruit M0 with Wifi
-Adafruit RTC Adalogger
-Adafruit Ethernet
-Adafruit 128x68 Display
-16bit I2C ADS1115

here is the current code:
main.cpp files:

#include <Arduino.h>
#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SH110X.h>
#include <Adafruit_I2CDevice.h>
#include <Adafruit_ADS1X15.h>
#include <RTClib.h>
#include <SD.h>
#include <Time.h>
#include <WiFiClient.h>
#include <NTPClient.h>
#include <WiFi101.h>
#include <millisDelay.h>
#include <WiFiUdp.h>
#include <wifilogin.h>
#include <Ethernet.h>

//Needed from Libary DO NOT EDIT!!!
RTC_PCF8523 rtc;
File root;
// Adafruit_ADS1115 ads;
Adafruit_ADS1115 ads1115;
millisDelay SDWriteDelay;
millisDelay SDWriteDelay2;
WiFiUDP ntpUDP;
const long utcOffsetInSeconds = 3600;
NTPClient timeClient(ntpUDP, "tz.pool.ntp.org", utcOffsetInSeconds); //Tanzina

byte mac[] = { 0xF8,0xF0,0x5,63,0xB6,0xBB };  // change if necessary
byte ip[] = { 192,168,0,57 };
byte gateway[] = { 192, 168, 0, 1 }; // internet access via router
byte subnet[] = { 255, 255, 255, 0 }; //subnet mask
WiFiServer server(80);

//FIRMWARE
const char *FIRMWARE_Version = "Firmware v1.0.4";

//CHANGE 2021 to 2022, etc. For each Month!!!!
const char *DATALOGSYEAR = "/LOGS/FULL-LOGS.txt"; //Change for each year, This is a full log of a full year
const char *Jan = "/LOGS/1.txt";
const char *Feb = "/LOGS/2.txt";
const char *March = "/LOGS/3.txt";
const char *April = "/LOGS/4.txt";
const char *May = "/LOGS/5.txt";
const char *June = "/LOGS/6.txt";
const char *July = "/LOGS/7.txt";
const char *Aug =  "/LOGS/8.txt";
const char *Sept = "/LOGS/9.txt";
const char *Oct =  "/LOGS/10.txt";
const char *Nov =  "/LOGS/11.txt";
const char *Dec =  "/LOGS/12.txt";

//SDcard pins
const int chipSelect = 10;
const uint8_t CS = 10;
#define cardSelect 10
#define SDCARD_CS 10
#define WIZ_CS 10

//SD and major delay for recording data
unsigned long delayStart = 0;
bool delayRunning = false;
bool VoltSD = false; //ALWAYS FALSE, This checks to see if millisDelay is running or not
bool WindSD = false; //ALWAYS FALSE, This checks to see if millisDelay is running or not

#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels
#define OLED_RESET     4 // Reset pin # (or -1 if sharing Arduino reset pin)
#define SCREEN_ADDRESS 0x3C ///< See datasheet for Address; 0x3D for 128x64, 0x3C for 128x32
Adafruit_SH110X display = Adafruit_SH110X(64, 128, &Wire);

//Real Time Clock and NTPClient
char daysOfTheWeek[7][12] = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};
char time_format[] = "hh:mm:ss AP";
char date_format[] = "MM/DD/YYYY";

bool Warning = 0;
bool Fault01 = 0;
bool Fault02 = 0;

int AI0 = 0;
int AI1 = 0;
int AI2 = 0;
int AI3 = 0;
int AI4 = 0;
int AI5 = 0;
int voltmath = (3.3 / 1024);

//MENU
const int BUTTON_UP = 9;
const int BUTTON_DOWN = 6;
const int BUTTON_SELECT = 5;
int menuitem = 1;
int page = 1;
int downButtonState = 0;
int upButtonState = 0;
int selectButtonState = 0;
int lastDownButtonState = 0;
int lastSelectButtonState = 0;
int lastUpButtonState = 0;
unsigned int x = 0;
volatile boolean up = false;
volatile boolean down = false;
volatile boolean middle = false;

//Delay for AnalogPins
const unsigned long eventInterval = 2500;
unsigned long previousTime = 0;

const unsigned int numReadings = 15; //AC Readings
const unsigned int numReadingsWind = 15; //Wind readings
const unsigned int numReadingsIBat = 15;
const unsigned int numReadingsBattery = 15;
const unsigned int numReadingsdump = 15;
const unsigned int numReadingsWarn = 15;
const unsigned int numReadingsIturb = 15;
const unsigned int numReadingsVturb = 15;
const int vtestpin = analogRead(A0);
const int windpin = analogRead(A1);
const int dumpload = analogRead(A2);
const int warningpin = analogRead(A3);

const int sensorPin = A1;
int sensorValue = 0; //Variable stores the value direct from the analog pin
float sensorVoltage = 0; //Variable that stores the voltage (in Volts) from the anemometer being sent to the analog pin
float windSpeed = 0; // Wind speed in meters per second (m/s)

float voltageConversionConstant = .004882814;
int sensorDelay = 1000; //Delay between sensor readings, measured in milliseconds (ms)

//Anemometer Technical Variables

float voltageMin = .4; // Mininum output voltage from anemometer in mV.
float windSpeedMin = 0; // Wind speed in meters/sec corresponding to minimum voltage

float voltageMax = 2.0; // Maximum output voltage from anemometer in mV.
float windSpeedMax = 32; // Wind speed in meters/sec corresponding to maximum voltage

int wind_avg[numReadingsWind];
unsigned int wind_readIndex = 0;
int wind_sum = 0;
unsigned int windstatus_avg = 0;

int vtest_avg[numReadings];
unsigned int vtest_readIndex = 0;
int vtest_sum = 0;
unsigned int vtest_avgerage = 0;

int warn_avg[numReadingsWarn];
unsigned int warn_readIndex = 0;
int warn_sum = 0;
unsigned int warning_avg = 0;

int dump_avg[numReadingsdump];
unsigned int Dump_Index = 0;
int dump_sum = 0;
unsigned int dumpaverage = 0;

int vbat_avg[numReadingsBattery];
unsigned int vbat_readIndex = 0;
int vbat_sum = 0;
unsigned int battery_avg = 0;

int ibat_avg [numReadingsIBat];
unsigned int ibat_readIndex = 0;
int ibat_sum = 0;
unsigned int ibat_average = 0;

int iturb_avg [numReadingsIturb];
unsigned int iturb_readIndex = 0;
int iturb_sum = 0;
unsigned int iturb_average = 0;

int vturb_avg [numReadingsVturb];
unsigned int vturb_readIndex = 0;
int vturb_sum = 0;
unsigned int vturb_average = 0;

float volts0;
float volts1;
float volts2;
float volts3;

//wifi wifilogin
//please enter your sensitive data in the Secret libary folder wifilogin.h
char ssid[] = SECRET_SSID;        // your network SSID (name)
char pass[] = SECRET_PASS;    // your network password (use for WPA, or use as key for WEP)

char ssid2[] = "Turbine Sensor";        // your network SSID (name)
char pass2[] = "bootsNcatsN";    // your network password (use for WPA, or use as key for WEP)

char ssid3[] = "Da Router"; //No Password SSID

int led =  LED_BUILTIN;
int status = WL_IDLE_STATUS;     // the WiFi radio's status
// int keyIndex = 0;            // your network key Index number (needed only for WEP/WPA)

//Wifi, Ethernet, RTC and NTP Setup
void printMacAddress(byte mac[]) {
  for (int i = 5; i >= 0; i--) {
    if (mac[i] < 16) {
      Serial.print("0");
    }
    Serial.print(mac[i], HEX);
    if (i > 0) {
      Serial.print(":");
    }
  }
  Serial.println();
}
void printCurrentNet() {
  // print the SSID of the network you're attached to:
  Serial.print("SSID: ");
  Serial.println(WiFi.SSID());

  // print the MAC address of the router you're attached to:
  byte bssid[6];
  WiFi.BSSID(bssid);
  Serial.print("BSSID: ");

  // printMacAddress(bssid);

  // print the received signal strength:
  long rssi = WiFi.RSSI();
  Serial.print("signal strength (RSSI):");
  Serial.println(rssi);

  // print the encryption type:
  byte encryption = WiFi.encryptionType();
  Serial.print("Encryption Type:");
  Serial.println(encryption, HEX);
  Serial.println();
}
void printWiFiData() {
  // print your WiFi shield's IP address:
  IPAddress ip = WiFi.localIP();
  Serial.print("IP Address: ");
  Serial.println(ip);
  Serial.println(ip);

  // print your MAC address:
  byte mac[6];
  WiFi.macAddress(mac);
  Serial.print("MAC address: ");
  printMacAddress(mac);

}

void wifi_init () {
  WiFi.setPins(8,7,4,2);
  WiFi.begin(ssid, pass);
  // you're connected now, so print out the data:
  Serial.print("You're connected to the network");
  printCurrentNet();
  printWiFiData();

}
void wifi_init_ap(){
  WiFi.setPins(8,7,4,2);
  Serial.print("Creating access point named: ");
  Serial.println(ssid2);

  // Create open network. Change this line if you want to create an WEP network:
  status = WiFi.beginAP(ssid2, pass2);
  if (status != WL_AP_LISTENING) {
    Serial.println("Creating access point failed");
    // don't continue
    while (true);
  }
}

//File System
void printDirectory(File dir, int numTabs) {
   while(true) {
     File entry =  dir.openNextFile();
     if (! entry) {
       // no more files
       break;
     }
     for (uint8_t i=0; i<numTabs; i++) {
       Serial.print('\t');
     }
     Serial.print(entry.name());
     if (entry.isDirectory()) {
       Serial.println("/");
       printDirectory(entry, numTabs+1);
     } else {
       // files have sizes, directories do not
       Serial.print("\t\t");
       Serial.println(entry.size(), DEC);
     }
     entry.close();
   }
}
void ListFiles(WiFiClient client, uint8_t flags, File dir) {
  client.println("<ul>");
  while (true) {
    File entry = dir.openNextFile();
     if (! entry) {
       break;
     }
    client.print("<li><a href=\"");
    client.print(entry.name());
    if (entry.isDirectory()) {
       client.println("/");
    }
    client.print("\">");
    client.print(entry.name());
    if (entry.isDirectory()) {
       client.println("/");
    }
    client.print("</a>");
    client.println("</li>");
    entry.close();
  }
  client.println("</ul>");
}
#define BUFSIZ 100
void clientfile_Host(void) {
  char clientline[BUFSIZ];
  char name[17];
  int index = 0;
  WiFiClient client = server.available();
  if (client) {
    // an http request ends with a blank line
    boolean current_line_is_blank = true;
    // reset the input buffer
    index = 0;
    while (client.connected()) {
      if (client.available()) {
        char c = client.read();
        // If it isn't a new line, add the character to the buffer
        if (c != '\n' && c != '\r') {
          clientline[index] = c;
          index++;
          // are we too big for the buffer? start tossing out data
          if (index >= BUFSIZ)
            index = BUFSIZ -1;

          // continue to read more data!
          continue;
        }

        // got a \n or \r new line, which means the string is done
        clientline[index] = 0;

        // Print it out for debugging
        // Serial.println(clientline);

        // Look for substring such as a request to get the file
        if (strstr(clientline, "GET /") != 0) {
          // this time no space after the /, so a sub-file!
          char *filename;

          filename = clientline + 5; // look after the "GET /" (5 chars)  *******
          // a little trick, look for the " HTTP/1.1" string and
          // turn the first character of the substring into a 0 to clear it out.
          (strstr(clientline, " HTTP"))[0] = 0;

          if(filename[strlen(filename)-1] == '/') {  // Trim a directory filename
            filename[strlen(filename)-1] = 0;        //  as Open throws error with trailing /
          }

          Serial.print(F("Web request for: "));
          Serial.println(filename);  // print the file we want

          File file = SD.open(filename, O_READ);
          if ( file == 0 ) {  // Opening the file with return code of 0 is an error in SDFile.open
            client.println("HTTP/1.1 404 Not Found");
            client.println("Content-Type: text/html");
            client.println();
            client.println("<h2>File Not Found!</h2>");
            client.println("<br><h3>Couldn't open the File!</h3>");
            break;
          }

          Serial.println("File Opened!");

          client.println("HTTP/1.1 200 OK");
          if (file.isDirectory()) {
            Serial.println("is a directory");
            //file.close();
            client.println("Content-Type: text/html");
            client.println();
            client.print("<h2>Files in /");
            client.print(filename);
            client.println(":</h2>");
            ListFiles(client,LS_SIZE,file);
            file.close();
          } else { // Any non-directory clicked, server will send file to client for download
            client.println("Content-Type: application/octet-stream");
            client.println();

            char file_buffer[16];
            int avail;
            while (avail = file.available()) {
              int to_read = min(avail, 16);
              if (to_read != file.read(file_buffer, to_read)) {
                break;
              }
              // uncomment the serial to debug (slow!)
              // Serial.write((char)c);
              client.write(file_buffer, to_read);
            }
            file.close();
          }
        } else {
          // everything else is a 404
          client.println("HTTP/1.1 404 Not Found");
          client.println("Content-Type: text/html");
          client.println();
          client.println("<h2>File Not Found!</h2>");
        }
        break;
      }
    }
    // give the web browser time to receive the data
    delay(1);
    client.stop();
  }
}

void WiFiAP_Main(void){
  // compare the previous status to the current status
  if (status != WiFi.status()) {
    // it has changed, so update the variable
    status = WiFi.status();

    if (status == WL_AP_CONNECTED) {
      byte remoteMac[6];

      // a device has connected to the AP
      Serial.print("Device connected to AP, MAC address: ");
      WiFi.APClientMacAddress(remoteMac);
      printMacAddress(remoteMac);
    } else {
      // a device has disconnected from the AP, and we are back in listening mode
      Serial.println("Device disconnected from AP");
    }
  }

  WiFiClient client = server.available();   // listen for incoming clients

  if (client) {                             // if you get a client,
    Serial.println("new client");           // print a message out the serial port
    String currentLine = "";                // make a String to hold incoming data from the client
    while (client.connected()) {            // loop while the client's connected
      if (client.available()) {             // if there are bytes to read from the client,
        char c = client.read();             // read a byte, then
        Serial.write(c);                    // print it out the serial monitor
        if (c == '\n') {                    // if the byte is a newline character

          // if the current line is blank, you got two newline characters in a row.
          // that's the end of the client HTTP request, so send a response:
          if (currentLine.length() == 0) {
            // HTTP headers always start with a response code (e.g. HTTP/1.1 200 OK)
            // and a content-type so the client knows what's coming, then a blank line:
            client.println("HTTP/1.1 200 OK");
            client.println("Content-type:text/html");
            client.println();

            // the content of the HTTP response follows the header:
            client.print("Click <a href=\"/H\">here</a> turn the LED on<br>");
            client.print("Click <a href=\"/L\">here</a> turn the LED off<br>");

            // The HTTP response ends with another blank line:
            client.println();
            // break out of the while loop:
            break;
          }
          else {      // if you got a newline, then clear currentLine:
            currentLine = "";
          }
        }
        else if (c != '\r') {    // if you got anything else but a carriage return character,
          currentLine += c;      // add it to the end of the currentLine
        }

        // Check to see if the client request was "GET /H" or "GET /L":
        if (currentLine.endsWith("GET /H")) {
          digitalWrite(led, HIGH);               // GET /H turns the LED on
        }
        if (currentLine.endsWith("GET /L")) {
          digitalWrite(led, LOW);                // GET /L turns the LED off
        }
      }
    }
    // close the connection:
    client.stop();
    Serial.println("client disconnected");
  }
}

//NTP and RTC
void ntp_clock() {
  timeClient.begin();
  rtc.begin();
  timeClient.update();
  rtc.adjust( DateTime(timeClient.getEpochTime()) );
  rtc.start();
  Serial.println(timeClient.getFormattedTime());
}

//Menu System
void Menu_init(){
  pinMode(BUTTON_UP, INPUT_PULLUP);
  pinMode(BUTTON_DOWN, INPUT_PULLUP);
  pinMode(BUTTON_SELECT, INPUT_PULLUP);
  display.begin(0x3C, true);
  display.clearDisplay();
  display.display();
  display.setRotation(1);
  ads1115.begin();
}
void pinouts(void) {
  Fault01 = digitalRead(0);
  AI0 = analogRead(A0);
  AI1 = analogRead(A1);
  AI2 = analogRead(A2);
  AI3 = analogRead(A3);
  AI4 = analogRead(A4);
  AI5 = analogRead(A5);

}
void checkIfDownButtonIsPressed() {
  if (downButtonState != lastDownButtonState) {
    if (downButtonState == 0) {
      down=true;
    }
    delay(50);
    }
   lastDownButtonState = downButtonState;
  }
void checkIfUpButtonIsPressed() {
  if (upButtonState != lastUpButtonState) {
    if (upButtonState == 0) {
      up=true;
    }
    delay(50);
  }
   lastUpButtonState = upButtonState;
  }
void SelectButton() {
  if (digitalRead(BUTTON_SELECT) == LOW) {
    middle=true;
  }
  else {
    middle=false;
  }
    delay(75);
  }
void dateandtime() {
  DateTime now = rtc.now();
  Serial.print(now.year(), DEC);
  Serial.print('/');
  Serial.print(now.month(), DEC);
  Serial.print('/');
  Serial.print(now.day(), DEC);
  Serial.print(" (");
  Serial.print(daysOfTheWeek[now.dayOfTheWeek()]);
  Serial.print(") ");
  Serial.print(now.hour(), DEC);
  Serial.print(':');
  Serial.print(now.minute(), DEC);
  Serial.println();
}
void timeanddate () {
  DateTime now = rtc.now();
  display.setTextSize(1);             // Normal 1:1 pixel scale
  display.setTextColor(SH110X_WHITE);
  display.print(now.year(), DEC);
  display.print('/');
  display.print(now.month(), DEC);
  display.print('/');
  display.print(now.day(), DEC);
  display.print(" (");
  display.print(daysOfTheWeek[now.dayOfTheWeek()]);
  display.print(")");
  display.print(now.hour(), DEC);
  display.print(':');
  display.print(now.minute(), DEC);
  display.print(':');
  display.print(now.second(), DEC);
  display.println();
}
void menutext() {
  display.clearDisplay();
  display.setTextSize(1);             // Normal 1:1 pixel scale
  display.setTextColor(SH110X_WHITE);        // Draw white text
  display.setCursor(0,0);
  display.println(F("TECNIX Upepo Umeme"));
}
void drawMenu() {
  if (page==1) {
    display.setTextSize(1.5);


    if (menuitem==1) {
      display.setTextColor(SH110X_WHITE, SH110X_BLACK);
    }
    else {
      display.setTextColor(SH110X_BLACK, SH110X_WHITE);
    }
    display.setCursor(0, 5);
    display.print("Volts");
    display.setTextColor(SH110X_BLACK);
    display.print(" ");
    display.display();


    if (menuitem==2) {
      display.setTextColor(SH110X_WHITE, SH110X_BLACK);
    }
    else {
      display.setTextColor(SH110X_BLACK, SH110X_WHITE);
    }
    display.print("Wind");
    display.setTextColor(SH110X_BLACK);
    display.print(" ");
    display.display();

    if (menuitem==3) {
      display.setTextColor(SH110X_WHITE, SH110X_BLACK);
    }
    else {
      display.setTextColor(SH110X_BLACK, SH110X_WHITE);
    }
    display.print("WiFi");
    display.display();

    if (menuitem==4) {
      display.setTextColor(SH110X_WHITE, SH110X_BLACK);
    }
    else {
      display.setTextColor(SH110X_BLACK, SH110X_WHITE);
    }
      display.setCursor(0, 25);
      display.print("Dump");
      display.setTextColor(SH110X_BLACK);
      display.print(" ");
      display.display();

    if (menuitem==5) {
      display.setTextColor(SH110X_WHITE, SH110X_BLACK);
    }
    else {
      display.setTextColor(SH110X_BLACK, SH110X_WHITE);
    }
      display.print("i/vBat");
      display.setTextColor(SH110X_BLACK);
      display.print(" ");
      display.display();

    if (menuitem==6) {
      display.setTextColor(SH110X_WHITE, SH110X_BLACK);
    }
    else {
      display.setTextColor(SH110X_BLACK, SH110X_WHITE);
    }
    display.print("i/vTurb");
    display.setTextColor(SH110X_BLACK);
    display.print(" ");
    display.display();

    if (menuitem==7) {
      display.setTextColor(SH110X_WHITE, SH110X_BLACK);
    }
    else {
      display.setTextColor(SH110X_BLACK, SH110X_WHITE);
    }
    display.setCursor(0, 50);
    display.print("Tech Menu");
    display.setTextColor(SH110X_BLACK);
    display.print(" ");
    display.display();

    if (menuitem==8) {
      display.setTextColor(SH110X_WHITE, SH110X_BLACK);
    }
    else {
      display.setTextColor(SH110X_BLACK, SH110X_WHITE);
    }
    display.print("Firm");
    display.setTextColor(SH110X_BLACK);
    display.print(" ");
    display.display();

    }
  }
void selectedmenubuttons() {
  if (middle) {
    middle = false;
    if(page == 1 && menuitem ==6) {
      if (menuitem==5) {
        middle = false;
        }
      else {
        middle = true;
        drawMenu();
       }
    }
    middle = false;
   }
}
void MenuDelay() {
  unsigned long currentTime = millis();

 /* This is the event */
 if (currentTime - previousTime >= eventInterval) {
   /* Event code */

  /* Update the timing for the next time around */
   previousTime = currentTime;
 }
}

//Menu Items
void Menu_1() {
  vtest_avg[numReadings] = analogRead(A0);
  for (unsigned int vtest_readIndex = 0; vtest_readIndex < (sizeof(vtest_avg[16])/sizeof(vtest_avg[0])); vtest_readIndex++) {
    vtest_sum += vtest_avg[vtest_readIndex] ;
  }
  vtest_avgerage = vtest_avg[numReadings];
  menutext();
  display.println("Volts Test - Analog A0");
  display.setTextSize(2);
  if (vtest_avgerage > 1.0 ){
    display.printf("True\n");
    display.println(vtest_avgerage * 0.00201416);
  } else {
    display.printf("False\n");
    display.println(vtest_avgerage * 0.00201416);
  }
  display.display();
  display.clearDisplay();
  // //delay(250);
  if (digitalRead(BUTTON_SELECT) == LOW) {
    middle=true;
    return;
  }
  else {
    middle=false;
    Menu_1();
  }
}
void Menu_2() {
  sensorValue = analogRead(windpin); //Get a value between 0 and 1023 from the analog pin connected to the anemometer
  sensorVoltage = sensorValue * voltageConversionConstant;
  if (sensorVoltage <= 0.4){
    windSpeed = (sensorVoltage - voltageMin)*windSpeedMax/(voltageMax - voltageMin);; //Check if voltage is below minimum value. If so, set wind speed to zero.
  }else {
    windSpeed = (sensorVoltage - voltageMin)*windSpeedMax/(voltageMax - voltageMin);
  }
  menutext();
  display.println(F("Wind Speed-Anemometer"));
  display.setTextSize(2);
  Serial.println(windSpeed);
  if (windSpeed > 1.0 ){
    display.println(windSpeed);
  } else {
    display.printf("Not Enough Wind\n");
    display.println("0");
  }
  display.display();
  display.clearDisplay();
  // delay(500);
  if (digitalRead(BUTTON_SELECT) == LOW) {
    middle=true;
  }
  else {
    middle=false;
    Menu_2();
  }
}
void Menu_3() {
  menutext();
  // unsigned int Warn_In = analogRead(A2);
  display.println(F("WiFi/Ethernet IP"));
  display.setTextSize(1);
  // printCurrentNet();
  IPAddress ip = WiFi.localIP();
  display.println("WiFi IP Address: ");
  display.println(ip);
  IPAddress ip2 = Ethernet.localIP();
  display.println("Ethernet IP Address: ");
  display.println(ip2);
  display.display();
  display.clearDisplay();
  if (digitalRead(BUTTON_SELECT) == LOW) {
    middle=true;
  }
  else {
    middle=false;
    Menu_3();
  }
}
void Menu_4() {
  menutext();
  display.println("Dump Load Input");
  display.setTextSize(1);
  dump_avg[numReadingsdump] = analogRead(A2);
  for (unsigned int Dump_Index = 0; Dump_Index < (sizeof(dump_avg[16])/sizeof(dump_avg[0])); Dump_Index++) {
    dump_sum += dump_avg[Dump_Index];
  }
  dumpaverage = dump_avg[numReadingsdump];
  if (dumpaverage > 1.0 ){
    display.printf("A2 True\n");
    display.print(dumpaverage  * 0.00201416);
    display.println(" Volts");
  } else {
    display.printf("A2 False\n");
    display.print(dumpaverage * 0.00201416);
    display.println(" Volts");
  }

  warn_avg[numReadingsWarn] = analogRead(A3);
  for (unsigned int warn_readIndex = 0; warn_readIndex < (sizeof(warn_avg[16])/sizeof(warn_avg[0])); warn_readIndex++) {
    warn_sum += warn_avg[warn_readIndex];
  }
  warning_avg = warn_avg[numReadingsWarn];
  display.println("A3 Warning Input");
  if (warning_avg > 1.0 ){
    display.printf("True\n");
    display.print(warning_avg * 0.00201416);
    display.println(" Volts");
  } else {
    display.printf("A3 False\n");
    display.print(warning_avg * 0.00201416);
    display.println(" Volts");
  }
  display.display();
  display.clearDisplay();
  if (digitalRead(BUTTON_SELECT) == LOW) {
    middle=true;
    return;
  }
  else {
    middle=false;
    Menu_4();
  }
}
void Menu_5(void) {
  float volts1;
  vbat_avg[numReadingsBattery] = ads1115.readADC_SingleEnded(1);
  for (unsigned int vbat_readIndex = 0; vbat_readIndex < (sizeof(vbat_avg[16])/sizeof(vbat_avg[0])); vbat_readIndex++) {
    vbat_sum += vbat_avg[vbat_readIndex] ;
  }
  battery_avg = vbat_avg[numReadingsBattery];
  volts1 = ads1115.computeVolts(battery_avg);

  float volts0;
  ibat_avg[numReadingsIBat] = ads1115.readADC_SingleEnded(0);
  for (unsigned int ibat_readIndex = 0; ibat_readIndex < (sizeof(ibat_avg[16])/sizeof(ibat_avg[0])); ibat_readIndex++) {
    ibat_sum += ibat_avg[ibat_readIndex] ;
  }
  ibat_average = ibat_avg[numReadingsIBat];
  volts0 = ads1115.computeVolts(ibat_average);
  menutext();
  display.println("Battery Volt");
  display.setTextSize(1);
  if (volts1 > 2.0 ){
    display.printf("A1 vBat On\n");
    display.print(volts0);
    display.print(" Volts");
  } else {
    display.printf("A1 vBat Off\n");
    display.print(volts0);
    display.println(" Volts");
  }
  display.println(F("A0 Battery Current"));
  display.setTextSize(1);
  if (volts0 > 2.0 ){
    display.printf("A0 iBat Working\n");
    display.print(volts1);
    display.print(" Volts");
  } else {
    display.printf("A0 iBat Not Working\n");
    display.print(volts1);
    display.print(" Volts");
  }
  display.display();
  display.clearDisplay();
  if (digitalRead(BUTTON_SELECT) == LOW) {
    middle=true;
  }
  else {
    middle=false;
    Menu_5();
  }
}
void Menu_6(void) {
  menutext();
  display.println("Turbine Volt");
  display.setTextSize(1);
  float volts2;
  vturb_avg[numReadingsVturb] = ads1115.readADC_SingleEnded(2);
  for (unsigned int vturb_readIndex = 0; vturb_readIndex < (sizeof(vturb_avg[16])/sizeof(vturb_avg[0])); vturb_readIndex++) {
    vturb_sum += vturb_avg[vturb_readIndex] ;
  }
  vturb_average = vbat_avg[vturb_readIndex];
  volts2 = ads1115.computeVolts(vturb_average);
  if (volts2 > 1.0 ){
    display.printf("A2 vTurb On\n");
    display.print(volts2);
    display.println(" Volts");
  } else {
    display.printf("A2 vTurb Off\n");
    display.print(volts2);
    display.println(" Volts");
  }

  float volts3;
  iturb_avg[numReadingsIturb] = ads1115.readADC_SingleEnded(3);
  for (unsigned int iturb_readIndex = 0; iturb_readIndex < (sizeof(iturb_avg[16])/sizeof(iturb_avg[0])); iturb_readIndex++) {
    iturb_sum += iturb_avg[iturb_readIndex];
  }
  iturb_average = iturb_avg[numReadingsIturb];
  volts3 = ads1115.computeVolts(iturb_average);

  display.println(F("A3 Turbine Current"));
  if (volts3 > 1.0 ){
    display.printf("A3 iTurb Working\n");
    display.print(volts3);
    display.print(" Volts");
  } else {
    display.printf("A3 iTurb Not Working\n");
    display.print(volts3);
    display.print(" Volts");
  }
  display.display();
  display.clearDisplay();
  if (digitalRead(BUTTON_SELECT) == LOW) {
    middle=true;
  }
  else {
    middle=false;
    Menu_6();
  }
}
void Menu_7() {
  menutext();
  display.display();
  display.clearDisplay();
  if (digitalRead(BUTTON_SELECT) == LOW) {
    middle=true;
  }
  else {
    middle=false;
    Menu_7();
  }
}
void Menu_8() {
  display.clearDisplay();
  display.setTextSize(1);             // Normal 1:1 pixel scale
  display.setTextColor(SH110X_WHITE);        // Draw white text
  display.setCursor(0,0);
  display.println(F("<< Unit Info >>"));
  display.setTextSize(1);
  display.println(FIRMWARE_Version);
  // ntp_clock();
  timeanddate();
  display.print("Eric Tarkleson and \n");
  display.print("John Mulholland\n");
  display.println("merutechnician@gmail.com");
  display.display();
  display.clearDisplay();
  if (digitalRead(BUTTON_SELECT) == LOW) {
    middle=true;
  }
  else {
    middle=false;
    Menu_8();
  }
}
void menubuttons() {
  if (up && page == 1 ) {
    up = false;
    menuitem--;
    if (menuitem==0) {
      menuitem=8;
    }
  } else if (up && page == 2 ) {
    up = false;
  }

  if (down && page == 1) {
    down = false;
    menuitem++;
    if (menuitem==9)
    {
      menuitem=0;
    }
  }else if (down && page == 2 ) {
    down = false;
  }

  if (middle) {
    middle = false;
    if(page == 1 && menuitem ==1) {
      if (menuitem==0) {
        middle = false;
        }
      else {
        middle = true;
        Menu_1();
       }
    }
    middle = false;

    if(page == 1 && menuitem ==2) {
      if (menuitem==1) {
        middle = false;
        }
      else {
        middle = true;
        Menu_2();
       }
    }
    middle = false;

    if(page == 1 && menuitem ==3) {
      if (menuitem==2) {
        middle = false;
        }
      else {
        middle = true;
        Menu_3();
       }
    }
    middle = false;

    if(page == 1 && menuitem ==4) {
      if (menuitem==3) {
        middle = false;
        }
      else {
        middle = true;
        Menu_4();
       }
    }
    middle = false;

    if(page == 1 && menuitem ==5) {
      if (menuitem==4) {
        middle = false;
        }
      else {
        middle = true;
        Menu_5();
       }
    }
    middle = false;

    if(page == 1 && menuitem ==6) {
      if (menuitem==5) {
        middle = false;
        }
      else {
        middle = true;
        Menu_6();
       }
    middle = false;
    }

    if(page == 1 && menuitem ==7) {
      if (menuitem==6) {
        middle = false;
        }
      else {
        middle = true;
        Menu_7();
       }
    middle = false;

    }
    if(page == 1 && menuitem ==8) {
      if (menuitem==7) {
        middle = false;
        }
      else {
        middle = true;
        Menu_8();
       }
    middle = false;

    }
    // if(page == 1 && menuitem ==9) {
    //   if (menuitem==8) {
    //     middle = false;
    //     }
    //   else {
    //     middle = true;
    //    }
    // middle = false;
    // }

    else if (page == 1 && menuitem>=1) {
      page=2;
     }
    else if (page == 2) {
      page=1;
     }
   }
}

//SD DATALOGS and recording time.
void errno(uint8_t errno) {
  while(1) {
    uint8_t i;
    for (i=0; i<errno; i++) {
      digitalWrite(13, HIGH);
      delay(100);
      digitalWrite(13, LOW);
      delay(100);
    }
    for (i=errno; i<10; i++) {
      delay(200);
    }
  }
}
void SD_init (){
  //SD sdset up
  delayRunning = true;
  // Serial.println("\r\nAnalog logger test");
  // if (!SD.begin(SDCARD_CS)) {
  //   Serial.println("Card init. failed!");
  //   errno(2);
  // }
  char filename[16];
  strcpy(filename, DATALOGSYEAR);
  for (uint8_t i = 0; i < 100; i++) {
    filename[7] = '0' + i/10;
    filename[8] = '0' + i%10;
    // create if does not exist, do not open existing, write, sync after write
    if (! SD.exists(filename)) {
      break;
    }
  }
  root = SD.open(filename, FILE_WRITE);
  if( ! root ) {
    Serial.print("Couldn't create ");
    Serial.println(filename);
    errno(3);
  }
  Serial.println("Files Ready!");
}

void SD_Files() {
    char filename[20];
    strcpy(filename, DATALOGSYEAR);
    for (uint8_t i = 0; i < 100; i++) {
      filename[7] = '0' + i/10;
      filename[8] = '0' + i%10;
      // create if does not exist, do not open existing, write, sync after write
      if (! SD.exists(filename)) {
        break;
      }
    }
    root = SD.open(filename, FILE_WRITE);
    if( ! root ) {
      Serial.print("Couldn't create ");
      Serial.println(filename);
      errno(3);
    }

    strcpy(filename, Jan);
    for (uint8_t i = 0; i < 100; i++) {
      filename[7] = '0' + i/10;
      filename[8] = '0' + i%10;
      // create if does not exist, do not open existing, write, sync after write
      if (! SD.exists(filename)) {
        break;
      }
    }
    root = SD.open(filename, FILE_WRITE);
    if( ! root ) {
      Serial.print("Couldn't create ");
      Serial.println(filename);
      errno(3);
    }

    strcpy(filename, Feb);
    for (uint8_t i = 0; i < 100; i++) {
      filename[7] = '0' + i/10;
      filename[8] = '0' + i%10;
      // create if does not exist, do not open existing, write, sync after write
      if (! SD.exists(filename)) {
        break;
      }
    }
    root = SD.open(filename, FILE_WRITE);
    if( ! root ) {
      Serial.print("Couldn't create ");
      Serial.println(filename);
      errno(3);
    }

    strcpy(filename, March);
    for (uint8_t i = 0; i < 100; i++) {
      filename[7] = '0' + i/10;
      filename[8] = '0' + i%10;
      // create if does not exist, do not open existing, write, sync after write
      if (! SD.exists(filename)) {
        break;
      }
    }
    root = SD.open(filename, FILE_WRITE);
    if( ! root ) {
      Serial.print("Couldn't create ");
      Serial.println(filename);
      errno(3);
    }

    strcpy(filename, April);
    for (uint8_t i = 0; i < 100; i++) {
      filename[7] = '0' + i/10;
      filename[8] = '0' + i%10;
      // create if does not exist, do not open existing, write, sync after write
      if (! SD.exists(filename)) {
        break;
      }
    }
    root = SD.open(filename, FILE_WRITE);
    if( ! root ) {
      Serial.print("Couldn't create ");
      Serial.println(filename);
      errno(3);
    }

    strcpy(filename, May);
    for (uint8_t i = 0; i < 100; i++) {
      filename[7] = '0' + i/10;
      filename[8] = '0' + i%10;
      // create if does not exist, do not open existing, write, sync after write
      if (! SD.exists(filename)) {
        break;
      }
    }
    root = SD.open(filename, FILE_WRITE);
    if( ! root ) {
      Serial.print("Couldn't create ");
      Serial.println(filename);
      errno(3);
    }

    strcpy(filename, June);
    for (uint8_t i = 0; i < 100; i++) {
      filename[7] = '0' + i/10;
      filename[8] = '0' + i%10;
      // create if does not exist, do not open existing, write, sync after write
      if (! SD.exists(filename)) {
        break;
      }
    }
    root = SD.open(filename, FILE_WRITE);
    if( ! root ) {
      Serial.print("Couldn't create ");
      Serial.println(filename);
      errno(3);
    }

    strcpy(filename, July);
    for (uint8_t i = 0; i < 100; i++) {
      filename[7] = '0' + i/10;
      filename[8] = '0' + i%10;
      // create if does not exist, do not open existing, write, sync after write
      if (! SD.exists(filename)) {
        break;
      }
    }
    root = SD.open(filename, FILE_WRITE);
    if( ! root ) {
      Serial.print("Couldn't create ");
      Serial.println(filename);
      errno(3);
    }

    strcpy(filename, Aug);
    for (uint8_t i = 0; i < 100; i++) {
      filename[7] = '0' + i/10;
      filename[8] = '0' + i%10;
      // create if does not exist, do not open existing, write, sync after write
      if (! SD.exists(filename)) {
        break;
      }
    }
    root = SD.open(filename, FILE_WRITE);
    if( ! root ) {
      Serial.print("Couldn't create ");
      Serial.println(filename);
      errno(3);
    }

    strcpy(filename, Sept);
    for (uint8_t i = 0; i < 100; i++) {
      filename[7] = '0' + i/10;
      filename[8] = '0' + i%10;
      // create if does not exist, do not open existing, write, sync after write
      if (! SD.exists(filename)) {
        break;
      }
    }
    root = SD.open(filename, FILE_WRITE);
    if( ! root ) {
      Serial.print("Couldn't create ");
      Serial.println(filename);
      errno(3);
    }

    strcpy(filename, Oct);
    for (uint8_t i = 0; i < 100; i++) {
      filename[7] = '0' + i/10;
      filename[8] = '0' + i%10;
      // create if does not exist, do not open existing, write, sync after write
      if (! SD.exists(filename)) {
        break;
      }
    }
    root = SD.open(filename, FILE_WRITE);
    if( ! root ) {
      Serial.print("Couldn't create ");
      Serial.println(filename);
      errno(3);
    }

    strcpy(filename, Nov);
    for (uint8_t i = 0; i < 100; i++) {
      filename[7] = '0' + i/10;
      filename[8] = '0' + i%10;
      // create if does not exist, do not open existing, write, sync after write
      if (! SD.exists(filename)) {
        break;
      }
    }
    root = SD.open(filename, FILE_WRITE);
    if( ! root ) {
      Serial.print("Couldn't create ");
      Serial.println(filename);
      errno(3);
    }

    strcpy(filename, Dec);
    for (uint8_t i = 0; i < 100; i++) {
      filename[7] = '0' + i/10;
      filename[8] = '0' + i%10;
      // create if does not exist, do not open existing, write, sync after write
      if (! SD.exists(filename)) {
        break;
      }
    }
    root = SD.open(filename, FILE_WRITE);
    if( ! root ) {
      Serial.print("Couldn't create ");
      Serial.println(filename);
      errno(3);
    }
    Serial.println("Files Ready!");

}

// store error strings in flash to save RAM
#define error(s) error_P(PSTR(s))
void error_P(const char* str) {
  Serial.print(F("error: "));
  Serial.println(str);

  while(1);
}

void DATALOGS() {
  DateTime now = rtc.now();
  root.print(now.year(), DEC);
  root.print('/');
  root.print(now.month(), DEC);
  root.print('/');
  root.print(now.day(), DEC);
  root.print(" (");
  root.print(daysOfTheWeek[now.dayOfTheWeek()]);
  root.print(") ");
  root.print(now.hour(), DEC);
  root.print(':');
  root.print(now.minute(), DEC);
  root.print(" ");
  root.print("vTest: ");
  root.print(vtest_avgerage * 0.00201416);
  root.print("  ");
  root.print("Wind Speed: ");
  root.print(windSpeed);
  root.print("  ");
  root.print("Dump: ");
  root.print(dumpaverage * 0.00201416);
  root.print("  ");
  root.print("Warn: ");
  root.print(warning_avg * 0.00201416);
  root.print(" ");
  root.print("iBat: ");
  root.print(volts0);
  root.print("  ");
  root.print("vBat: ");
  root.print(volts1);
  root.print("  ");
  root.print("vTurb: ");
  root.print(volts2);
  root.print("  ");
  root.print("iTurb: ");
  root.print(volts3);
  root.print("  ");
  root.print("\r\n");
  root.close();
}

void DATALOGS_WIND() {
  DateTime now = rtc.now();
  root.print(now.year(), DEC);
  root.print('/');
  root.print(now.month(), DEC);
  root.print('/');
  root.print(now.day(), DEC);
  root.print(" (");
  root.print(daysOfTheWeek[now.dayOfTheWeek()]);
  root.print(") ");
  root.print(now.hour(), DEC);
  root.print(':');
  root.print(now.minute(), DEC);
  root.print("  ");
  root.print(windSpeed);
  root.print("\r\n");
  root.close();
}

void AnologeOutput() {
  Serial.println(AI0, DEC);
  Serial.println(AI1, DEC);
  Serial.println(AI2, DEC);
  Serial.println(AI3, DEC);
  Serial.println(AI4, DEC);
  Serial.println(AI5, DEC);
}
void AnalogWrite_A0() { //AC Output
  if (SDWriteDelay.justFinished()) {
      SDWriteDelay.repeat();
      VoltSD = !VoltSD;
      if (VoltSD) {
        vtest_avg[numReadings] = analogRead(vtestpin);
        for (unsigned int vtest_readIndex = 0; vtest_readIndex < (sizeof(vtest_avg[16])/sizeof(vtest_avg[0])); vtest_readIndex++) {
          vtest_sum += vtest_avg[vtest_readIndex] ;
        }
        vtest_avgerage = vtest_avg[numReadings];
        Serial.println("New Timer");
        DateTime now = rtc.now();
        digitalWrite(8, HIGH);
        while (now.month() == 1) {
          root = SD.open(Jan, FILE_WRITE);
          DATALOGS();
          break;
        }
        while (now.month() == 2) {
          root = SD.open(Feb, FILE_WRITE);
          DATALOGS();
          break;
        }
        while (now.month() == 3) {
          root = SD.open(March, FILE_WRITE);
          DATALOGS();
          break;
        }
        while (now.month() == 4) {
          root = SD.open(April, FILE_WRITE);
          DATALOGS();
          break;
        }
        while (now.month() == 5) {
          root = SD.open(May, FILE_WRITE);
          DATALOGS();
          break;
        }
        while (now.month() == 6) {
          root = SD.open(June, FILE_WRITE);
          DATALOGS();
          break;
        }
        while (now.month() == 7) {
          root = SD.open(July, FILE_WRITE);
          DATALOGS();
          break;
        }
        while (now.month() == 8) {
          root = SD.open(Aug, FILE_WRITE);
          DATALOGS();
          break;
        }
        while (now.month() == 9) {
          root = SD.open(Sept, FILE_WRITE);
          DATALOGS();
          break;
        }
        while (now.month() == 10) {
          root = SD.open(Oct, FILE_WRITE);
          DATALOGS();
          break;
        }
        while (now.month() == 11) {
          root = SD.open(Nov, FILE_WRITE);
          DATALOGS();
          break;
        }
        while (now.month() == 12) {
          root = SD.open(Dec, FILE_WRITE);
          DATALOGS();
          break;
        }
        root = SD.open(DATALOGSYEAR, FILE_WRITE);
        root.print(now.year(), DEC);
        root.print('/');
        root.print(now.month(), DEC);
        root.print('/');
        root.print(now.day(), DEC);
        root.print(" (");
        root.print(daysOfTheWeek[now.dayOfTheWeek()]);
        root.print(") ");
        root.print(now.hour(), DEC);
        root.print(':');
        root.print(now.minute(), DEC);
        root.print("  ");
        root.print(vtest_avgerage * (3.3/1024));
        root.print("\r\n");
        root.close();
        // DATALOGS();
        // delay(5000);
      }
    }
  }
void SDLogs(void) { //AC Output
      if (SDWriteDelay.justFinished()) {
          SDWriteDelay.repeat();
          VoltSD = !VoltSD;
          if (VoltSD) {
            vtest_avg[numReadings] = analogRead(A0);
            for (unsigned int vtest_readIndex = 0; vtest_readIndex < (sizeof(vtest_avg[16])/sizeof(vtest_avg[0])); vtest_readIndex++) {
              vtest_sum += vtest_avg[vtest_readIndex] ;
            }
            vtest_avgerage = vtest_avg[numReadings];

            sensorValue = analogRead(A1); //Get a value between 0 and 1023 from the analog pin connected to the anemometer
            sensorVoltage = sensorValue * voltageConversionConstant;
            if (sensorVoltage <= 0.4){
              windSpeed = 0; //Check if voltage is below minimum value. If so, set wind speed to zero.
            }else {
              windSpeed = (sensorVoltage - voltageMin)*windSpeedMax/(voltageMax - voltageMin);
            }

            dump_avg[numReadingsdump] = analogRead(A2);
            for (unsigned int dump_readIndex = 0; dump_readIndex < (sizeof(dump_avg[16])/sizeof(dump_avg[0])); dump_readIndex++) {
              dump_sum += dump_avg[dump_readIndex];
            }
            dumpaverage = dump_avg[numReadingsdump];

            warn_avg[numReadingsWarn] = analogRead(A3);
            for (unsigned int warn_readIndex = 0; warn_readIndex < (sizeof(warn_avg[16])/sizeof(warn_avg[0])); warn_readIndex++) {
              warn_sum += warn_avg[warn_readIndex];
            }
            warning_avg = warn_avg[numReadingsWarn];

            float volts1;
            vbat_avg[numReadingsBattery] = ads1115.readADC_SingleEnded(1);
            for (unsigned int vbat_readIndex = 0; vbat_readIndex < (sizeof(vbat_avg[16])/sizeof(vbat_avg[0])); vbat_readIndex++) {
              vbat_sum += vbat_avg[vbat_readIndex] ;
            }
            battery_avg = vbat_avg[numReadingsBattery];
            volts1 = ads1115.computeVolts(battery_avg);

            float volts0;
            ibat_avg[numReadingsIBat] = ads1115.readADC_SingleEnded(0);
            for (unsigned int ibat_readIndex = 0; ibat_readIndex < (sizeof(ibat_avg[16])/sizeof(ibat_avg[0])); ibat_readIndex++) {
              ibat_sum += ibat_avg[ibat_readIndex] ;
            }
            ibat_average = ibat_avg[numReadingsIBat];
            volts0 = ads1115.computeVolts(ibat_average);

            float volts2;
            vturb_avg[numReadingsVturb] = ads1115.readADC_SingleEnded(2);
            for (unsigned int vturb_readIndex = 0; vturb_readIndex < (sizeof(vturb_avg[16])/sizeof(vturb_avg[0])); vturb_readIndex++) {
              vturb_sum += vturb_avg[vturb_readIndex] ;
            }
            vturb_average = vturb_avg[numReadingsVturb];
            volts2 = ads1115.computeVolts(vturb_average);

            float volts3;
            iturb_avg[numReadingsIturb] = ads1115.readADC_SingleEnded(3);
            for (unsigned int iturb_readIndex = 0; iturb_readIndex < (sizeof(iturb_avg[16])/sizeof(iturb_avg[0])); iturb_readIndex++) {
              iturb_sum += iturb_avg[iturb_readIndex] ;
            }
            iturb_average = iturb_avg[numReadingsIturb];
            volts3 = ads1115.computeVolts(iturb_average);

            // Serial.println(stat_avg[numReadings] * (3.3/1024));
            // Serial.println(stat_avg[numReadings] * (3.3/1024));
            Serial.println("New Timer");
            DateTime now = rtc.now();
            digitalWrite(8, HIGH);
            while (now.month() == 1) {
              root = SD.open(Jan, FILE_WRITE);
              DATALOGS();
              break;
            }
            while (now.month() == 2) {
              root = SD.open(Feb, FILE_WRITE);
              DATALOGS();
              break;
            }
            while (now.month() == 3) {
              root = SD.open(March, FILE_WRITE);
              DATALOGS();
              break;
            }
            while (now.month() == 4) {
              root = SD.open(April, FILE_WRITE);
              DATALOGS();
              break;
            }
            while (now.month() == 5) {
              root = SD.open(May, FILE_WRITE);
              DATALOGS();
              break;
            }
            while (now.month() == 6) {
              root = SD.open(June, FILE_WRITE);
              DATALOGS();
              break;
            }
            while (now.month() == 7) {
              root = SD.open(July, FILE_WRITE);
              DATALOGS();
              break;
            }
            while (now.month() == 8) {
              root = SD.open(Aug, FILE_WRITE);
              DATALOGS();
              break;
            }
            while (now.month() == 9) {
              root = SD.open(Sept, FILE_WRITE);
              DATALOGS();
              break;
            }
            while (now.month() == 10) {
              root = SD.open(Oct, FILE_WRITE);
              DATALOGS();
              break;
            }
            while (now.month() == 11) {
              root = SD.open(Nov, FILE_WRITE);
              DATALOGS();
              break;
            }
            while (now.month() == 12) {
              root = SD.open(Dec, FILE_WRITE);
              DATALOGS();
              break;
            }
            root = SD.open(DATALOGSYEAR, FILE_WRITE);
            root.print(now.year(), DEC);
            root.print('/');
            root.print(now.month(), DEC);
            root.print('/');
            root.print(now.day(), DEC);
            root.print(" (");
            root.print(daysOfTheWeek[now.dayOfTheWeek()]);
            root.print(") ");
            root.print(now.hour(), DEC);
            root.print(':');
            root.print(now.minute(), DEC);
            root.print(" ");
            root.print("vTest: ");
            root.print(vtest_avgerage * 0.00201416);
            root.print("  ");
            root.print("Wind Speed: ");
            root.print(windSpeed);
            root.print("  ");
            root.print("Dump: ");
            root.print(dumpaverage * 0.00201416);
            root.print("  ");
            root.print("Warn: ");
            root.print(warning_avg * 0.00201416);
            root.print(" ");
            root.print("iBat: ");
            root.print(volts0);
            root.print("  ");
            root.print("vBat: ");
            root.print(volts1);
            root.print("  ");
            root.print("vTurb: ");
            root.print(volts2);
            root.print("  ");
            root.print("iTurb: ");
            root.print(volts3);
            root.print("  ");
            root.print("\r\n");
            root.close();
            // delay(5000);
          }
        }
      }
//Main Settings for board
void setup() {
    Serial.begin(115200);
    // while (!Serial);      // For 32u4 based microcontrollers like 32u4 Adalogger Feather
    if (!SD.begin(SDCARD_CS)) {
      error("card.init failed!");
    }
    // SD_Files();
    root = SD.open("/");
    printDirectory(root, 0);
    Serial.println(F("Files found in all dirs:"));
    printDirectory(root, 0);
    Serial.println();
    Serial.println(F("Done"));
    // SD_init();
    // SD_Files();

    Serial.println(F("Initializing WizNet"));
    Ethernet.init(13);
    Ethernet.begin(mac, ip);
    // Ethernet.begin(mac);
    Serial.print(F("My IP address: "));
    Serial.println(Ethernet.localIP());
    // wifi_init(); //Connect to routers WiFi init for WiFi
    // ntp_clock(); //Get Date and Time from Ethernet or WiFi
    wifi_init_ap(); // Init for local AP WiFi
    Serial.println(WiFi.localIP());
    server.begin();
    display.begin(0x3C, true); //display info
    display.clearDisplay();
    display.display();
    display.setRotation(1);
    Menu_init();
    ads1115.setGain(GAIN_TWOTHIRDS);
    pinMode(A0, OUTPUT);
    pinMode(A1, OUTPUT);
    pinMode(A2, OUTPUT);
    pinMode(A4, OUTPUT);
    pinMode(A5, OUTPUT);
    pinMode(13, OUTPUT);
    pinMode(8, OUTPUT);
    delayRunning = true;
    SDWriteDelay.start(5000); //SD Write Delay in milliseconds
    // ads1115.setGain(GAIN_TWOTHIRDS);
    // SDWriteDelay2.start(5000);
    // rtc.adjust(DateTime(2021, 6, 15, 2, 00, 0));
}

//Main Loop
void loop(void) {
 clientfile_Host();
 WiFiAP_Main();
 SDLogs();
 drawMenu();
 upButtonState = digitalRead(9);
 downButtonState = digitalRead(6);
 selectButtonState = digitalRead(5);

 checkIfDownButtonIsPressed();
 checkIfUpButtonIsPressed();
 SelectButton();
 menubuttons();
}

wifi password file:
wifilogin.h

// #define SECRET_SSID "ETnet-5Ghz"
// #define SECRET_PASS "ETfiwi2021"

#define SECRET_SSID "EVOLVE"
#define SECRET_PASS "evolvemusic"

// #define SECRET_SSID "Da  Router"
// #define SECRET_PASS ""

Any help would be greatly apreciated.

Thanks You,
John Mulholland

please edit you post by posting your lengthy code using </>

is there only one file?

1 Like

No there are two files for the program. I am using Atom io and Platformio. I will edit the post, sorry about that :smile:

The only String you are using (in the code proved in #1) is here

 if (client) {                             // if you get a client,
    Serial.println("new client");           // print a message out the serial port
    String currentLine = "";
  .  .  .

which gets cleaned up at the end of that block, but there may be some interaction with other Strings used in the wifi libraries.

You could try moving that String to a global are reserving space with reserve( )
See Taming Arduino Strings for more details and for a class to test that you have reserved enough space.

Other than that, try stripping down your code until it works and then add a little bit back in at a time and see when it brakes. I would start with just the Wifi stuff and then add the SD stuff next

Try passing your client and File parameters by reference

Nevermind I found the issue, forgot to initiate the ADS1115, and the ground wire was not correct.