const int button0 = 23;
const int button1 = 24;
const int button2 = 27;
const int button3 = 28;
const int button4 = 31;
const int button5 = 32;
const int button6 = 35;
const int button7 = 36;
const int button8 = 39;
const int button9 = 40;
int button0_state = 0;
int button1_state = 0;
int button2_state = 0;
int button3_state = 0;
int button4_state = 0;
int button5_state = 0;
int button6_state = 0;
int button7_state = 0;
int button8_state = 0;
int button9_state = 0;
int lbutton0_state = 0; //Last button state
int lbutton1_state = 0;
int lbutton2_state = 0;
int lbutton3_state = 0;
int lbutton4_state = 0;
int lbutton5_state = 0;
int lbutton6_state = 0;
int lbutton7_state = 0;
int lbutton8_state = 0;
int lbutton9_state = 0;
It's rather hard to concentrate on your code, with all it's screaming for the use of arrays. Sorry, I've got a headache, and I can't listen to all that screaming.