default: { // MenuMode 0 is the default screen
if ((Button1State) == LOW) { // test for Button1 being pressed
DistanceMiles = 0; // if so, reset distance miles to zero
DistanceTenths = 0; // also, reset the tenths to zero
DistanceClicks = 0; // finally, reset the clicks to zero
printmileage(); // display the odometer
break;
}
if ((Button2State) == LOW) { // test for Button2 being pressed
MenuMode = 1; // Set MenuMode to 1
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
break;
}
}
}
}
ButtonPressedPrev = ButtonPressed; // store ButtonPressed in ButtonPressedPrev for test on next loop
}
void AddSensorCount() { // This is the subroutine that is called when interrupt 0 goes high
SensorCount++; // Increment SensorCount by 1
}
void EEPROMwrite() { // This is the subroutine that is called when interrupt 1 goes low
// store mileage variables in EEPROM
EEPROM.write(0, byte((DistanceMiles & 65280)/256));
EEPROM.write(1, byte((DistanceMiles & 255)));
EEPROM.write(2, byte(DistanceTenths));
EEPROM.write(3, byte((DistanceClicks) & 65280)/256);
EEPROM.write(4, byte((DistanceClicks) & 255));
EEPROM.write(5, byte((TotalMiles & 16711680)/65536));
EEPROM.write(6, byte((TotalMiles & 65280)/256));
EEPROM.write(7, byte((TotalMiles & 255)));
EEPROM.write(8, byte(TotalTenths));
EEPROM.write(9, byte((TotalClicks) & 65280)/256);
EEPROM.write(10, byte((TotalClicks) & 255));
}
void loadchars() { // This subroutine programs the custom character data into the LCD
lcd.command(64);
// Custom character 0
lcd.write(byte(B11111));
lcd.write(byte(B11111));
lcd.write(byte(B11111));
lcd.write(byte(B00000));
lcd.write(byte(B00000));
lcd.write(byte(B00000));
lcd.write(byte(B00000));
lcd.write(byte(B00000));
// Custom character 1
lcd.write(byte(B00000));
lcd.write(byte(B00000));
lcd.write(byte(B00000));
lcd.write(byte(B00000));
lcd.write(byte(B00000));
lcd.write(byte(B11111));
lcd.write(byte(B11111));
lcd.write(byte(B11111));
// Custom character 2
lcd.write(byte(B11111));
lcd.write(byte(B11111));
lcd.write(byte(B11111));
lcd.write(byte(B00000));
lcd.write(byte(B00000));
lcd.write(byte(B11111));
lcd.write(byte(B11111));
lcd.write(byte(B11111));
// Custom character 3
lcd.write(byte(B00000));
lcd.write(byte(B00000));
lcd.write(byte(B00000));
lcd.write(byte(B00000));
lcd.write(byte(B00000));
lcd.write(byte(B01110));
lcd.write(byte(B01110));
lcd.write(byte(B01110));
// Custom character 4
lcd.write(byte(B00000));
lcd.write(byte(B00000));
lcd.write(byte(B00000));
lcd.write(byte(B01110));
lcd.write(byte(B01110));
lcd.write(byte(B01110));
lcd.write(byte(B00000));
lcd.write(byte(B00000));
// Custom character 5
lcd.write(byte(B00000));
lcd.write(byte(B00000));
lcd.write(byte(B00000));
lcd.write(byte(B00000));
lcd.write(byte(B00000));
lcd.write(byte(B00000));
lcd.write(byte(B00000));
lcd.write(byte(B00000));
// Custom character 6
lcd.write(byte(B00000));
lcd.write(byte(B00000));
lcd.write(byte(B00000));
lcd.write(byte(B00000));
lcd.write(byte(B00000));
lcd.write(byte(B00000));
lcd.write(byte(B00000));
lcd.write(byte(B00000));
// Custom character 7
lcd.write(byte(B00000));
lcd.write(byte(B00000));
lcd.write(byte(B00000));
lcd.write(byte(B00000));
lcd.write(byte(B00000));
lcd.write(byte(B00000));
lcd.write(byte(B00000));
lcd.write(byte(B00000));
lcd.home();
}
void printmileage() {
lcd.setCursor(13, 0); // set the cursor to (13,0)
lcd.print(int((TotalMiles % 100000) / 10000)); // print the total miles ten-thousands digit
lcd.print(int((TotalMiles % 10000) / 1000)); // print the total miles thousands digit
lcd.print(int((TotalMiles % 1000) / 100)); // print the total miles hundreds digit
lcd.print(int((TotalMiles % 100) / 10)); // print the total miles tens digit
lcd.print(TotalMiles % 10); // print the total miles ones digit
lcd.print("."); // print the decimal point
lcd.print(TotalTenths); // print the total miles tenths digit
lcd.setCursor(14, 1); // set the cursor to (15,0)
lcd.print(int((DistanceMiles % 1000) / 100)); // print the distance miles hundreds digit
lcd.print(int((DistanceMiles % 100) / 10)); // print the distance miles hundreds digit
lcd.print(DistanceMiles % 10); // print the distance miles hundreds digit
lcd.print("."); // print the decimal point
lcd.print(DistanceTenths); // print the distance miles tenths digit
}
void printfeet() {
lcd.setCursor(13, 0); // set the cursor to (13,0)
lcd.print(" FEET: "); // print the FEET units
lcd.setCursor(13, 1); // set the cursor to (13,0)
lcd.print(int((DistanceFeet % 100000) / 10000)); // print the distance feet ten thousands digit
lcd.print(int((DistanceFeet % 10000) / 1000)); // print the distance feet thousands digit
lcd.print(int((DistanceFeet % 1000) / 100)); // print the distance feet hundreds digit
lcd.print(int((DistanceFeet % 100) / 10)); // print the distance feet tens digit
lcd.print(DistanceFeet % 10); // print the distance feet ones digit
lcd.print("."); // print the decimal point
lcd.print(DistanceFeetTenths); // print the distance feet tenths digit
}
void printbigchar(byte digit, byte col) { // This subroutine prints the big font characters on the LCD screen
if (digit > 9) return; // anything above 9 gets rejected
for (int i = 0; i < 2; i++) { // count i from 0 to 1
lcd.setCursor(col*4 , i); // set LCD cursor at correct point
for (int j = 0; j < 3; j++) { // count j from 0 to 2
lcd.write(bignums[digit][i][j]); // write proper block to LCD from array
}
lcd.write(254); // write an empty space
}
lcd.setCursor(col + 4, 0); // move the cursor to the top line, col + 4
}