On PC, you can just write test vectors like
int button_a[] = {0,0,0,0,0,0,0,0,0,0,1,1,1,1,0,1,0,1,0,0,0,0,0,0,0,0,0};
Then printf() the heck out of every if-else branch with all variables of interest, and see what happens.
Or you can single-step it in a debugger, no big difference.
Doing it sucks, but then you get the aha! moment and fix it.
Though, the ultimate target would be to learn to write more robust code, so that you actually understand what happens by just looking at that code. I rarely need to resort to tedious brute-force head-banging debug sessions of my program logic / algorithms anymore, although of course it sometimes happens.