// test to see if it's been at over 50 mS since last button was released
// and that a button is being pressed for the first time around
if (((millis() - ButtonsOffTime) > 50) && (ButtonPressed == true) && (ButtonPressedPrev == false)) {
switch (MenuMode) { // which menu is currently active?
case 1: { // MenuMode 1 is the Calibration screen
if (Button1State == LOW) { // test for Button1 being pressed
if (MenuModeActive) { // test to see if a menu mode has been selected
MenuModeActive = false; // Set MenuModeActive to false
lcd.setCursor(13, 0); // set the cursor to (13,0)
lcd.print(" CAL "); // overwrite total mileage with "CAL" & spaces
lcd.setCursor(13, 1); // set the cursor to (13,1)
lcd.print(" "); // overwrite CalDist with spaces
//write CalDist to EEPROM:
EEPROM.write(101, byte((CalDist & 65280)/256));
EEPROM.write(102, byte((CalDist & 255)));
}
else {
MenuModeActive = true; // Set MenuModeActive to true
CalDistPrev = CalDist; // copy CalDist to CalDistPrev
lcd.setCursor(13, 0); // set the cursor to (13,0)
lcd.print(" CAL: "); // overwrite total mileage with "CAL:" & spaces
lcd.setCursor(13, 1); // set the cursor to (13,1)
lcd.print(" "); // overwrite trip mileage with spaces
lcd.setCursor(15, 1); // set the cursor to (13,1)
lcd.print(CalDist); // print CalDist
}
}
if (Button2State == LOW) { // test for Button2 being pressed
if (MenuModeActive) { // test to see if a menu mode has been selected
MenuModeActive = false; // Set MenuModeActive to false
lcd.setCursor(13, 0); // set the cursor to (13,0)
lcd.print(" CAL "); // overwrite total mileage with "CAL" & spaces
lcd.setCursor(13, 1); // set the cursor to (13,1)
lcd.print(" "); // overwrite CalDist with spaces
CalDist = CalDistPrev; // set CalDist back to CalDistPrev (toss changes)
CalValue = int((2812500.0 / CalDist) + .5); // recalculate CalValue from CalDist
}
else {
MenuMode = 0; // Set MenuMode to 0
lcd.setCursor(13, 0); // set the cursor to (13,0)
lcd.print(" "); // overwrite "CAL" with spaces
lcd.setCursor(13, 1); // set the cursor to (13,1)
lcd.print(" "); // overwrite CalDist with spaces
printmileage(); // display the odometer
}
}
if (Button3State == LOW) { // test for Button3 being pressed
if (MenuModeActive) { // test to see if a menu mode has been selected
CalDist ++; // Increment CalDist
CalValue = int((2812500.0 / CalDist) + .5); // recalculate CalValue from CalDist
lcd.setCursor(15, 1); // set the cursor to (13,0)
lcd.print(CalDist); // print CalDist
}
else {
MenuMode = 2; // Go to the previous menu
lcd.setCursor(13, 0); // set the cursor to (13,0)
lcd.print(" FEET "); // overwrite menu item with "FEET:" & spaces
lcd.setCursor(13, 1); // set the cursor to (13,1)
lcd.print(" "); // overwrite lower menu area with spaces
}
}
if (Button4State == LOW) { // test for Button4 being pressed
if (MenuModeActive) { // test to see if a menu mode has been selected
CalDist --; // decrement CalDist
CalValue = int((2812500.0 / CalDist) + .5); // recalculate CalValue from CalDist
lcd.setCursor(15, 1); // set the cursor to (13,0)
lcd.print(CalDist); // print CalDist
}
else {
MenuMode = 2; // Go to the previous menu
lcd.setCursor(13, 0); // set the cursor to (13,0)
lcd.print(" FEET "); // overwrite menu item with "FEET:" & spaces
lcd.setCursor(13, 1); // set the cursor to (13,1)
lcd.print(" "); // overwrite lower menu area with spaces
}
}
break;
}
case 2: { // MenuMode 2 is the Foot distance meter
if (Button1State == LOW) { // test for Button1 being pressed
if (MenuModeActive) { // test to see if a menu mode has been selected
DistanceFeet = 0; // Reset DistanceFeet to 0
DistanceFeetTenths = 0; // Reset DistanceFeetTenths to 0
printfeet(); // Print the distance in feet
}
else {
MenuModeActive = true; // Set MenuModeActive to true (enter this mode)
lcd.setCursor(13, 0); // set the cursor to (13,0)
lcd.print(" FEET: "); // overwrite total mileage with "FEET:" & spaces
DistanceFeet = 0; // Reset DistanceFeet to 0
DistanceFeetTenths = 0; // Reset DistanceFeetTenths to 0
FeetScaleFactor = 528000 / CalDist; // Calculate FeetScaleFactor from CalValue
printfeet(); // Print the distance in feet
}
}
if (Button2State == LOW) { // test for Button2 being pressed
if (MenuModeActive) { // test to see if a menu mode has been selected
MenuModeActive = false; // Set MenuModeActive to true (exit this mode)
lcd.setCursor(13, 0); // set the cursor to (13,0)
lcd.print(" FEET "); // overwrite total mileage with "FEET:" & spaces
lcd.setCursor(13, 1); // set the cursor to (13,1)
lcd.print(" "); // overwrite feet distance with spaces
}
else {
MenuMode = 0; // Set MenuMode to 0
lcd.setCursor(13, 0); // set the cursor to (13,0)
lcd.print(" "); // overwrite "CAL" with spaces
lcd.setCursor(13, 1); // set the cursor to (13,1)
lcd.print(" "); // overwrite CalDist with spaces
printmileage(); // display the odometer
}
}
if (Button3State == LOW) { // test for Button3 being pressed
if (MenuModeActive) { // test to see if a menu mode has been selected
// do nothing
}
else {
MenuMode = 1; // Go to the previous menu
lcd.setCursor(13, 0); // set the cursor to (13,0)
lcd.print(" CAL "); // overwrite menu item with "CAL" & spaces
lcd.setCursor(13, 1); // set the cursor to (13,1)
lcd.print(" "); // overwrite lower menu area with spaces
}
}
if (Button4State == LOW) { // test for Button4 being pressed
if (MenuModeActive) { // test to see if a menu mode has been selected
// do nothing
}
else {
MenuMode = 1; // Go to the previous menu
lcd.setCursor(13, 0); // set the cursor to (13,0)
lcd.print(" CAL "); // overwrite menu item with "CAL" & spaces
lcd.setCursor(13, 1); // set the cursor to (13,1)
lcd.print(" "); // overwrite lower menu area with spaces
}
}
break;
}