ok im using 2 buttons to change 33 global points
the switch im using in buttons is getting long at this point so im trying to decide if there's a better way.
ive cut this section to give you a idea of what im talking about
one of my concern is the use of floats, ints and bytes which is why the switch works well but its getting rather long and I hate having to search for the correct number to use
//example of using a switch
case 14:
//set humidity here
while (escape == 0) {
checkeditbutton();
buttons(11);
lcd.setCursor(0, 0);
lcd.print (F("change humidity"));
lcd.setCursor(0, 1);
lcd.print(standardText[2]);
lcd.print (humidity_setpoint, 0);
lcd.setCursor(0, 3);
lcd.print(standardText[1]);
memory_update = 1;
}
editMode = editMode - 1;
break;
void buttons(byte type) {
plusButton = digitalRead(buttonPlus);
minusButton = digitalRead(buttonMinus);
if ((plusButton == 0) && (prevplusButton == 1)) {
lcd.clear();
switch (type) {
case 11:
humidity_setpoint++; //float adding 1
break;
case 12:
cal_temp = cal_temp + 0.1;//float adding 0.1
break;
case 20:
turnerAlarm = !turnerAlarm;//byte flipflop
break;
}
prevplusButton = 0;
}
if (plusButton == 1) {
prevplusButton = 1; //debounce
}
if ((minusButton == 0) && (prevMinusButton == 1)) {
lcd.clear();
switch (type) {
case 11:
humidity_setpoint--;
break;
case 12:
cal_temp = cal_temp - 0.1;
break;
case 20:
turnerAlarm = !turnerAlarm;
break;
}
prevMinusButton = 0;
}
if (minusButton == 1) {
prevMinusButton = 1; //debounce
}
}
so im trying this but it means moving byte, int into float positions then converting back later
//example of using a crude return
//example 1
buttons2(temp_setpoint, 0.1, 0);//float +/- 0.1 not a flip flop
temp_setpoint = result;
//example 2
buttons2(set_hour, 1, 0);//byte +/- 1 not a flip flop
set_hour = result;
//example 3
buttons2(hatchAlarm, 1, 1);//byte, ????? no scale, flip flop
hatchAlarm = result;
void buttons2(float viarable, float scale, byte flipflop) {
plusButton = digitalRead(buttonPlus);
minusButton = digitalRead(buttonMinus);
if ((plusButton == 0) && (prevplusButton == 1)) {
lcd.clear();
if (flipflop == 1) {
viarable = ! viarable;
} else {
viarable = viarable + scale;
}
prevplusButton = 0;
}
if (plusButton == 1) {
prevplusButton = 1; //debounce
}
if ((minusButton == 0) && (prevMinusButton == 1)) {
lcd.clear();
if (flipflop == 1) {
viarable = ! viarable;
} else {
viarable = viarable - scale;
}
prevMinusButton = 0;
}
if (minusButton == 1) {
prevMinusButton = 1; //debounce
}
result = viarable;//result is global
}
both ways seem to work and I haven't found a problem yet
I like the second way but im not sure if im asking for trouble (buttons are locked into a while loop so they shouldn't play with each other)
any suggestions?