Well I finally figured out the easy way to do this function. I had never heard the word "modulo" used for a mathematical method of finding the remainder of two numbers divided by each other. In C++ and Arduino it is the operator "%". By dividing the SetTime variable by a divisor (10 in this case) using the % operator, the remainder is returned into the Remainder variable. When Remainder = 0, you know that you are at an even multiple of the divisor, and you can count up by adding the divisor instead of 1.
This would also work to count by any other number by changing the value of the divisor. This simple math function that I didn't know existed cut out over 200 lines of code from my program.
int TimeUp = A5; // Time(+) Button Pin Location
int TUp = 0; // varible for Time(+) pin status
int TimeDown = A2; // Time(-) Button Pin Location
int TDown = 0; // varible for Time(-) pin status
unsigned long CT = 0; // Current Time (millisecs) - Current Clock Time, continuous running
unsigned long ST = 0; // Saved Time (millisecs) - clock time saved for next increment (Time buttons)
unsigned long PT = 0; // Pulse Time Varible (millisecs) - time between increments on button hold (Time buttons)
unsigned long ST2 = 0; // Saved Time (millisecs) - clock time saved for next increment (Speed buttons)
unsigned long PT2 = 0; // Pulse Time Varible (millisecs) - time between increments on button hold (Speed buttons)
int MinP = 180; // Minimum Pulse Time (millisecs) - minimum time between increments on button hold
int MaxP = 300; // Maximum Pulse Time (millisecs) - maximum time between increments on button hold
int Jump = 200; // pulse time to jump by 10s
const float Ramp = .9; // Pulse Time Accel %
int Divisor = 10; // Varible for size of time jump other than 1 second
int Remainder = 0; // Varible for determining if SetTime is divisible by divisor
int MaxTime = 300; // Max Run Time for machine (seconds)
//EEprom memory usage
int SetTime = EEPROM.read(10); // read SetTime stored in memory from before reset - SetTime is time set via Time+ and Time- buttons
int DispTime = 0; // Time that is actually displayed on LCD - initial time set via SetTime varible
void setup()
{
pinMode(TimeUp, INPUT); // set pin to input
pinMode(TimeDown, INPUT); // set pin to input
}
void TimeChange()
{
TUp = digitalRead(TimeUp); // read input value
TDown = digitalRead(TimeDown); // read input value
if (TUp == HIGH || TDown == HIGH) { // check if either input is HIGH (either button is pressed)
if (TUp == HIGH && SetTime < MaxTime) { // check if input is HIGH (button is pressed)
if (CT > ST){ // check if current time is higher than the time for next increment
if (PT <= Jump){ // check if pulse time is smaller than designated jump by tens time
Remainder = SetTime % Divisor; // Determine the remainder of SetTime divided by the Divisor
if (Remainder == 0){ // if the remainder is zero, you are at a multiple of the divisor
SetTime += Divisor; // add the Divisor to SetTime
}
else{
SetTime++; // increment one
}
}
else{
SetTime++; // increment one
}
tone(Spkr,Freq1,ShortBeep); // Play short button press tone
ST = CT + PT; // set time for next increment to current time plus pulse time
if (PT > MinP){ // check that pulse time is above minium pulse time
PT = PT * Ramp; // decrease pulse time by Ramp% to decrease pulse time
}
}
}
if (TDown == HIGH && SetTime > 1) { // check if input is HIGH (button is pressed)
if (CT > ST){ // check if current time is higher than the time for next increment
if (PT <= Jump){ // check if pulse time is smaller than designated jump by tens time
Remainder = SetTime % Divisor; // Determine the remainder of SetTime divided by the Divisor
if (Remainder == 0){ // if the remainder is zero, you are at a multiple of the divisor
SetTime -= Divisor; // subtract the Divisor from SetTime
}
else{
SetTime--; // decrement one
}
}
else{
SetTime--; // decrement one
}
tone(Spkr,Freq1,ShortBeep); // Play short button press tone
ST = CT + PT; // set time for next increment to current time plus pulse time
if (PT > MinP){ // check that pulse time is above minium pulse time
PT = PT * Ramp; // decrease pulse time by % to decrease pulse time
}
}
}
}
else {
ST = CT; // set time to next increment equal to current time
PT = MaxP; // reset pulse time to max pulse time
}
if (SetTime >= MaxTime){ // do not count higher than max run time
SetTime = MaxTime;
}
if (SetTime <= 1){ // set time cannot be less than 0
SetTime = 1;
}
if (SetTime != EEPROM.read(10)){ // if SetTime is different that stored value of SetTime
EEPROM.write(10, SetTime); // then write current SetTime to EEPROM
}
DispTime = SetTime; // time for display = to the set time
}