// call libraries
#include <EEPROM.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <Arduino.h>
#include "TCA9548A.h"
#include <Adafruit_NeoPixel.h>

/* 
=========================
DISPLAY SECTION
all of the OLED display
business is defined here
=========================
*/

// define the height and width of the OLED (pixels)
#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 32
#define OLED_RESET     4      // Reset pin hard coded into the OLED Library (use -1 if sharing Arduino reset pin)
#define SCREEN_ADDRESS 0x3C   // 0x3C is hard coded into the 128x32 OLED.

Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);

// define height and width for drawing bitmaps
#define LOGO_HEIGHT   128
#define LOGO_WIDTH    32

/* 
=========================
BUTTON SECTION
all of the input button
business is defined here
=========================
*/

// declare the input pins for the push buttons.
int button_mon_pin = 52;
int button_tue_pin = 50;
int button_wed_pin = 48;
int button_thu_pin = 46;
int button_fri_pin = 44;
int button_sat_pin = 42;
int button_sun_pin = 40;
int button_up_pin = 38;
int button_down_pin = 36;
/* 
=========================
EEPROM Address
Memory allocation etc.
=========================
*/
int eeprom_integer_mon_dist = 0;
int eeprom_decimal_mon_dist = 1;

int eeprom_integer_tue_dist = 2;
int eeprom_decimal_tue_dist = 3;

int eeprom_integer_wed_dist = 4;
int eeprom_decimal_wed_dist = 5;

int eeprom_integer_thu_dist = 6;
int eeprom_decimal_thu_dist = 7;

int eeprom_integer_fri_dist = 8;
int eeprom_decimal_fri_dist = 9;

int eeprom_integer_sat_dist = 10;
int eeprom_decimal_sat_dist = 11;

int eeprom_integer_sun_dist = 12;
int eeprom_decimal_sun_dist = 13;

/*
=========================
target memory addresses
=========================
*/
int eeprom_integer_mon_targ = 14;
int eeprom_decimal_mon_targ = 15;

int eeprom_integer_tue_targ = 16;
int eeprom_decimal_tue_targ = 17;

int eeprom_integer_wed_targ = 18;
int eeprom_decimal_wed_targ = 19;

int eeprom_integer_thu_targ = 20;
int eeprom_decimal_thu_targ = 21;

int eeprom_integer_fri_targ = 22;
int eeprom_decimal_fri_targ = 23;

int eeprom_integer_sat_targ = 24;
int eeprom_decimal_sat_targ = 25;

int eeprom_integer_sun_targ = 26;
int eeprom_decimal_sun_targ = 27;


float eeprom_calc_mon_dist;
float eeprom_calc_mon_targ;

float eeprom_calc_tue_dist;
float eeprom_calc_tue_targ;

float eeprom_calc_wed_dist;
float eeprom_calc_wed_targ;

float eeprom_calc_thu_dist;
float eeprom_calc_thu_targ;

float eeprom_calc_fri_dist;
float eeprom_calc_fri_targ;

float eeprom_calc_sat_dist;
float eeprom_calc_sat_targ;

float eeprom_calc_sun_dist;
float eeprom_calc_sun_targ;

/* 
=========================
I2C Multiplexing
all of the I2C Mux
addressing is defined here
=========================
*/

// declare the TCA 9548A as I2CMux
TCA9548A I2CMux;

// name all of the OLED displays for I2C MUX addressing.
int oled_mon = 0;
int oled_tue = 1;
int oled_wed = 2;
int oled_thu = 3;
int oled_fri = 4;
int oled_sat = 5;
int oled_sun = 6;
/* 
=========================
PIXEL LED SECTION
=========================
*/
// pixels(number_of_pixels, pixel_data_pin, NEO_GRB, + NEOKHZ800)
Adafruit_NeoPixel pixels(7, 30, NEO_GRB + NEO_KHZ800);

int mon_pixel = 0;
int tue_pixel = 1;
int wed_pixel = 2;
int thu_pixel = 3;
int fri_pixel = 4;
int sat_pixel = 5;
int sun_pixel = 6;
/* 
=========================
MUSIC SFX SECTION
=========================
*/
int mon_sound = 53;
int tue_sound = 51;
int wed_sound = 49;
int thu_sound = 47;
int fri_sound = 45;
int sat_sound = 43;
int sun_sound = 41;
/* 
=========================
MISCELLANEOUS
floats for point operations
calculations etc are dealt
with here.
=========================
*/
// distance ran per day
float distance_mon = 0.0;
float distance_tue = 0.0;
float distance_wed = 0.0;
float distance_thu = 0.0;
float distance_fri = 0.0;
float distance_sat = 0.0;
float distance_sun = 0.0;

// targets for each day
float target_mon = 0.0;
float target_tue = 0.0;
float target_wed = 0.0;
float target_thu = 0.0;
float target_fri = 0.0;
float target_sat = 0.0;
float target_sun = 0.0;

float result;

// button states for each day button (and up for reset)
bool button_state_mon = false;
bool button_state_tue = false;
bool button_state_wed = false;
bool button_state_thu = false;
bool button_state_fri = false;
bool button_state_sat = false;
bool button_state_sun = false;
bool button_state_up = false;

// button states for long presses (one for each day, including up for reset)
bool button_state_mon_long = false;
bool button_state_tue_long = false;
bool button_state_wed_long = false;
bool button_state_thu_long = false;
bool button_state_fri_long = false;
bool button_state_sat_long = false;
bool button_state_sun_long = false;
bool button_state_up_long = false;
/* 
=========================
STORED BITMAPS
all of the stored bitmaps
are dealt with here
=========================
*/
const unsigned char PROGMEM target_ran_bmp [] = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0xD2, 0x00, 0x03, 0xE0, 0xF0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x02, 0x10, 0x80, 0x01, 0xF0, 0xF8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x08, 0x10, 0x20, 0x00, 0xF0, 0x7C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x10, 0x10, 0x10, 0x00, 0xF8, 0x3C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x10, 0x00, 0x00, 0x7C, 0x3E, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x20, 0x00, 0x08, 0x00, 0x3C, 0x1F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x04, 0x00, 0x3E, 0x0F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x40, 0x00, 0x04, 0x00, 0x1F, 0x0F, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x40, 0x00, 0x00, 0x00, 0x0F, 0x07, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x0F, 0x83, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x03, 0xFC, 0x00, 0x7F, 0x80, 0x07, 0x83, 0xE0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x0F, 0x83, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x40, 0x00, 0x00, 0x00, 0x0F, 0x07, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x40, 0x00, 0x04, 0x00, 0x1F, 0x07, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x04, 0x00, 0x3E, 0x0F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x20, 0x00, 0x00, 0x00, 0x3C, 0x1F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x10, 0x08, 0x00, 0x7C, 0x1E, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x10, 0x10, 0x10, 0x00, 0xF8, 0x3C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x08, 0x10, 0x20, 0x00, 0xF0, 0x7C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x02, 0x10, 0x40, 0x01, 0xF0, 0x78, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x01, 0x93, 0x00, 0x01, 0xE0, 0xF0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};

const unsigned char PROGMEM distance_ran_bmp [] = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0xF0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x01, 0xF8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x01, 0xF8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x01, 0x81, 0xF8, 0x03, 0xE0, 0xF0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x07, 0xF8, 0xF0, 0x01, 0xF0, 0xF8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x0F, 0xFE, 0x00, 0x00, 0xF0, 0x7C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x1C, 0x3F, 0x00, 0x00, 0xF8, 0x3C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x38, 0x3F, 0x00, 0x00, 0x7C, 0x3E, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x70, 0x3F, 0x80, 0x00, 0x3C, 0x1F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x20, 0x7F, 0x80, 0x00, 0x3E, 0x0F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x7D, 0xC0, 0x00, 0x1F, 0x0F, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0xF9, 0xE0, 0x00, 0x0F, 0x07, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x01, 0xF8, 0xFF, 0x80, 0x0F, 0x83, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x01, 0xF0, 0x7F, 0x80, 0x07, 0x83, 0xE0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x03, 0xE0, 0x00, 0x00, 0x0F, 0x83, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x07, 0xE0, 0x00, 0x00, 0x0F, 0x07, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x0F, 0xC0, 0x00, 0x00, 0x1F, 0x07, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x0F, 0xF0, 0x00, 0x00, 0x3E, 0x0F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x1C, 0xF8, 0x00, 0x00, 0x3C, 0x1F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x3F, 0xFC, 0x3C, 0x00, 0x00, 0x7C, 0x1E, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x3F, 0xF8, 0x1E, 0x00, 0x00, 0xF8, 0x3C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x1F, 0xF0, 0x0E, 0x00, 0x00, 0xF0, 0x7C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x0E, 0x00, 0x01, 0xF0, 0x78, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x1C, 0x00, 0x01, 0xE0, 0xF0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x1C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x38, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x38, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
/* 
=========================
DRAW BITMAPS CALLBACKS
=========================
*/
void draw_target()
{
  display.clearDisplay();
  display.drawBitmap(0, 0, target_ran_bmp, LOGO_HEIGHT, LOGO_WIDTH, SSD1306_INVERSE);
  display.setTextSize(2);
  display.setTextColor(SSD1306_WHITE);
  display.setCursor(65,10);
  display.println("TARG.");
  display.display();
}

void draw_distance()
{
  display.clearDisplay();
  display.drawBitmap(0, 0, distance_ran_bmp, LOGO_HEIGHT, LOGO_WIDTH, SSD1306_INVERSE);
  display.setTextSize(2);
  display.setTextColor(SSD1306_WHITE);
  display.setCursor(65,10);
  display.println("DIST.");
  display.display();
}
/*
=========================
SAVE DISTANCE CALLBACKS
=========================
 */
void save_eeprom_mon_distance()
{
  int whole = distance_mon;                       // truncates decimal e.g. 3.17 to just 3
  int remainder = ((distance_mon - whole)*100);   // remainder makes the decimal a whole number (integer)
  EEPROM.write(eeprom_integer_mon_dist, whole);
  EEPROM.write(eeprom_decimal_mon_dist, remainder);
}

void save_eeprom_tue_distance()
{
  int whole = distance_tue;                       // truncates decimal e.g. 3.17 to just 3
  int remainder = ((distance_tue - whole)*100);   // remainder makes the decimal a whole number (integer)
  EEPROM.write(eeprom_integer_tue_dist, whole);
  EEPROM.write(eeprom_decimal_tue_dist, remainder);
}

void save_eeprom_wed_distance()
{
  int whole = distance_wed;                       // truncates decimal e.g. 3.17 to just 3
  int remainder = ((distance_wed - whole)*100);   // remainder makes the decimal a whole number (integer)
  EEPROM.write(eeprom_integer_wed_dist, whole);
  EEPROM.write(eeprom_decimal_wed_dist, remainder);
}

