Thanks again for the ideas guys. I tried HazardsMinds code, and it works well for the changing increments, but it changes based on holding the button, not based on what number the variable is. I used a similar approach to what Graynomad suggested, but using a large switch case to change the increment size. I tried to figure a way to rewrite the massive switch case as an array, but cannot figure out how to make that work. This is really messy and I'm certain there is a better way, but it works for now!
Is there an easy way to compare a single variable to all the variables in an array that would eliminate the switch case?
IE::
int ArrayTens[] = {10,20,30,40,50,60...etc};
if (ArrayTens[any stored value in entire array] == SetTime) {
SetTime += 10;
}
Here is the current version of the time change subroutine. It works very well, single button presses result in single digit increases, if you hold the button, it increases by 1's at an increasing delay rate, and when it reaches a multiple of ten it counts by 10's. Releasing the button resets the count increment to 1's.
// pins and associated varibles for pushbuttons:
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 MaxTime = 180; // Max Run Time for machine (seconds)
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
switch(SetTime){ // if SetTime is 10,20,30 etc, increment by tens
case 10:
SetTime += 10;
break;
case 20:
SetTime += 10;
break;
case 30:
SetTime += 10;
break;
case 40:
SetTime += 10;
break;
case 50:
SetTime += 10;
break;
case 60:
SetTime += 10;
break;
case 70:
SetTime += 10;
break;
case 80:
SetTime += 10;
break;
case 90:
SetTime += 10;
break;
case 100:
SetTime += 10;
break;
case 110:
SetTime += 10;
break;
case 120:
SetTime += 10;
break;
case 130:
SetTime += 10;
break;
case 140:
SetTime += 10;
break;
case 150:
SetTime += 10;
break;
case 160:
SetTime += 10;
break;
case 170:
SetTime += 10;
break;
case 180:
SetTime += 10;
break;
default: // if SetTime is not multiple of ten
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
switch(SetTime){ // if SetTime is 10,20,30 etc, increment by tens
case 10:
SetTime -= 10;
break;
case 20:
SetTime -= 10;
break;
case 30:
SetTime -= 10;
break;
case 40:
SetTime -= 10;
break;
case 50:
SetTime -= 10;
break;
case 60:
SetTime -= 10;
break;
case 70:
SetTime -= 10;
break;
case 80:
SetTime -= 10;
break;
case 90:
SetTime -= 10;
break;
case 100:
SetTime -= 10;
break;
case 110:
SetTime -= 10;
break;
case 120:
SetTime -= 10;
break;
case 130:
SetTime -= 10;
break;
case 140:
SetTime -= 10;
break;
case 150:
SetTime -= 10;
break;
case 160:
SetTime -= 10;
break;
case 170:
SetTime -= 10;
break;
case 180:
SetTime -= 10;
break;
default:
SetTime--;
}
}
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 % 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
}