"""
Robocar 2 Wheels - Variante 2
"""
import machine, time
print(" ##### RoboCar 2 Wheels #####")
ena_pin = 23; in1_pin = 22; in2_pin = 21;
enb_pin = 15; in3_pin = 4; in4_pin = 2;
ena = machine.PWM(machine.Pin(ena_pin)); ena.duty(0)
in1 = machine.Pin(in1_pin, machine.Pin.OUT); in1.off()
in2 = machine.Pin(in2_pin, machine.Pin.OUT); in2.off()
enb = machine.PWM(machine.Pin(enb_pin)); enb.duty(0)
in3 = machine.Pin(in3_pin, machine.Pin.OUT); in1.off()
in4 = machine.Pin(in4_pin, machine.Pin.OUT); in2.off()
def motorA(duty_value): # rechter Motor
print("Motor rechts : ", duty_value)
if (duty_value>=0):
in1.on(); in2.off(); ena.duty(duty_value)
else:
in1.off(); in2.on(); ena.duty(-duty_value)
def motorB(duty_value): # linker Motor
print("Motor links : ", duty_value)
if (duty_value>=0):
in3.on(); in4.off(); enb.duty(duty_value)
else:
in3.off(); in4.on(); enb.duty(-duty_value)
def fahren(*args):
l = len(args)
print("Fahren: ", len(args), args)
if l==0:
pass
elif l==1:
print(" : ", args[0])
motorA(args[0])
motorB(args[0])
elif l==2:
print(" : ", args[0], args[1])
motorA(args[0])
motorB(args[1])
elif l==3:
print(" : ", args[0], args[1], args[2])
motorA(args[0])
motorB(args[1])
time.sleep(args[2])
else:
pass
dt = 2.5
fahren()
fahren(111)
fahren(222, 333); time.sleep(dt)
fahren(-22, 88); time.sleep(dt)
fahren(222, -88, 2)