void save_eeprom_thu_distance()
{
  int whole = distance_thu;                       // truncates decimal e.g. 3.17 to just 3
  int remainder = ((distance_thu - whole)*100);   // remainder makes the decimal a whole number (integer)
  EEPROM.write(eeprom_integer_thu_dist, whole);
  EEPROM.write(eeprom_decimal_thu_dist, remainder);
}

void save_eeprom_fri_distance()
{
  int whole = distance_fri;                       // truncates decimal e.g. 3.17 to just 3
  int remainder = ((distance_fri - whole)*100);   // remainder makes the decimal a whole number (integer)
  EEPROM.write(eeprom_integer_fri_dist, whole);
  EEPROM.write(eeprom_decimal_fri_dist, remainder);
}

void save_eeprom_sat_distance()
{
  int whole = distance_sat;                       // truncates decimal e.g. 3.17 to just 3
  int remainder = ((distance_sat - whole)*100);   // remainder makes the decimal a whole number (integer)
  EEPROM.write(eeprom_integer_sat_dist, whole);
  EEPROM.write(eeprom_decimal_sat_dist, remainder);
}

void save_eeprom_sun_distance()
{
  int whole = distance_sun;                       // truncates decimal e.g. 3.17 to just 3
  int remainder = ((distance_sun - whole)*100);   // remainder makes the decimal a whole number (integer)
  EEPROM.write(eeprom_integer_sun_dist, whole);
  EEPROM.write(eeprom_decimal_sun_dist, remainder);
}
/*
==========================================================
CALL BACKS FOR TARGET SAVING
==========================================================
 */
void save_eeprom_mon_target()
{
  int whole = target_mon;                       // truncates decimal e.g. 3.17 to just 3
  int remainder = ((target_mon - whole)*100);   // remainder makes the decimal a whole number (integer)
  EEPROM.write(eeprom_integer_mon_targ, whole);
  EEPROM.write(eeprom_decimal_mon_targ, remainder);
}

void save_eeprom_tue_target()
{
  int whole = target_tue;                       // truncates decimal e.g. 3.17 to just 3
  int remainder = ((target_tue - whole)*100);   // remainder makes the decimal a whole number (integer)
  EEPROM.write(eeprom_integer_tue_targ, whole);
  EEPROM.write(eeprom_decimal_tue_targ, remainder);
}

void save_eeprom_wed_target()
{
  int whole = target_wed;                       // truncates decimal e.g. 3.17 to just 3
  int remainder = ((target_wed - whole)*100);   // remainder makes the decimal a whole number (integer)
  EEPROM.write(eeprom_integer_wed_targ, whole);
  EEPROM.write(eeprom_decimal_wed_targ, remainder);
}

void save_eeprom_thu_target()
{
  int whole = target_thu;                       // truncates decimal e.g. 3.17 to just 3
  int remainder = ((target_thu - whole)*100);   // remainder makes the decimal a whole number (integer)
  EEPROM.write(eeprom_integer_thu_targ, whole);
  EEPROM.write(eeprom_decimal_thu_targ, remainder);
}

void save_eeprom_fri_target()
{
  int whole = target_fri;                       // truncates decimal e.g. 3.17 to just 3
  int remainder = ((target_fri - whole)*100);   // remainder makes the decimal a whole number (integer)
  EEPROM.write(eeprom_integer_fri_targ, whole);
  EEPROM.write(eeprom_decimal_fri_targ, remainder);
}

void save_eeprom_sat_target()
{
  int whole = target_sat;                       // truncates decimal e.g. 3.17 to just 3
  int remainder = ((target_sat - whole)*100);   // remainder makes the decimal a whole number (integer)
  EEPROM.write(eeprom_integer_sat_targ, whole);
  EEPROM.write(eeprom_decimal_sat_targ, remainder);
}

void save_eeprom_sun_target()
{
  int whole = target_sun;                       // truncates decimal e.g. 3.17 to just 3
  int remainder = ((target_sun - whole)*100);   // remainder makes the decimal a whole number (integer)
  EEPROM.write(eeprom_integer_sun_targ, whole);
  EEPROM.write(eeprom_decimal_sun_targ, remainder);
}
/*
=================================================
CALLBACKS FOR READING DISTANCE EEPROM
=================================================
 */
void read_eeprom_mon_dist()
{
  float integer = EEPROM.read(eeprom_integer_mon_dist);
  float decimal = EEPROM.read(eeprom_decimal_mon_dist);
  eeprom_calc_mon_dist = (((integer*100)+decimal)/100);
  return eeprom_calc_mon_dist;
}

void read_eeprom_tue_dist()
{
  float integer = EEPROM.read(eeprom_integer_tue_dist);
  float decimal = EEPROM.read(eeprom_decimal_tue_dist);
  eeprom_calc_tue_dist = (((integer*100)+decimal)/100);
  return eeprom_calc_tue_dist;
}

void read_eeprom_wed_dist()
{
  float integer = EEPROM.read(eeprom_integer_wed_dist);
  float decimal = EEPROM.read(eeprom_decimal_wed_dist);
  eeprom_calc_wed_dist = (((integer*100)+decimal)/100);
  return eeprom_calc_wed_dist;
}

void read_eeprom_thu_dist()
{
  float integer = EEPROM.read(eeprom_integer_thu_dist);
  float decimal = EEPROM.read(eeprom_decimal_thu_dist);
  eeprom_calc_thu_dist = (((integer*100)+decimal)/100);
  return eeprom_calc_thu_dist;
}

void read_eeprom_fri_dist()
{
  float integer = EEPROM.read(eeprom_integer_fri_dist);
  float decimal = EEPROM.read(eeprom_decimal_fri_dist);
  eeprom_calc_fri_dist = (((integer*100)+decimal)/100);
  return eeprom_calc_fri_dist;
}

void read_eeprom_sat_dist()
{
  float integer = EEPROM.read(eeprom_integer_sat_dist);
  float decimal = EEPROM.read(eeprom_decimal_sat_dist);
  eeprom_calc_sat_dist = (((integer*100)+decimal)/100);
  return eeprom_calc_sat_dist;
}

void read_eeprom_sun_dist()
{
  float integer = EEPROM.read(eeprom_integer_sun_dist);
  float decimal = EEPROM.read(eeprom_decimal_sun_dist);
  eeprom_calc_sun_dist = (((integer*100)+decimal)/100);
  return eeprom_calc_sun_dist;
}
/*
=================================
CALLBACKS TO READ EEPROM TARGETS
=================================
 */
void read_eeprom_mon_targ()
{
  float integer = EEPROM.read(eeprom_integer_mon_targ);
  float decimal = EEPROM.read(eeprom_decimal_mon_targ);
  eeprom_calc_mon_targ = (((integer*100)+decimal)/100);
  return eeprom_calc_mon_targ;
}

void read_eeprom_tue_targ()
{
  float integer = EEPROM.read(eeprom_integer_tue_targ);
  float decimal = EEPROM.read(eeprom_decimal_tue_targ);
  eeprom_calc_tue_targ = (((integer*100)+decimal)/100);
  return eeprom_calc_tue_targ;
}

void read_eeprom_wed_targ()
{
  float integer = EEPROM.read(eeprom_integer_wed_targ);
  float decimal = EEPROM.read(eeprom_decimal_wed_targ);
  eeprom_calc_wed_targ = (((integer*100)+decimal)/100);
  return eeprom_calc_wed_targ;
}

void read_eeprom_thu_targ()
{
  float integer = EEPROM.read(eeprom_integer_thu_targ);
  float decimal = EEPROM.read(eeprom_decimal_thu_targ);
  eeprom_calc_thu_targ = (((integer*100)+decimal)/100);
  return eeprom_calc_thu_targ;
}

void read_eeprom_fri_targ()
{
  float integer = EEPROM.read(eeprom_integer_fri_targ);
  float decimal = EEPROM.read(eeprom_decimal_fri_targ);
  eeprom_calc_fri_targ = (((integer*100)+decimal)/100);
  return eeprom_calc_fri_targ;
}

void read_eeprom_sat_targ()
{
  float integer = EEPROM.read(eeprom_integer_sat_targ);
  float decimal = EEPROM.read(eeprom_decimal_sat_targ);
  eeprom_calc_sat_targ = (((integer*100)+decimal)/100);
  return eeprom_calc_sat_targ;
}

void read_eeprom_sun_targ()
{
  float integer = EEPROM.read(eeprom_integer_sun_targ);
  float decimal = EEPROM.read(eeprom_decimal_sun_targ);
  eeprom_calc_sun_targ = (((integer*100)+decimal)/100);
  return eeprom_calc_sun_targ;
}
/*
============================================
CALLBACKS TO READ BUTTON STATUSES
============================================
 */
void read_button_up()
{ 
  unsigned long start_timer = millis();
  while (digitalRead(button_up_pin) == HIGH)
  {
    button_state_up = true;
    delay(1000);
  }
  unsigned long end_timer = millis();
  result = end_timer - start_timer;

  if (result < 3000)                          // the long press time is set to 3 seconds
  {
    button_state_up_long = false;
  }
  else
  {
    button_state_up_long = true;
  }
  return result;
}

void read_button_mon()  // this function determines if the button was a long or short press.
                        // However it is only coded to Monday! Distance and Targets
{ 
  unsigned long start_timer = millis();
  while (digitalRead(button_mon_pin) == HIGH) // if the monday pin is HIGH
  {
    button_state_mon = true;                  // set the state boolean to TRUE
    read_eeprom_mon_dist();                   // read the eeprom memory address for Monday's distance
    read_eeprom_mon_targ();                   // read the eeprom memory address for Monday's target
    distance_mon = eeprom_calc_mon_dist;
    target_mon = eeprom_calc_mon_targ;
    delay(1000);                              // software debounce
  }
  
  unsigned long end_timer = millis();
  result = end_timer - start_timer;

  if (result < 3000)                          // the long press time is set to 3 seconds
  {
    button_state_mon_long = false;
  }
  else
  {
    button_state_mon_long = true;
  }
  return result;
}


void read_button_tue()  // this function determines if the button was a long or short press.
                        // However it is only coded to Monday! Distance and Targets
{ 
  unsigned long start_timer = millis();
  while (digitalRead(button_tue_pin) == HIGH) // if the monday pin is HIGH
  {
    button_state_tue = true;                  // set the state boolean to TRUE
    read_eeprom_tue_dist();                   // read the eeprom memory address for Monday's distance
    read_eeprom_tue_targ();                   // read the eeprom memory address for Monday's target
    distance_tue = eeprom_calc_tue_dist;
    target_tue = eeprom_calc_tue_targ;
    delay(1000);                              // software debounce
  }
  
  unsigned long end_timer = millis();
  result = end_timer - start_timer;

  if (result < 3000)                          // the long press time is set to 3 seconds
  {
    button_state_tue_long = false;
  }
  else
  {
    button_state_tue_long = true;
  }
  return result;
}

