// see if we're supposed to be in trim mode or card format mode or HC05 pad mode
int mat = scanmatrix();
if (mat == WALK_1) {
Serial.println("#trim");
TrimMode = 1;
} else if (mat == REC_ERASE) {
// Format the SD card
Serial.println("#sdfmt");
SDCardFormat();
Serial.println("#sdfmt done");
} else if (mat == DANCE_1) { // no padding of BT packets
HC05_pad = 0;
EEPROM.update(1, HC05_pad); // save for future boots
} else if (mat == DANCE_2) { // pad BT packets
HC05_pad = 1;
EEPROM.update(1, HC05_pad); // save for future boots
}
So we can see here that holding down W1 during gamepad boot puts us in trim mode, holding R4 while booting
formats the SD card, D1 and D2 were used to work around an issue with certain bluetooth modules (which no longer
happens, it was just one manufacturer for a few months who had this weird bluetooth issue that required packets
be padded out to 256 bytes.)
You could pick any button other than those, for example maybe W4, and if you boot the gamepad when W4 is held that
would mean to reverse the direction of "forward". The code would be something like this:
// see if we're supposed to be in trim mode or card format mode or HC05 pad mode
int mat = scanmatrix();
if (mat == WALK_1) {
Serial.println("#trim");
TrimMode = 1;
} else if (mat == REC_ERASE) {
// Format the SD card
Serial.println("#sdfmt");
SDCardFormat();
Serial.println("#sdfmt done");
} else if (mat == DANCE_1) { // no padding of BT packets
HC05_pad = 0;
EEPROM.update(1, HC05_pad); // save for future boots
} else if (mat == DANCE_2) { // pad BT packets
HC05_pad = 1;
EEPROM.update(1, HC05_pad); // save for future boots
} else if (mat == WALK_4) { // reverse the robot's sense of "forward" direction
ReverseRobot = 1;
}
You would then declare near the top of the program a global like: byte ReverseRobot = 0; and you would change
the prior code by removing the #define REVERSEROBOT and instead just reference the variable ReverseRobot.
Again, I have not tested any of the above, so debugging may be necessary!
On a side note, the mode W4W4 (double tap on W4) actually "turns" by simply redefining what the front of the robot is.
Try it out! (A lot of people are unaware of the double-tap modes but there are some fun ones there.) It's not useful for
what you're trying to do, but the robot side of the code already has a mechanism to redefine the front of the robot
to be between any of the six hip servos. For your purposes, just redefining the buttons in the gamepad is a
cleaner and simpler solution.
Hope this helps,
-Steve P.