sbcshop / MotorShield

Designed to help you get your Raspberry Pi based Robot. This board can control DC motor as well as the stepper motor. You can connect your IR and Ultrasonic sensors to tell your robot about its environment. You can easily make your Line Following, Object following, Wall following, Maze-Solver Robots.
https://shop.sb-components.co.uk/products/motorshield-for-raspberry-pi
53 stars 47 forks source link

Motor stay on always when .stop function is used #26

Open AlphaWolf655 opened 2 years ago

AlphaWolf655 commented 2 years ago

tried to make it so that if something is infront of my ultrasonic sensor then the motor turns on but as soon as theres nothing infront of it the motor stops but for some reason the motor never stops.

`import RPi.GPIO as GPIO import time import PiMotor

GPIO.setwarnings(False)

US1 = PiMotor.Sensor("ULTRASONIC", 40) m1 = PiMotor.Motor("MOTOR1", 2)

while True: US1.sonicCheck() time.sleep(0.5) if US1.Triggered == True: print('Starting') m1.forward(40) else: print('Stopping') m1.stop`

when i run this script and stand infront of the sensor the motor turns on but when i move out the way the motor stays on but it prints "stopping" which means the else part of the if statement is being executed but the motor doesnt stop, the .stop function does work ive tried but for some reason here it doesnt work.