void read_button_wed()  // this function determines if the button was a long or short press.
                        // However it is only coded to Monday! Distance and Targets
{ 
  unsigned long start_timer = millis();
  while (digitalRead(button_wed_pin) == HIGH) // if the monday pin is HIGH
  {
    button_state_wed = true;                  // set the state boolean to TRUE
    read_eeprom_wed_dist();                   // read the eeprom memory address for Monday's distance
    read_eeprom_wed_targ();                   // read the eeprom memory address for Monday's target
    distance_wed = eeprom_calc_wed_dist;
    target_wed = eeprom_calc_wed_targ;
    delay(1000);                              // software debounce
  }
  
  unsigned long end_timer = millis();
  result = end_timer - start_timer;

  if (result < 3000)                          // the long press time is set to 3 seconds
  {
    button_state_wed_long = false;
  }
  else
  {
    button_state_wed_long = true;
  }
  return result;
}

void read_button_thu()  // this function determines if the button was a long or short press.
                        // However it is only coded to Monday! Distance and Targets
{ 
  unsigned long start_timer = millis();
  while (digitalRead(button_thu_pin) == HIGH) // if the monday pin is HIGH
  {
    button_state_thu = true;                  // set the state boolean to TRUE
    read_eeprom_thu_dist();                   // read the eeprom memory address for Monday's distance
    read_eeprom_thu_targ();                   // read the eeprom memory address for Monday's target
    distance_thu = eeprom_calc_thu_dist;
    target_thu = eeprom_calc_thu_targ;
    delay(1000);                              // software debounce
  }
  
  unsigned long end_timer = millis();
  result = end_timer - start_timer;

  if (result < 3000)                          // the long press time is set to 3 seconds
  {
    button_state_thu_long = false;
  }
  else
  {
    button_state_thu_long = true;
  }
  return result;
}

void read_button_fri()  // this function determines if the button was a long or short press.
                        // However it is only coded to Monday! Distance and Targets
{ 
  unsigned long start_timer = millis();
  while (digitalRead(button_fri_pin) == HIGH) // if the monday pin is HIGH
  {
    button_state_fri = true;                  // set the state boolean to TRUE
    read_eeprom_fri_dist();                   // read the eeprom memory address for Monday's distance
    read_eeprom_fri_targ();                   // read the eeprom memory address for Monday's target
    distance_fri = eeprom_calc_fri_dist;
    target_fri = eeprom_calc_fri_targ;
    delay(1000);                              // software debounce
  }
  
  unsigned long end_timer = millis();
  result = end_timer - start_timer;

  if (result < 3000)                          // the long press time is set to 3 seconds
  {
    button_state_fri_long = false;
  }
  else
  {
    button_state_fri_long = true;
  }
  return result;
}

void read_button_sat()  // this function determines if the button was a long or short press.

{ 
  unsigned long start_timer = millis();
  while (digitalRead(button_sat_pin) == HIGH) // if the monday pin is HIGH
  {
    button_state_sat = true;                  // set the state boolean to TRUE
    read_eeprom_sat_dist();                   // read the eeprom memory address for Monday's distance
    read_eeprom_sat_targ();                   // read the eeprom memory address for Monday's target
    distance_sat = eeprom_calc_sat_dist;
    target_sat = eeprom_calc_sat_targ;
    delay(1000);                              // software debounce
  }
  
  unsigned long end_timer = millis();
  result = end_timer - start_timer;
  if (result < 3000)                          // the long press time is set to 3 seconds
  {
    button_state_sat_long = false;
  }
  else
  {
    button_state_sat_long = true;
  }
  return result;
}

void read_button_sun()  // this function determines if the button was a long or short press.
                        // However it is only coded to Monday! Distance and Targets
{ 
  unsigned long start_timer = millis();
  while (digitalRead(button_sun_pin) == HIGH) // if the monday pin is HIGH
  {
    button_state_sun = true;                  // set the state boolean to TRUE
    read_eeprom_sun_dist();                   // read the eeprom memory address for Monday's distance
    read_eeprom_sun_targ();                   // read the eeprom memory address for Monday's target
    distance_sun = eeprom_calc_sun_dist;
    target_sun = eeprom_calc_sun_targ;
    delay(1000);                              // software debounce
  }
  
  unsigned long end_timer = millis();
  result = end_timer - start_timer;

  if (result < 3000)                          // the long press time is set to 3 seconds
  {
    button_state_sun_long = false;
  }
  else
  {
    button_state_sun_long = true;
  }
  return result;
}
/*
============================================
ANIMATE LED CALLBACKS
============================================
 */
// plays a lovely soft transistioning LED effect.
void animate_led()
{
  int DELAYTIME = 1;  // change the speed of the transitions.
  int R, G, B = 0;    // initialise starting values for colours R, G, and B
  
  for(R; R<255; R++) // red transition up.
  {
    for(int pixel_number = 0; pixel_number < 7; pixel_number++)
    {
      pixels.setPixelColor(pixel_number, pixels.Color(R, G, B));
    }
    pixels.show();
    delay(DELAYTIME);
  }
  
  for(G; G<255; G++) // green transition up.
  {
    for(int pixel_number = 0; pixel_number < 7; pixel_number++)
    {
      pixels.setPixelColor(pixel_number, pixels.Color(R, G, B));
    }
    pixels.show();
    delay(DELAYTIME);
  }

  for(B; B<255; B++) // blue transition up.
  {
    for(int pixel_number = 0; pixel_number < 7; pixel_number++)
    {
      pixels.setPixelColor(pixel_number, pixels.Color(R, G, B));
    }
    pixels.show();
    delay(DELAYTIME);
  }

  
  for(R; R>0; R--) // red transition down.
  {
    for(int pixel_number = 0; pixel_number < 7; pixel_number++)
    {
      pixels.setPixelColor(pixel_number, pixels.Color(R, G, B));
    }
    pixels.show();
    delay(DELAYTIME);
  }
  
  for(G; G>0; G--) // green transition down.
  {
    for(int pixel_number = 0; pixel_number < 7; pixel_number++)
    {
      pixels.setPixelColor(pixel_number, pixels.Color(R, G, B));
    }
    pixels.show();
    delay(DELAYTIME);
  }

  for(B; B>0; B--) // blue transition down.
  {
    for(int pixel_number = 0; pixel_number < 7; pixel_number++)
    {
      pixels.setPixelColor(pixel_number, pixels.Color(R, G, B));
    }
    pixels.show();
    delay(DELAYTIME);
  }
pixels.clear();
pixels.show();
}

// plays the flashing epilepsy inducing celebrate LEDs !!!!
void CELEBRATE()
{
// pixels are days 0 to 6 (i.e. monday to friday)
  
  for(int repeat = 0; repeat < 5; repeat++)
  {
    for (int W = 0; W<7; W++)
    {
      pixels.setPixelColor(W, pixels.Color(255, 255, 255));
      pixels.show();
      delay(50);
      pixels.setPixelColor(W, pixels.Color(0, 0, 0));
      pixels.show();
    }

    for (int R = 0; R<7; R++)
    {
      pixels.setPixelColor(R, pixels.Color(255, 0, 0));
      pixels.show();
      delay(50);
      pixels.setPixelColor(R, pixels.Color(0, 0, 0));
      pixels.show();
    }

    for (int G = 0; G<7; G++)
    {
      pixels.setPixelColor(G, pixels.Color(0, 255, 0));
      pixels.show();
      delay(50);
      pixels.setPixelColor(G, pixels.Color(0, 0, 0));
      pixels.show();
    }

    for (int B = 0; B<7; B++)
    {
      pixels.setPixelColor(B, pixels.Color(0, 0, 255));
      pixels.show();
      delay(50);
      pixels.setPixelColor(B, pixels.Color(0, 0, 0));
      pixels.show();
    }
  }
  animate_led();
}
/*
============================================
ERASE EEPROM CALLBACK
use this to write zeros to eeproms
if they need to be reset
============================================
 */
void clear_eeproms()
{
  for(int address = 0; address < 27; address++)
  {
    EEPROM.write(address, 0);
  }
}
/*
============================================
SETUP SECTION
============================================
 */
