Can someone help me to improve my code? IR remote control to control Motor

Try this... before setup(), create an "infinite flag" and reset as "off"

int infinite = 0; // 0 = NOT infinite

Next, create a condition outside the button press tests "if the infinite flag is set... run your motors"

if (infinite) { // infinite flag was set... make the motors run
      rotateMotor(4, 50, motorDir1);  // Mode 1: 4 rotations, half speed
      rotateMotor(4, 50, motorDir2); // Mode 1: 4 rotations, half speed in reverse (clockwise)
}

Then, if you press "button 1" you will need to turn the infinite flag "on" inside the "button 1" condition

infinite = 1;

Then, inside button "2", "3" and "5" you need to turn the infinite flag OFF so the "infinite" condition fails...

infinite = 0;
2 Likes