1

I am controlling motor with raspberry pi, using wiringPi. I made my code, and implemented. It worked. But when I exit the code, motor was still working. How can I stop this?

while(1){
            digitalWrite(EN1, HIGH);
            digitalWrite(IN1, HIGH);
            digitalWrite(IN2, LOW);
            delay(10000);

            digitalWrite(EN1, LOW);
            delay(5000);

            digitalWrite(EN1, HIGH);
            digitalWrite(IN1, HIGH);
            digitalWrite(IN2, LOW);
            delay(10000);

            digitalWrite(EN1, LOW);
            delay(5000);
    }
Ju-Ae
  • 11
  • 2

1 Answers1

1

Because of your

while (1)

I understand you stop with a signal, like Ctrl-C. You should use signal handler to handle the stop and when you catch the signal, you should stop the motors with

digitalWrite(EN1, LOW);
David Bensoussan
  • 2,887
  • 2
  • 38
  • 55