Hey guys!
i would like to ask if i could add in some delays to the motors so that when the touch sensor is released, it will continue moving to make a uturn.
Would be grateful for any help!
# S1 = left touch
# S4 = right touch
from BrickPi import * #import BrickPi.py file to use BrickPi operations
#Move Forward
def fwd():
BrickPi.MotorSpeed[leftm] = -150
BrickPi.MotorSpeed[rightm] = -150
#Move Left
def left():
BrickPi.MotorSpeed[leftm] = 150
BrickPi.MotorSpeed[rightm] = -150
#Move Right
def right():
BrickPi.MotorSpeed[leftm] = 150
BrickPi.MotorSpeed[rightm] = -150
BrickPiSetup()
BrickPi.SensorType[PORT_1] = TYPE_SENSOR_TOUCH
BrickPi.SensorType[PORT_4] = TYPE_SENSOR_TOUCH
leftm=PORT_A
rightm=PORT_D
BrickPi.MotorEnable[leftm] = 1
BrickPi.MotorEnable[rightm] = 1
BrickPiSetupSensors()
while True:
fwd()
if BrickPi.Sensor[PORT_1] == 1: # when left touch sensor is pressed
right()
if BrickPi.Sensor[PORT_4] == 1: # when right touch sensor is pressed
left()
BrickPiUpdateValues()
time.sleep(.01)