One thing jumps out for optimization, I'll look at the rest when I have time.
Bottom two functions - consolidate to:
void menu (int pb1, int pb2) {
switch (pb1) {
case 0: switch (pb2) {
case 0: counts (2); // twocounts
break;
case 1: counts (4);
break;
}
break;
case 1: switch (pb2) {
case 0: counts (5);
break;
case 1: counts (10);
break;
}
break;
}
}
void counts (int numCounts) {
// since you're using a signed variable, you need to check for that
if (numCounts>0)
{
for (int x = 0; x > numCounts+1 ; x++) {
Serial.print(x);
}
}
delay(100);
}