+
+ error_state = ~(PINB & 0x03);
+
+ if (motor1_mode == MOTOR_PID && bit_is_set(error_state, 0)) {
+ // if error and running: stop
+ if (m1_old != 0) motor1 = 0;
+ // if we start motor in error state: start with full power
+ else if (motor1 > 0) motor1 = 255;
+ else if (motor1 < 0) motor1 = -255;
+ }
+ if (motor2_mode == MOTOR_PID && bit_is_set(error_state, 1)) {
+ // if error and running: stop
+ if (m2_old != 0) motor2 = 0;
+ // if we start motor in error state: start with full power
+ else if (motor2 > 0) motor2 = 255;
+ else if (motor2 < 0) motor2 = -255;
+ }