I'm building a little Car with 2 Engine, one L298N driver and a Raspberry pi 3. But i need the engine run during some specific seconds and then cleanup the GPIO and the engine stop. Why? Because i'm building an API then when i do the car go forward with my actual code the car go forward in an infinite loop and it doesn't accept other request until it finished the last request(go forward) but it won't happen because is an infinite loop.
My code for the car go forward is:
import RPi.GPIO as GPIO
import os
import time
ena = 18
in1 = 23
in2 = 24
enb = 19
in3 = 6
in4 = 5
GPIO.setmode(GPIO.BCM)
GPIO.setup(ena,GPIO.OUT)
GPIO.setup(in1,GPIO.OUT)
GPIO.setup(in2,GPIO.OUT)
GPIO.setup(enb,GPIO.OUT)
GPIO.setup(in3,GPIO.OUT)
GPIO.setup(in4,GPIO.OUT)
pwm_a = GPIO.PWM(ena,500)
pwm_b = GPIO.PWM(enb,500)
pwm_a.start(0)
pwm_b.start(0)
os.system('clear')
try:
while True:
GPIO.output(in1,False)
GPIO.output(in2,True)
GPIO.output(in3,False)
GPIO.output(in4,True)
pwm_a.ChangeDutyCycle(100)
pwm_b.ChangeDutyCycle(100)
except KeyboardInterrupt:
pwm_a.stop()
pwm_b.stop()
GPIO.cleanup()
os.system('clear')
print
print("User finished the program")
print
exit()
time.sleep()
what you want? – Mark Smith Oct 15 '18 at 19:13