// near start of the loop:
switch_pressed = switch_input_bit;
// or !switch_input_bit for an active low input
// That guarantees that an change to the input state is only registered
// at the start of the loop, and nothing can change during the loop body.
//The input state test
if(switch_pressed == true && switch_image == false) {
// New switch press, take appropriate action
....
}
else {
// switch not pressed, or already seen.
}
// Rest of code
// and just before the end of the main loop
switch_image = switch_pressed;