Sorry I should of said "complex". I need to see something that constantly monitors a series of failsafe's i.e emergency stop switches while controlling the speed or torque of a DC motor through a varied PWM voltage or current.
I was thinking if this just used a load of if statements that just constantly scanned the inputs to the failsafe switches and the control in an infinite while loop.
If you have multiple safety switches, connect them to the same 8bit port. So all port pins are 1 when safe, but any switch activated will make that pin a 0.
Then check the port in one operation;
if(PORTB != 0xFF) // if a switch is tripped!
which is very simple and quick. Obviously if a switch is tripped, you can then do some tests and see which one it was. But the main code only needs that one line to check all switches are safe.