void setup()
{
  // declare the following push buttons as inputs.
  pinMode(button_up_pin, INPUT);
  pinMode(button_down_pin, INPUT);
  pinMode(button_mon_pin, INPUT);
  pinMode(button_tue_pin, INPUT);
  pinMode(button_wed_pin, INPUT);
  pinMode(button_thu_pin, INPUT);
  pinMode(button_fri_pin, INPUT);
  pinMode(button_sat_pin, INPUT);
  pinMode(button_sun_pin, INPUT);

  // declare the following audio trigger pins as output.
  pinMode(mon_sound, OUTPUT);
  pinMode(tue_sound, OUTPUT);
  pinMode(wed_sound, OUTPUT);
  pinMode(thu_sound, OUTPUT);
  pinMode(fri_sound, OUTPUT);
  pinMode(sat_sound, OUTPUT);
  pinMode(sun_sound, OUTPUT);

  // also pull them high straight away (they are active LOW!)
  digitalWrite(mon_sound, HIGH);
  digitalWrite(tue_sound, HIGH);
  digitalWrite(wed_sound, HIGH);
  digitalWrite(thu_sound, HIGH);
  digitalWrite(fri_sound, HIGH);
  digitalWrite(sat_sound, HIGH);
  digitalWrite(sun_sound, HIGH);
  
  I2CMux.begin(Wire);
  I2CMux.closeAll();

  pixels.begin();
  pixels.show();
  pixels.setBrightness(255); // Set pixel LED BRIGHTNESS to FULL
 
  // for loop cycles through screens 0 to 6 (i.e. Monday to Sunday).
  // and clear them

  int screens = 0;
  for (screens; screens < 7; screens++)
  {
    I2CMux.openChannel(screens);
    display.begin(SSD1306_SWITCHCAPVCC, SCREEN_ADDRESS);
    display.setRotation(2); // I mounted the OLED displays in the enclosure upside down by accident!
    display.clearDisplay();
    display.invertDisplay(false);
    display.display();
    I2CMux.closeChannel(screens);
  }
}
/*
=================================================
MAIN LOOP SECTION
=================================================
*/
void loop()
{
// READ ALL THE BUTTON STATES FOR EACH DAY
    read_button_mon(); 
    read_button_tue();
    read_button_wed();
    read_button_thu();
    read_button_fri();
    read_button_sat();
    read_button_sun();
    read_button_up();
/*
=================================================
DISPLAY DAY OF THE WEEK UNTIL BUTTON IS PUSHED

If nothing is push the display displays the miles ran
fetched from the EEPROM. Also change LED to indicate
green or red depending on if the target has been met
=================================================
*/
    if (button_state_mon == false)
    {
      read_eeprom_mon_dist();  // Read the eeproms
      read_eeprom_mon_targ();

      I2CMux.openChannel(oled_mon);
      display.clearDisplay();
      display.setTextColor(SSD1306_WHITE);
      display.setTextSize(2);
      display.setCursor(0,10);
      //display.println("MONDAY");
      display.print(eeprom_calc_mon_dist);
      display.print(" miles");
      display.display();
      I2CMux.closeChannel(oled_mon);
      
      if(eeprom_calc_mon_dist <= eeprom_calc_mon_targ)
      {
        pixels.setPixelColor(mon_pixel, pixels.Color(255, 0, 0));
        pixels.show();
      }
      if(eeprom_calc_mon_dist > eeprom_calc_mon_targ)
      {
        pixels.setPixelColor(mon_pixel, pixels.Color(0, 255, 0));
        pixels.show();        
      }
    }

    if (button_state_tue == false)
    {
      read_eeprom_tue_dist();
      read_eeprom_tue_targ();

      I2CMux.openChannel(oled_tue);
      display.clearDisplay();
      display.setTextColor(SSD1306_WHITE);
      display.setTextSize(2);
      display.setCursor(0,10); // tuesday move 5 pixels left compared to Monday
      //display.println("TUESDAY");
      display.print(eeprom_calc_tue_dist);
      display.print(" miles");
      display.display();
      I2CMux.closeChannel(oled_tue);
      
      if(eeprom_calc_tue_dist <= eeprom_calc_tue_targ)
      {
        pixels.setPixelColor(tue_pixel, pixels.Color(255, 0, 0));
        pixels.show();
      }
      if(eeprom_calc_tue_dist > eeprom_calc_tue_targ)
      {
        pixels.setPixelColor(tue_pixel, pixels.Color(0, 255, 0));
        pixels.show();        
      }
    }

    if (button_state_wed == false)
    {
      read_eeprom_wed_dist();
      read_eeprom_wed_targ();

      I2CMux.openChannel(oled_wed);
      display.clearDisplay();
      display.setTextColor(SSD1306_WHITE);
      display.setTextSize(2);
      display.setCursor(0,10); // move pixels left compared to Monday
      //display.println("WEDNESDAY");
      display.print(eeprom_calc_wed_dist);
      display.print(" miles");
      display.display();
      I2CMux.closeChannel(oled_wed);
      
      if(eeprom_calc_wed_dist <= eeprom_calc_wed_targ)
      {
        pixels.setPixelColor(wed_pixel, pixels.Color(255, 0, 0));
        pixels.show();
      }
      if(eeprom_calc_wed_dist > eeprom_calc_wed_targ)
      {
        pixels.setPixelColor(wed_pixel, pixels.Color(0, 255, 0));
        pixels.show();        
      }
    }


  
    if (button_state_thu == false)
    {
      read_eeprom_thu_dist();
      read_eeprom_thu_targ();

      I2CMux.openChannel(oled_thu);
      display.clearDisplay();
      display.setTextColor(SSD1306_WHITE);
      display.setTextSize(2);
      display.setCursor(0,10); // move 10 pixels left compared to Monday
      //display.println("THURSDAY");
      display.print(eeprom_calc_thu_dist);
      display.print(" miles");
      display.display();
      I2CMux.closeChannel(oled_thu); 
      
      if(eeprom_calc_thu_dist <= eeprom_calc_thu_targ)
      {
        pixels.setPixelColor(thu_pixel, pixels.Color(255, 0, 0));
        pixels.show();
      }
      if(eeprom_calc_thu_dist > eeprom_calc_thu_targ)
      {
        pixels.setPixelColor(thu_pixel, pixels.Color(0, 255, 0));
        pixels.show();        
      }
    }


    
    if (button_state_fri == false)
    {
      read_eeprom_fri_dist();
      read_eeprom_fri_targ();

      I2CMux.openChannel(oled_fri);
      display.clearDisplay();
      display.setTextColor(SSD1306_WHITE);
      display.setTextSize(2);
      display.setCursor(0,10);
      //display.println("FRIDAY");
      display.print(eeprom_calc_fri_dist);
      display.print(" miles");
      display.display();
      I2CMux.closeChannel(oled_fri);
      
      if(eeprom_calc_fri_dist <= eeprom_calc_fri_targ)
      {
        pixels.setPixelColor(fri_pixel, pixels.Color(255, 0, 0));
        pixels.show();
      }
      if(eeprom_calc_fri_dist > eeprom_calc_fri_targ)
      {
        pixels.setPixelColor(fri_pixel, pixels.Color(0, 255, 0));
        pixels.show();        
      }
    }

    if (button_state_sat == false)
    {
      read_eeprom_sat_dist();
      read_eeprom_sat_targ();

      I2CMux.openChannel(oled_sat);
      display.clearDisplay();
      display.setTextColor(SSD1306_WHITE);
      display.setTextSize(2);
      display.setCursor(0,10); // move 10 pixels left compared to Monday
      //display.println("SATURDAY");
      display.print(eeprom_calc_sat_dist);
      display.print(" miles");
      display.display();
      I2CMux.closeChannel(oled_sat); 

      if(eeprom_calc_sat_dist <= eeprom_calc_sat_targ)
      {
        pixels.setPixelColor(sat_pixel, pixels.Color(255, 0, 0));
        pixels.show();
      }
      if(eeprom_calc_sat_dist > eeprom_calc_sat_targ)
      {
        pixels.setPixelColor(sat_pixel, pixels.Color(0, 255, 0));
        pixels.show();        
      }      
    }
 
    if (button_state_sun == false)
    {
      read_eeprom_sun_dist();
      read_eeprom_sun_targ();
  
      I2CMux.openChannel(oled_sun);
      display.clearDisplay();
      display.setTextColor(SSD1306_WHITE);
      display.setTextSize(2);
      display.setCursor(0,10);
      //display.println("SUNDAY");
      display.print(eeprom_calc_sun_dist);
      display.print(" miles");
      display.display();
      I2CMux.closeChannel(oled_sun);

      if(eeprom_calc_sun_dist <= eeprom_calc_sun_targ) //less than or equal to target...stay red
      {
        pixels.setPixelColor(sun_pixel, pixels.Color(255, 0, 0));
        pixels.show();
      }
      if(eeprom_calc_sun_dist > eeprom_calc_sun_targ)
      {
        pixels.setPixelColor(sun_pixel, pixels.Color(0, 255, 0));
        pixels.show();        
      }
    }
/*
===========================================================
BUTTON MONITORING
A section of logical tests using booleans to start updating
the distance/targets depending on if a short/long press is
detected (< 3 seconds).
===========================================================

===========================================================
UP/RESET - BUTTON MONITORING
===========================================================
*/
    if (button_state_up == true && button_state_up_long == true)
    {
      for(int pxl = 0; pxl < 7; pxl++)
      {
        pixels.setPixelColor(pxl, pixels.Color(255, 0, 0)); //set all pixels to red.
      }
      pixels.show();
    }
    
    while (button_state_up == true && button_state_up_long == true)
    {
      I2CMux.openChannel(oled_mon);
      display.clearDisplay();
      display.display();
      I2CMux.closeChannel(oled_mon);
      
      I2CMux.openChannel(oled_tue);
      display.clearDisplay();
      display.setTextColor(SSD1306_WHITE);
      display.setTextSize(2);
      display.setCursor(0,10);
      display.print("CLEAR");
      display.display();
      I2CMux.closeChannel(oled_tue);

      I2CMux.openChannel(oled_wed);
      display.clearDisplay();
      display.setTextColor(SSD1306_WHITE);
      display.setTextSize(2);
      display.setCursor(0,10);
      display.print("ALL");
      display.display();
      I2CMux.closeChannel(oled_wed);

      I2CMux.openChannel(oled_thu);
      display.clearDisplay();
      display.setTextColor(SSD1306_WHITE);
      display.setTextSize(2);
      display.setCursor(0,10);
      display.print("MEMORY?");
      display.display();
      I2CMux.closeChannel(oled_thu);

      I2CMux.openChannel(oled_fri);
      display.clearDisplay();
      display.setTextColor(SSD1306_WHITE);
      display.setTextSize(2);
      display.setCursor(0,10);
      display.print("UP = YES");
      display.display();
      I2CMux.closeChannel(oled_fri);

      I2CMux.openChannel(oled_sat);
      display.clearDisplay();
      display.setTextColor(SSD1306_WHITE);
      display.setTextSize(2);
      display.setCursor(0,10);
      display.print("DOWN = NO");
      display.display();
      I2CMux.closeChannel(oled_sat); 

      I2CMux.openChannel(oled_sun);
      display.clearDisplay();
      display.display();
      I2CMux.closeChannel(oled_sun); 
      
      if (digitalRead(button_up_pin) == HIGH)        
      {
        button_state_up = false;                     // if it was pressed again make the boolean false
        button_state_up_long = false;          // ... making it false will exit the loop.
        
        clear_eeproms();

        for(int disp = 0; disp <6; disp++)
        {
          I2CMux.openChannel(disp);
          display.clearDisplay();
          display.display();
          I2CMux.closeChannel(disp); 
        }

        I2CMux.openChannel(oled_wed);
        display.clearDisplay();
        display.setTextColor(SSD1306_WHITE);
        display.setTextSize(2);
        display.setCursor(0,10);
        display.print("ALL");
        display.display();
        I2CMux.closeChannel(oled_wed);
  
        I2CMux.openChannel(oled_thu);
        display.clearDisplay();
        display.setTextColor(SSD1306_WHITE);
        display.setTextSize(2);
        display.setCursor(0,10);
        display.print("MEMORY");
        display.display();
        I2CMux.closeChannel(oled_thu);
  
        I2CMux.openChannel(oled_fri);
        display.clearDisplay();
        display.setTextColor(SSD1306_WHITE);
        display.setTextSize(2);
        display.setCursor(0,10);
        display.print("CLEARED");
        display.display();
        I2CMux.closeChannel(oled_fri);
        
        pixels.clear();
        pixels.show();

        delay(2000);
      }
      if (digitalRead(button_down_pin) == HIGH)
      {
        button_state_up = false;                     // if it was pressed again make the boolean false
        button_state_up_long = false;          // ... making it false will exit the loop.

        animate_led();
        pixels.clear();
        pixels.show();

        delay(2000);
      }
    }
/*
===========================================================
MONDAY - BUTTON MONITORING
===========================================================
*/
    if(button_state_mon == true && button_state_mon_long == false)
    {
      pixels.setPixelColor(mon_pixel, pixels.Color(0, 128, 128));
      pixels.show();
      
      I2CMux.openChannel(oled_mon);          // open MUX channel MON
      display.clearDisplay();
      draw_distance();                       // this function draws the running man (distance)
      I2CMux.closeChannel(oled_mon);         // close MUX channel MON
    }

    if (button_state_mon == true && button_state_mon_long == true)
    {
      pixels.setPixelColor(mon_pixel, pixels.Color(0, 0, 255));
      pixels.show();
      
      I2CMux.openChannel(oled_mon);          // open MUX channel MON
      display.clearDisplay();
      draw_target();                         // this function draws the target (target)
      I2CMux.closeChannel(oled_mon);         // close MUX channel MON
    } 
/*
===========================================================
TUESDAY - BUTTON MONITORING
===========================================================
*/  
    if(button_state_tue == true && button_state_tue_long == false)
    {
      pixels.setPixelColor(tue_pixel, pixels.Color(0, 128, 128));
      pixels.show();
      
      I2CMux.openChannel(oled_tue);          // open MUX channel MON
      display.clearDisplay();
      draw_distance();                       // this function draws the running man (distance)
      I2CMux.closeChannel(oled_tue);         // close MUX channel MON
    }

    if (button_state_tue == true && button_state_tue_long == true)
    {
      pixels.setPixelColor(tue_pixel, pixels.Color(0, 0, 255));
      pixels.show();
      
      I2CMux.openChannel(oled_tue);          // open MUX channel MON
      display.clearDisplay();
      draw_target();                         // this function draws the target (target)
      I2CMux.closeChannel(oled_tue);         // close MUX channel MON
    }
/*
===========================================================
WEDNESDAY - BUTTON MONITORING
===========================================================
*/ 
    if(button_state_wed == true && button_state_wed_long == false)
    {
      pixels.setPixelColor(wed_pixel, pixels.Color(0, 128, 128));
      pixels.show();
      
      I2CMux.openChannel(oled_wed);          // open MUX channel MON
      display.clearDisplay();
      draw_distance();                       // this function draws the running man (distance)
      I2CMux.closeChannel(oled_wed);         // close MUX channel MON
    }

    if (button_state_wed == true && button_state_wed_long == true)
    {
      pixels.setPixelColor(wed_pixel, pixels.Color(0, 0, 255));
      pixels.show();
      
      I2CMux.openChannel(oled_wed);          // open MUX channel MON
      display.clearDisplay();
      draw_target();                         // this function draws the target (target)
      I2CMux.closeChannel(oled_wed);         // close MUX channel MON
    }
/*
===========================================================
THURSDAY - BUTTON MONITORING
===========================================================
*/ 
    if(button_state_thu == true && button_state_thu_long == false)
    {
      pixels.setPixelColor(thu_pixel, pixels.Color(0, 128, 128));
      pixels.show();
      
      I2CMux.openChannel(oled_thu);          // open MUX channel MON
      display.clearDisplay();
      draw_distance();                       // this function draws the running man (distance)
      I2CMux.closeChannel(oled_thu);         // close MUX channel MON
    }

    if (button_state_thu == true && button_state_thu_long == true)
    {
      pixels.setPixelColor(thu_pixel, pixels.Color(0, 0, 255));
      pixels.show();
      
      I2CMux.openChannel(oled_thu);          // open MUX channel MON
      display.clearDisplay();
      draw_target();                         // this function draws the target (target)
      I2CMux.closeChannel(oled_thu);         // close MUX channel MON
    }
/*
===========================================================
FRIDAY - BUTTON MONITORING
===========================================================
*/ 
    if(button_state_fri == true && button_state_fri_long == false)
    {
      pixels.setPixelColor(fri_pixel, pixels.Color(0, 128, 128));
      pixels.show();
      
      I2CMux.openChannel(oled_fri);          // open MUX channel MON
      display.clearDisplay();
      draw_distance();                       // this function draws the running man (distance)
      I2CMux.closeChannel(oled_fri);         // close MUX channel MON
    }

    if (button_state_fri == true && button_state_fri_long == true)
    {
      pixels.setPixelColor(fri_pixel, pixels.Color(0, 0, 255));
      pixels.show();
      
      I2CMux.openChannel(oled_fri);          // open MUX channel MON
      display.clearDisplay();
      draw_target();                         // this function draws the target (target)
      I2CMux.closeChannel(oled_fri);         // close MUX channel MON
    }
/*
===========================================================
SATURDAY - BUTTON MONITORING
===========================================================
*/ 
    if(button_state_sat == true && button_state_sat_long == false)
    {
      pixels.setPixelColor(sat_pixel, pixels.Color(0, 128, 128));
      pixels.show();
      
      I2CMux.openChannel(oled_sat);          // open MUX channel MON
      display.clearDisplay();
      draw_distance();                       // this function draws the running man (distance)
      I2CMux.closeChannel(oled_sat);         // close MUX channel MON
    }

    if (button_state_sat == true && button_state_sat_long == true)
    {
      pixels.setPixelColor(sat_pixel, pixels.Color(0, 0, 255));
      pixels.show();
      
      I2CMux.openChannel(oled_sat);          // open MUX channel MON
      display.clearDisplay();
      draw_target();                         // this function draws the target (target)
      I2CMux.closeChannel(oled_sat);         // close MUX channel MON
    }
/*
===========================================================
SUNDAY - BUTTON MONITORING
===========================================================
*/ 
    if(button_state_sun == true && button_state_sun_long == false)
    {
      pixels.setPixelColor(sun_pixel, pixels.Color(0, 128, 128));
      pixels.show();
      
      I2CMux.openChannel(oled_sun);          // open MUX channel MON
      display.clearDisplay();
      draw_distance();                       // this function draws the running man (distance)
      I2CMux.closeChannel(oled_sun);         // close MUX channel MON
    }

    if (button_state_sun == true && button_state_sun_long == true)
    {
      pixels.setPixelColor(sun_pixel, pixels.Color(0, 0, 255));
      pixels.show();
      
      I2CMux.openChannel(oled_sun);          // open MUX channel MON
      display.clearDisplay();
      draw_target();                         // this function draws the target (target)
      I2CMux.closeChannel(oled_sun);         // close MUX channel MON
    }
/*
===========================================================
SHORT PRESS ACTIONS - MONDAY
What to do if the push button was pressed for < 3 seconds
===========================================================
*/ 
    while (button_state_mon == true && button_state_mon_long == false)                  // if the above boolean is true do the following
    {
      if (digitalRead(button_up_pin) == HIGH)         // check to see if the UP button has been pressed
      {
        distance_mon = distance_mon + 0.01;           // increase the distance ran for MONDAY
    
        I2CMux.openChannel(oled_mon);                 // open the MUX channel for MONDAY
  
        // first blank the display
        display.setTextSize(2);                       // 2:1 pixel scale
        display.setTextColor(WHITE, BLACK);           // Draw white text
        display.setCursor(65,10);                     // Start at 61 pixels from left, and 5 from the top
        display.println("     ");                     // blank out the original text with spaces
        display.display();                            // display it.
  
        // update the display with the distance
        display.setTextColor(SSD1306_WHITE);
        display.setCursor(65,10);
        display.println(distance_mon, 2);
        display.display();
  
        I2CMux.closeChannel(oled_mon);                // close the MUX if you have finished updating displays
        
        delay(50);                                    // delay a bit so the increment does not go too fast.
      }
  
      if (digitalRead(button_down_pin) == HIGH)       // check to see if the UP button has been pressed
      {
        distance_mon = distance_mon - 0.01;           // increase the distance ran for MONDAY
    
        I2CMux.openChannel(oled_mon);                 // open the MUX channel for MONDAY
  
        // first blank the display
        display.setTextSize(2);                       // 2:1 pixel scale
        display.setTextColor(WHITE, BLACK);           // Draw white text
        display.setCursor(65,10);                     // Start at 61 pixels from left, and 5 from the top
        display.println("     ");                     // blank out the original text with spaces
        display.display();                            // display it.
  
        // update the display with the distance
        display.setTextColor(SSD1306_WHITE);
        display.setCursor(65,10);
        display.println(distance_mon, 2);
        display.display();
  
        I2CMux.closeChannel(oled_mon);                // close the MUX if you have finished updating displays
        
        delay(50);                                    // delay a bit so the increment does not go too fast.
      }
  
      if (distance_mon < 0)                           // error trapping for negative numbers.
      {
        distance_mon = 0.00;
      }
  
       // whilst still in the same loop, check to see if the MON button has been pressed again.
      if (digitalRead(button_mon_pin) == HIGH)        
      {
        save_eeprom_mon_distance();
        button_state_mon = false;                     // if it was pressed again make the boolean false
        button_state_mon_long = false;          // ... making it false will exit the loop.
        
        animate_led();
        pixels.clear();
        pixels.show();

        if(distance_mon > target_mon)
        {
          digitalWrite(mon_sound, LOW);
          CELEBRATE();
          digitalWrite(mon_sound, HIGH);
        }
        delay(500);
      }  
    }
/*
===========================================================
LONG PRESS ACTIONS - MONDAY
What to do if the push button was pressed for < 3 seconds
===========================================================
*/
    while (button_state_mon == true && button_state_mon_long == true)                  // if the above boolean is true do the following
    {
      if (digitalRead(button_up_pin) == HIGH)         // check to see if the UP button has been pressed
      {
        target_mon = target_mon + 0.01;           // increase the target for MONDAY
    
        I2CMux.openChannel(oled_mon);                 // open the MUX channel for MONDAY
  
        // first blank the display
        display.setTextSize(2);                       // 2:1 pixel scale
        display.setTextColor(WHITE, BLACK);           // Draw white text
        display.setCursor(65,10);                     // Start at 61 pixels from left, and 5 from the top
        display.println("     ");                     // blank out the original text with spaces
        display.display();                            // display it.
  
        // update the display with the distance
        display.setTextColor(SSD1306_WHITE);
        display.setCursor(65,10);
        display.println(target_mon, 2);
        display.display();
  
        I2CMux.closeChannel(oled_mon);                // close the MUX if you have finished updating displays
        
        delay(50);                                    // delay a bit so the increment does not go too fast.
      }
  
      if (digitalRead(button_down_pin) == HIGH)       // check to see if the UP button has been pressed
      {
        target_mon = target_mon - 0.01;           // increase the target ran for MONDAY
    
        I2CMux.openChannel(oled_mon);                 // open the MUX channel for MONDAY
  
        // first blank the display
        display.setTextSize(2);                       // 2:1 pixel scale
        display.setTextColor(WHITE, BLACK);           // Draw white text
        display.setCursor(65,10);                     // Start at 61 pixels from left, and 5 from the top
        display.println("     ");                     // blank out the original text with spaces
        display.display();                            // display it.
  
        // update the display with the target
        display.setTextColor(SSD1306_WHITE);
        display.setCursor(65,10);
        display.println(target_mon, 2);
        display.display();
  
        I2CMux.closeChannel(oled_mon);                // close the MUX if you have finished updating displays
        
        delay(50);                                    // delay a bit so the increment does not go too fast.
      }
  
      if (target_mon < 0)                           // error trapping for negative numbers.
      {
        target_mon = 0.00;
      }
  
       // whilst still in the same loop, check to see if the MON button has been pressed again.
      if (digitalRead(button_mon_pin) == HIGH)        
      {
        save_eeprom_mon_target();
        button_state_mon = false;                     // if it was pressed again make the boolean false
        button_state_mon_long = false;// ... making it false will exit the loop.

        animate_led();        
        pixels.clear();
        pixels.show();
                
        delay(500);
      }  
    }
/*
===========================================================
SHORT PRESS ACTIONS - TUESDAY
===========================================================
*/ 
    while (button_state_tue == true && button_state_tue_long == false)                  // if the above boolean is true do the following
    {
      if (digitalRead(button_up_pin) == HIGH)         // check to see if the UP button has been pressed
      {
        distance_tue = distance_tue + 0.01;           // increase the distance ran for MONDAY
    
        I2CMux.openChannel(oled_tue);                 // open the MUX channel for MONDAY
  
        // first blank the display
        display.setTextSize(2);                       // 2:1 pixel scale
        display.setTextColor(WHITE, BLACK);           // Draw white text
        display.setCursor(65,10);                     // Start at 61 pixels from left, and 5 from the top
        display.println("     ");                     // blank out the original text with spaces
        display.display();                            // display it.
  
        // update the display with the distance
        display.setTextColor(SSD1306_WHITE);
        display.setCursor(65,10);
        display.println(distance_tue, 2);
        display.display();
  
        I2CMux.closeChannel(oled_tue);                // close the MUX if you have finished updating displays
        
        delay(50);                                    // delay a bit so the increment does not go too fast.
      }
  
      if (digitalRead(button_down_pin) == HIGH)       // check to see if the UP button has been pressed
      {
        distance_tue = distance_tue - 0.01;           // increase the distance ran for MONDAY
    
        I2CMux.openChannel(oled_tue);                 // open the MUX channel for MONDAY
  
        // first blank the display
        display.setTextSize(2);                       // 2:1 pixel scale
        display.setTextColor(WHITE, BLACK);           // Draw white text
        display.setCursor(65,10);                     // Start at 61 pixels from left, and 5 from the top
        display.println("     ");                     // blank out the original text with spaces
        display.display();                            // display it.
  
        // update the display with the distance
        display.setTextColor(SSD1306_WHITE);
        display.setCursor(65,10);
        display.println(distance_tue, 2);
        display.display();
  
        I2CMux.closeChannel(oled_tue);                // close the MUX if you have finished updating displays
        
        delay(50);                                    // delay a bit so the increment does not go too fast.
      }
  
      if (distance_tue < 0)                           // error trapping for negative numbers.
      {
        distance_tue = 0.00;
      }
  
       // whilst still in the same loop, check to see if the MON button has been pressed again.
      if (digitalRead(button_tue_pin) == HIGH)        
      {
        save_eeprom_tue_distance();
        button_state_tue = false;
        button_state_tue_long = false;

        animate_led();
        pixels.clear();
        pixels.show();

        if(distance_tue > target_tue)
        {
          digitalWrite(tue_sound, LOW);
          CELEBRATE();
          digitalWrite(tue_sound, HIGH);
        }       
        
        delay(500);
      }  
    }
/*
===========================================================
LONG PRESS ACTIONS - TUESDAY
===========================================================
*/ 
    while (button_state_tue == true && button_state_tue_long == true)                  // if the above boolean is true do the following
    {
      if (digitalRead(button_up_pin) == HIGH)         // check to see if the UP button has been pressed
      {
        target_tue = target_tue + 0.01;           // increase the target for MONDAY
    
        I2CMux.openChannel(oled_tue);                 // open the MUX channel for MONDAY
  
        // first blank the display
        display.setTextSize(2);                       // 2:1 pixel scale
        display.setTextColor(WHITE, BLACK);           // Draw white text
        display.setCursor(65,10);                     // Start at 61 pixels from left, and 5 from the top
        display.println("     ");                     // blank out the original text with spaces
        display.display();                            // display it.
  
        // update the display with the distance
        display.setTextColor(SSD1306_WHITE);
        display.setCursor(65,10);
        display.println(target_tue, 2);
        display.display();
  
        I2CMux.closeChannel(oled_tue);                // close the MUX if you have finished updating displays
        
        delay(50);                                    // delay a bit so the increment does not go too fast.
      }
  
      if (digitalRead(button_down_pin) == HIGH)       // check to see if the UP button has been pressed
      {
        target_tue = target_tue - 0.01;           // increase the target ran for MONDAY
    
        I2CMux.openChannel(oled_tue);                 // open the MUX channel for MONDAY
  
        // first blank the display
        display.setTextSize(2);                       // 2:1 pixel scale
        display.setTextColor(WHITE, BLACK);           // Draw white text
        display.setCursor(65,10);                     // Start at 61 pixels from left, and 5 from the top
        display.println("     ");                     // blank out the original text with spaces
        display.display();                            // display it.
  
        // update the display with the target
        display.setTextColor(SSD1306_WHITE);
        display.setCursor(65,10);
        display.println(target_tue, 2);
        display.display();
  
        I2CMux.closeChannel(oled_tue);                // close the MUX if you have finished updating displays
        
        delay(50);                                    // delay a bit so the increment does not go too fast.
      }
  
      if (target_tue < 0)                           // error trapping for negative numbers.
      {
        target_tue = 0.00;
      }
  
       // whilst still in the same loop, check to see if the MON button has been pressed again.
      if (digitalRead(button_tue_pin) == HIGH)        
      {
        save_eeprom_tue_target();
        button_state_tue = false;                     // if it was pressed again make the boolean false
        button_state_tue_long = false;

        animate_led();
        pixels.clear();
        pixels.show();   
        
        delay(500);
      }  
    }
/*
===========================================================
SHORT PRESS ACTIONS - WEDNESDAY
===========================================================
*/ 
    while (button_state_wed == true && button_state_wed_long == false)                  // if the above boolean is true do the following
    {
      if (digitalRead(button_up_pin) == HIGH)         // check to see if the UP button has been pressed
      {
        distance_wed = distance_wed + 0.01;           // increase the distance ran for MONDAY
    
        I2CMux.openChannel(oled_wed);                 // open the MUX channel for MONDAY
  
        // first blank the display
        display.setTextSize(2);                       // 2:1 pixel scale
        display.setTextColor(WHITE, BLACK);           // Draw white text
        display.setCursor(65,10);                     // Start at 61 pixels from left, and 5 from the top
        display.println("     ");                     // blank out the original text with spaces
        display.display();                            // display it.
  
        // update the display with the distance
        display.setTextColor(SSD1306_WHITE);
        display.setCursor(65,10);
        display.println(distance_wed, 2);
        display.display();
  
        I2CMux.closeChannel(oled_wed);                // close the MUX if you have finished updating displays
        
        delay(50);                                    // delay a bit so the increment does not go too fast.
      }
  
      if (digitalRead(button_down_pin) == HIGH)       // check to see if the UP button has been pressed
      {
        distance_wed = distance_wed - 0.01;           // increase the distance ran for MONDAY
    
        I2CMux.openChannel(oled_wed);                 // open the MUX channel for MONDAY
  
        // first blank the display
        display.setTextSize(2);                       // 2:1 pixel scale
        display.setTextColor(WHITE, BLACK);           // Draw white text
        display.setCursor(65,10);                     // Start at 61 pixels from left, and 5 from the top
        display.println("     ");                     // blank out the original text with spaces
        display.display();                            // display it.
  
        // update the display with the distance
        display.setTextColor(SSD1306_WHITE);
        display.setCursor(65,10);
        display.println(distance_wed, 2);
        display.display();
  
        I2CMux.closeChannel(oled_wed);                // close the MUX if you have finished updating displays
        
        delay(50);                                    // delay a bit so the increment does not go too fast.
      }
  
      if (distance_wed < 0)                           // error trapping for negative numbers.
      {
        distance_wed = 0.00;
      }
  
       // whilst still in the same loop, check to see if the MON button has been pressed again.
      if (digitalRead(button_wed_pin) == HIGH)        
      {
        save_eeprom_wed_distance();
        button_state_wed = false;
        button_state_wed_long = false;

        animate_led();
        pixels.clear();
        pixels.show();

        if(distance_wed > target_wed)
        {
          digitalWrite(wed_sound, LOW);
          CELEBRATE();
          digitalWrite(wed_sound, HIGH);
        }
        
        delay(500);
      }  
    }
/*
===========================================================
LONG PRESS ACTIONS - WEDNESDAY
===========================================================
*/ 
    while (button_state_wed == true && button_state_wed_long == true)                  // if the above boolean is true do the following
    {
      if (digitalRead(button_up_pin) == HIGH)         // check to see if the UP button has been pressed
      {
        target_wed = target_wed + 0.01;           // increase the target for MONDAY
    
        I2CMux.openChannel(oled_wed);                 // open the MUX channel for MONDAY
  
        // first blank the display
        display.setTextSize(2);                       // 2:1 pixel scale
        display.setTextColor(WHITE, BLACK);           // Draw white text
        display.setCursor(65,10);                     // Start at 61 pixels from left, and 5 from the top
        display.println("     ");                     // blank out the original text with spaces
        display.display();                            // display it.
  
        // update the display with the distance
        display.setTextColor(SSD1306_WHITE);
        display.setCursor(65,10);
        display.println(target_wed, 2);
        display.display();
  
        I2CMux.closeChannel(oled_wed);                // close the MUX if you have finished updating displays
        
        delay(50);                                    // delay a bit so the increment does not go too fast.
      }
  
      if (digitalRead(button_down_pin) == HIGH)       // check to see if the UP button has been pressed
      {
        target_wed = target_wed - 0.01;           // increase the target ran for MONDAY
    
        I2CMux.openChannel(oled_wed);                 // open the MUX channel for MONDAY
  
        // first blank the display
        display.setTextSize(2);                       // 2:1 pixel scale
        display.setTextColor(WHITE, BLACK);           // Draw white text
        display.setCursor(65,10);                     // Start at 61 pixels from left, and 5 from the top
        display.println("     ");                     // blank out the original text with spaces
        display.display();                            // display it.
  
        // update the display with the target
        display.setTextColor(SSD1306_WHITE);
        display.setCursor(65,10);
        display.println(target_wed, 2);
        display.display();
  
        I2CMux.closeChannel(oled_wed);                // close the MUX if you have finished updating displays
        
        delay(50);                                    // delay a bit so the increment does not go too fast.
      }
  
      if (target_wed < 0)                           // error trapping for negative numbers.
      {
        target_wed = 0.00;
      }
  
       // whilst still in the same loop, check to see if the MON button has been pressed again.
      if (digitalRead(button_wed_pin) == HIGH)        
      {
        save_eeprom_wed_target();
        button_state_wed = false;                     // if it was pressed again make the boolean false
        button_state_wed_long = false;

        animate_led();
        pixels.clear();
        pixels.show();        
        
        delay(500);
      }  
    }
/*
===========================================================
SHORT PRESS ACTIONS - THURSDAY
===========================================================
*/ 
    while (button_state_thu == true && button_state_thu_long == false)                  // if the above boolean is true do the following
    {
      if (digitalRead(button_up_pin) == HIGH)         // check to see if the UP button has been pressed
      {
        distance_thu = distance_thu + 0.01;           // increase the distance ran for MONDAY
    
        I2CMux.openChannel(oled_thu);                 // open the MUX channel for MONDAY
  
        // first blank the display
        display.setTextSize(2);                       // 2:1 pixel scale
        display.setTextColor(WHITE, BLACK);           // Draw white text
        display.setCursor(65,10);                     // Start at 61 pixels from left, and 5 from the top
        display.println("     ");                     // blank out the original text with spaces
        display.display();                            // display it.
  
        // update the display with the distance
        display.setTextColor(SSD1306_WHITE);
        display.setCursor(65,10);
        display.println(distance_thu, 2);
        display.display();
  
        I2CMux.closeChannel(oled_thu);                // close the MUX if you have finished updating displays
        
        delay(50);                                    // delay a bit so the increment does not go too fast.
      }
  
      if (digitalRead(button_down_pin) == HIGH)       // check to see if the UP button has been pressed
      {
        distance_thu = distance_thu - 0.01;           // increase the distance ran for MONDAY
    
        I2CMux.openChannel(oled_thu);                 // open the MUX channel for MONDAY
  
        // first blank the display
        display.setTextSize(2);                       // 2:1 pixel scale
        display.setTextColor(WHITE, BLACK);           // Draw white text
        display.setCursor(65,10);                     // Start at 61 pixels from left, and 5 from the top
        display.println("     ");                     // blank out the original text with spaces
        display.display();                            // display it.
  
        // update the display with the distance
        display.setTextColor(SSD1306_WHITE);
        display.setCursor(65,10);
        display.println(distance_thu, 2);
        display.display();
  
        I2CMux.closeChannel(oled_thu);                // close the MUX if you have finished updating displays
        
        delay(50);                                    // delay a bit so the increment does not go too fast.
      }
  
      if (distance_thu < 0)                           // error trapping for negative numbers.
      {
        distance_thu = 0.00;
      }
  
       // whilst still in the same loop, check to see if the MON button has been pressed again.
      if (digitalRead(button_thu_pin) == HIGH)        
      {
        save_eeprom_thu_distance();
        button_state_thu = false;
        button_state_thu_long = false;

        animate_led();
        pixels.clear();
        pixels.show();

        if(distance_thu > target_thu)
        {
          digitalWrite(thu_sound, LOW);
          CELEBRATE();
          digitalWrite(thu_sound, HIGH);
        }

        delay(500);
      }  
    }
/*
===========================================================
LONG PRESS ACTIONS - THURSDAY
===========================================================
*/
    while (button_state_thu == true && button_state_thu_long == true)                  // if the above boolean is true do the following
    {
      if (digitalRead(button_up_pin) == HIGH)         // check to see if the UP button has been pressed
      {
        target_thu = target_thu + 0.01;           // increase the target for MONDAY
    
        I2CMux.openChannel(oled_thu);                 // open the MUX channel for MONDAY
  
        // first blank the display
        display.setTextSize(2);                       // 2:1 pixel scale
        display.setTextColor(WHITE, BLACK);           // Draw white text
        display.setCursor(65,10);                     // Start at 61 pixels from left, and 5 from the top
        display.println("     ");                     // blank out the original text with spaces
        display.display();                            // display it.
  
        // update the display with the distance
        display.setTextColor(SSD1306_WHITE);
        display.setCursor(65,10);
        display.println(target_thu, 2);
        display.display();
  
        I2CMux.closeChannel(oled_thu);                // close the MUX if you have finished updating displays
        
        delay(50);                                    // delay a bit so the increment does not go too fast.
      }
  
      if (digitalRead(button_down_pin) == HIGH)       // check to see if the UP button has been pressed
      {
        target_thu = target_thu - 0.01;           // increase the target ran for MONDAY
    
        I2CMux.openChannel(oled_thu);                 // open the MUX channel for MONDAY
  
        // first blank the display
        display.setTextSize(2);                       // 2:1 pixel scale
        display.setTextColor(WHITE, BLACK);           // Draw white text
        display.setCursor(65,10);                     // Start at 61 pixels from left, and 5 from the top
        display.println("     ");                     // blank out the original text with spaces
        display.display();                            // display it.
  
        // update the display with the target
        display.setTextColor(SSD1306_WHITE);
        display.setCursor(65,10);
        display.println(target_thu, 2);
        display.display();
  
        I2CMux.closeChannel(oled_thu);                // close the MUX if you have finished updating displays
        
        delay(50);                                    // delay a bit so the increment does not go too fast.
      }
  
      if (target_thu < 0)                           // error trapping for negative numbers.
      {
        target_thu = 0.00;
      }
  
       // whilst still in the same loop, check to see if the MON button has been pressed again.
      if (digitalRead(button_thu_pin) == HIGH)        
      {
        save_eeprom_thu_target();
        button_state_thu = false;                     // if it was pressed again make the boolean false
        button_state_thu_long = false;

        animate_led();
        pixels.clear();
        pixels.show();
        
        delay(500);
      }  
    }
/*
===========================================================
SHORT PRESS ACTIONS - FRIDAY
===========================================================
*/ 
    while (button_state_fri == true && button_state_fri_long == false)                  // if the above boolean is true do the following
    {
      if (digitalRead(button_up_pin) == HIGH)         // check to see if the UP button has been pressed
      {
        distance_fri = distance_fri + 0.01;           // increase the distance ran for MONDAY
    
        I2CMux.openChannel(oled_fri);                 // open the MUX channel for MONDAY
  
        // first blank the display
        display.setTextSize(2);                       // 2:1 pixel scale
        display.setTextColor(WHITE, BLACK);           // Draw white text
        display.setCursor(65,10);                     // Start at 61 pixels from left, and 5 from the top
        display.println("     ");                     // blank out the original text with spaces
        display.display();                            // display it.
  
        // update the display with the distance
        display.setTextColor(SSD1306_WHITE);
        display.setCursor(65,10);
        display.println(distance_fri, 2);
        display.display();
  
        I2CMux.closeChannel(oled_fri);                // close the MUX if you have finished updating displays
        
        delay(50);                                    // delay a bit so the increment does not go too fast.
      }
  
      if (digitalRead(button_down_pin) == HIGH)       // check to see if the UP button has been pressed
      {
        distance_fri = distance_fri - 0.01;           // increase the distance ran for MONDAY
    
        I2CMux.openChannel(oled_fri);                 // open the MUX channel for MONDAY
  
        // first blank the display
        display.setTextSize(2);                       // 2:1 pixel scale
        display.setTextColor(WHITE, BLACK);           // Draw white text
        display.setCursor(65,10);                     // Start at 61 pixels from left, and 5 from the top
        display.println("     ");                     // blank out the original text with spaces
        display.display();                            // display it.
  
        // update the display with the distance
        display.setTextColor(SSD1306_WHITE);
        display.setCursor(65,10);
        display.println(distance_fri, 2);
        display.display();
  
        I2CMux.closeChannel(oled_fri);                // close the MUX if you have finished updating displays
        
        delay(50);                                    // delay a bit so the increment does not go too fast.
      }
  
      if (distance_fri < 0)                           // error trapping for negative numbers.
      {
        distance_fri = 0.00;
      }
  
       // whilst still in the same loop, check to see if the MON button has been pressed again.
      if (digitalRead(button_fri_pin) == HIGH)        
      {
        save_eeprom_fri_distance();
        button_state_fri = false;
        button_state_fri_long = false;

        animate_led();
        pixels.clear();
        pixels.show();

        if(distance_fri > target_fri)
        {
          digitalWrite(fri_sound, LOW);
          CELEBRATE();
          digitalWrite(fri_sound, HIGH);
        }        
        
        delay(500);
      }  
    }
/*
===========================================================
LONG PRESS ACTIONS - FRIDAY
===========================================================
*/
    while (button_state_fri == true && button_state_fri_long == true)                  // if the above boolean is true do the following
    {
      if (digitalRead(button_up_pin) == HIGH)         // check to see if the UP button has been pressed
      {
        target_fri = target_fri + 0.01;           // increase the target for MONDAY
    
        I2CMux.openChannel(oled_fri);                 // open the MUX channel for MONDAY
  
        // first blank the display
        display.setTextSize(2);                       // 2:1 pixel scale
        display.setTextColor(WHITE, BLACK);           // Draw white text
        display.setCursor(65,10);                     // Start at 61 pixels from left, and 5 from the top
        display.println("     ");                     // blank out the original text with spaces
        display.display();                            // display it.
  
        // update the display with the distance
        display.setTextColor(SSD1306_WHITE);
        display.setCursor(65,10);
        display.println(target_fri, 2);
        display.display();
  
        I2CMux.closeChannel(oled_fri);                // close the MUX if you have finished updating displays
        
        delay(50);                                    // delay a bit so the increment does not go too fast.
      }
  
      if (digitalRead(button_down_pin) == HIGH)       // check to see if the UP button has been pressed
      {
        target_fri = target_fri - 0.01;           // increase the target ran for MONDAY
    
        I2CMux.openChannel(oled_fri);                 // open the MUX channel for MONDAY
  
        // first blank the display
        display.setTextSize(2);                       // 2:1 pixel scale
        display.setTextColor(WHITE, BLACK);           // Draw white text
        display.setCursor(65,10);                     // Start at 61 pixels from left, and 5 from the top
        display.println("     ");                     // blank out the original text with spaces
        display.display();                            // display it.
  
        // update the display with the target
        display.setTextColor(SSD1306_WHITE);
        display.setCursor(65,10);
        display.println(target_fri, 2);
        display.display();
  
        I2CMux.closeChannel(oled_fri);                // close the MUX if you have finished updating displays
        
        delay(50);                                    // delay a bit so the increment does not go too fast.
      }
  
      if (target_fri < 0)                           // error trapping for negative numbers.
      {
        target_fri = 0.00;
      }
  
       // whilst still in the same loop, check to see if the MON button has been pressed again.
      if (digitalRead(button_fri_pin) == HIGH)        
      {
        save_eeprom_fri_target();
        button_state_fri = false;                     // if it was pressed again make the boolean false
        button_state_fri_long = false;

        animate_led();
        pixels.clear();
        pixels.show();
        
        delay(500);
      }  
    }
/*
===========================================================
SHORT PRESS ACTIONS - SATURDAY
===========================================================
*/ 
    while (button_state_sat == true && button_state_sat_long == false)                  // if the above boolean is true do the following
    {
      if (digitalRead(button_up_pin) == HIGH)         // check to see if the UP button has been pressed
      {
        distance_sat = distance_sat + 0.01;           // increase the distance ran for MONDAY
    
        I2CMux.openChannel(oled_sat);                 // open the MUX channel for MONDAY
  
        // first blank the display
        display.setTextSize(2);                       // 2:1 pixel scale
        display.setTextColor(WHITE, BLACK);           // Draw white text
        display.setCursor(65,10);                     // Start at 61 pixels from left, and 5 from the top
        display.println("     ");                     // blank out the original text with spaces
        display.display();                            // display it.
  
        // update the display with the distance
        display.setTextColor(SSD1306_WHITE);
        display.setCursor(65,10);
        display.println(distance_sat, 2);
        display.display();
  
        I2CMux.closeChannel(oled_sat);                // close the MUX if you have finished updating displays
        
        delay(50);                                    // delay a bit so the increment does not go too fast.
      }
  
      if (digitalRead(button_down_pin) == HIGH)       // check to see if the UP button has been pressed
      {
        distance_sat = distance_sat - 0.01;           // increase the distance ran for MONDAY
    
        I2CMux.openChannel(oled_sat);                 // open the MUX channel for MONDAY
  
        // first blank the display
        display.setTextSize(2);                       // 2:1 pixel scale
        display.setTextColor(WHITE, BLACK);           // Draw white text
        display.setCursor(65,10);                     // Start at 61 pixels from left, and 5 from the top
        display.println("     ");                     // blank out the original text with spaces
        display.display();                            // display it.
  
        // update the display with the distance
        display.setTextColor(SSD1306_WHITE);
        display.setCursor(65,10);
        display.println(distance_sat, 2);
        display.display();
  
        I2CMux.closeChannel(oled_sat);                // close the MUX if you have finished updating displays
        
        delay(50);                                    // delay a bit so the increment does not go too fast.
      }
  
      if (distance_sat < 0)                           // error trapping for negative numbers.
      {
        distance_sat = 0.00;
      }
  
       // whilst still in the same loop, check to see if the MON button has been pressed again.
      if (digitalRead(button_sat_pin) == HIGH)        
      {
        save_eeprom_sat_distance();
        button_state_sat = false;
        button_state_sat_long = false;

        animate_led();
        pixels.clear();
        pixels.show();

        if(distance_sat > target_sat)
        {
          digitalWrite(sat_sound, LOW);
          CELEBRATE();
          digitalWrite(sat_sound, HIGH);
        }
        
        
        delay(500);
      }  
    }
/*
===========================================================
LONG PRESS ACTIONS - SATURDAY
===========================================================
*/ 
    while (button_state_sat == true && button_state_sat_long == true)                  // if the above boolean is true do the following
    {
      if (digitalRead(button_up_pin) == HIGH)         // check to see if the UP button has been pressed
      {
        target_sat = target_sat + 0.01;           // increase the target for MONDAY
    
        I2CMux.openChannel(oled_sat);                 // open the MUX channel for MONDAY
  
        // first blank the display
        display.setTextSize(2);                       // 2:1 pixel scale
        display.setTextColor(WHITE, BLACK);           // Draw white text
        display.setCursor(65,10);                     // Start at 61 pixels from left, and 5 from the top
        display.println("     ");                     // blank out the original text with spaces
        display.display();                            // display it.
  
        // update the display with the distance
        display.setTextColor(SSD1306_WHITE);
        display.setCursor(65,10);
        display.println(target_sat, 2);
        display.display();
  
        I2CMux.closeChannel(oled_sat);                // close the MUX if you have finished updating displays
        
        delay(50);                                    // delay a bit so the increment does not go too fast.
      }
  
      if (digitalRead(button_down_pin) == HIGH)       // check to see if the UP button has been pressed
      {
        target_sat = target_sat - 0.01;           // increase the target ran for MONDAY
    
        I2CMux.openChannel(oled_sat);                 // open the MUX channel for MONDAY
  
        // first blank the display
        display.setTextSize(2);                       // 2:1 pixel scale
        display.setTextColor(WHITE, BLACK);           // Draw white text
        display.setCursor(65,10);                     // Start at 61 pixels from left, and 5 from the top
        display.println("     ");                     // blank out the original text with spaces
        display.display();                            // display it.
  
        // update the display with the target
        display.setTextColor(SSD1306_WHITE);
        display.setCursor(65,10);
        display.println(target_sat, 2);
        display.display();
  
        I2CMux.closeChannel(oled_sat);                // close the MUX if you have finished updating displays
        
        delay(50);                                    // delay a bit so the increment does not go too fast.
      }
  
      if (target_sat < 0)                           // error trapping for negative numbers.
      {
        target_sat = 0.00;
      }
  
       // whilst still in the same loop, check to see if the MON button has been pressed again.
      if (digitalRead(button_sat_pin) == HIGH)        
      {
        save_eeprom_sat_target();
        button_state_sat = false;                     // if it was pressed again make the boolean false
        button_state_sat_long = false;

        animate_led();
        pixels.clear();
        pixels.show();
        
        delay(500);
      }  
    }
/*
===========================================================
SHORT PRESS ACTIONS - SUNDAY
===========================================================
*/ 
    while (button_state_sun == true && button_state_sun_long == false)                  // if the above boolean is true do the following
    {
      if (digitalRead(button_up_pin) == HIGH)         // check to see if the UP button has been pressed
      {
        distance_sun = distance_sun + 0.01;           // increase the distance ran for MONDAY
    
        I2CMux.openChannel(oled_sun);                 // open the MUX channel for MONDAY
  
        // first blank the display
        display.setTextSize(2);                       // 2:1 pixel scale
        display.setTextColor(WHITE, BLACK);           // Draw white text
        display.setCursor(65,10);                     // Start at 61 pixels from left, and 5 from the top
        display.println("     ");                     // blank out the original text with spaces
        display.display();                            // display it.
  
        // update the display with the distance
        display.setTextColor(SSD1306_WHITE);
        display.setCursor(65,10);
        display.println(distance_sun, 2);
        display.display();
  
        I2CMux.closeChannel(oled_sun);                // close the MUX if you have finished updating displays
        
        delay(50);                                    // delay a bit so the increment does not go too fast.
      }
  
      if (digitalRead(button_down_pin) == HIGH)       // check to see if the UP button has been pressed
      {
        distance_sun = distance_sun - 0.01;           // increase the distance ran for MONDAY
    
        I2CMux.openChannel(oled_sun);                 // open the MUX channel for MONDAY
  
        // first blank the display
        display.setTextSize(2);                       // 2:1 pixel scale
        display.setTextColor(WHITE, BLACK);           // Draw white text
        display.setCursor(65,10);                     // Start at 61 pixels from left, and 5 from the top
        display.println("     ");                     // blank out the original text with spaces
        display.display();                            // display it.
  
        // update the display with the distance
        display.setTextColor(SSD1306_WHITE);
        display.setCursor(65,10);
        display.println(distance_sun, 2);
        display.display();
  
        I2CMux.closeChannel(oled_sun);                // close the MUX if you have finished updating displays
        
        delay(50);                                    // delay a bit so the increment does not go too fast.
      }
  
      if (distance_sun < 0)                           // error trapping for negative numbers.
      {
        distance_sun = 0.00;
      }
  
       // whilst still in the same loop, check to see if the MON button has been pressed again.
      if (digitalRead(button_sun_pin) == HIGH)        
      {
        save_eeprom_sun_distance();
        button_state_sun = false;
        button_state_sun_long = false;

        animate_led();
        pixels.clear();
        pixels.show();

        if(distance_sun > target_sun)
        {
          digitalWrite(sun_sound, LOW);
          CELEBRATE();
          digitalWrite(sun_sound, HIGH);
        }
        delay(500);
      }  
    }
/*
===========================================================
LONG PRESS ACTIONS - SUNDAY
===========================================================
*/
    while (button_state_sun == true && button_state_sun_long == true)                  // if the above boolean is true do the following
    {
      if (digitalRead(button_up_pin) == HIGH)         // check to see if the UP button has been pressed
      {
        target_sun = target_sun + 0.01;           // increase the target for MONDAY
    
        I2CMux.openChannel(oled_sun);                 // open the MUX channel for MONDAY
  
        // first blank the display
        display.setTextSize(2);                       // 2:1 pixel scale
        display.setTextColor(WHITE, BLACK);           // Draw white text
        display.setCursor(65,10);                     // Start at 61 pixels from left, and 5 from the top
        display.println("     ");                     // blank out the original text with spaces
        display.display();                            // display it.
  
        // update the display with the distance
        display.setTextColor(SSD1306_WHITE);
        display.setCursor(65,10);
        display.println(target_sun, 2);
        display.display();
  
        I2CMux.closeChannel(oled_sun);                // close the MUX if you have finished updating displays
        
        delay(50);                                    // delay a bit so the increment does not go too fast.
      }
  
      if (digitalRead(button_down_pin) == HIGH)       // check to see if the UP button has been pressed
      {
        target_sun = target_sun - 0.01;           // increase the target ran for MONDAY
    
        I2CMux.openChannel(oled_sun);                 // open the MUX channel for MONDAY
  
        // first blank the display
        display.setTextSize(2);                       // 2:1 pixel scale
        display.setTextColor(WHITE, BLACK);           // Draw white text
        display.setCursor(65,10);                     // Start at 61 pixels from left, and 5 from the top
        display.println("     ");                     // blank out the original text with spaces
        display.display();                            // display it.
  
        // update the display with the target
        display.setTextColor(SSD1306_WHITE);
        display.setCursor(65,10);
        display.println(target_sun, 2);
        display.display();
  
        I2CMux.closeChannel(oled_sun);                // close the MUX if you have finished updating displays
        
        delay(50);                                    // delay a bit so the increment does not go too fast.
      }
  
      if (target_sun < 0)                           // error trapping for negative numbers.
      {
        target_sun = 0.00;
      }
  
       // whilst still in the same loop, check to see if the MON button has been pressed again.
      if (digitalRead(button_sun_pin) == HIGH)        
      {
        save_eeprom_sun_target();
        button_state_sun = false;                     // if it was pressed again make the boolean false
        button_state_sun_long = false;

        animate_led();
        pixels.clear();
        pixels.show();

        if(distance_sun > target_sun)
        {
          digitalWrite(sun_sound, LOW);
          CELEBRATE();
          digitalWrite(sun_sound, HIGH);
        }        
        delay(500);
      }  
    }
} // END OF VOID LOOP()
