Exemplo n.º 1
0
def main():
    #    import time
    #
    #    print "********************************************"
    #    print "*                                          *"
    #    print "*           SunFounder TB6612              *"
    #    print "*                                          *"
    #    print "*          Connect MA to BCM17 -> 20            *"
    #    print "*          Connect MB to BCM18 -> 16           *"
    #    print "*         Connect PWMA to BCM27 -> 12          *"
    #    print "*         Connect PWMB to BCM22 -> 26          *"
    #    print "*                                          *"
    #    print "********************************************"
    GPIO.setmode(GPIO.BCM)
    GPIO.setup((12, 26), GPIO.OUT)
    a = GPIO.PWM(12, 60)
    b = GPIO.PWM(26, 60)
    a.start(0)
    b.start(0)

    def a_speed(value):
        a.ChangeDutyCycle(value)

    def b_speed(value):
        b.ChangeDutyCycle(value)

    motorA = TB6612.Motor(20)
    motorB = TB6612.Motor(16)
    #    motorA.debug = True
    #    motorB.debug = True
    motorA.pwm = a_speed
    motorB.pwm = b_speed

    inkey = _Getch()
    while (1):
        k = inkey()
        if k != '': break
    if k == '\x1b[A':
        print("forward")
        motorA.forward()
        motorA.speed = 100
        motorB.forward()
        motorB.speed = 100
    elif k == '\x1b[B':
        print("backward")
        motorA.backward()
        motorA.speed = 100
        motorB.backward()
        motorB.speed = 100
    elif k == '\x1b[C':
        print("right")
        motorA.backward()
        motorA.speed = 100
        motorB.forward()
        motorB.speed = 100
    elif k == '\x1b[D':
        print("left")
        motorA.forward()
        motorA.speed = 100
        motorB.backward()
        motorB.speed = 100
#    elif k==',':
#        print("<")
#    elif k=='.':
#        print(">")
    else:
        print("not an arrow key!")
Exemplo n.º 2
0
def main():
	import time
	GPIO.setwarnings(False)
	GPIO.setmode(GPIO.BCM)
	GPIO.setup((12, 26), GPIO.OUT)
	a = GPIO.PWM(12, 60)
	b = GPIO.PWM(26, 60)
	a.start(0)
	b.start(0)

	def a_speed(value):
		a.ChangeDutyCycle(value)

	def b_speed(value):
		b.ChangeDutyCycle(value)

	motorA = TB6612.Motor(20)
	motorB = TB6612.Motor(16)
# 	motorA.debug = True
# 	motorB.debug = True
	motorA.pwm = a_speed
	motorB.pwm = b_speed

	delay = 0.05
	
	while(1):
		s = get()
		if s == 0
		#stop if nothing pressed#
		    motorA.stop()
		    motorB.stop()   
		elif s == 1
		#going forward#
		    motorA.forward()
		    motorA.speed = 100
		    motorB.forward()
		    motorB.speed = 100

		elif s == -1
		#going backward#
		    motorA.backward()
		    motorA.speed = 100
		    motorB.backward()
		    motorB.speed = 100

		elif s == 2
		#rotate right#	
		    motorA.forward()
		    motorA.speed = 100
		    motorB.backward()
		    motorB.speed = 100

		elif s == 3
		#rotate left#
		    motorA.backward()
		    motorA.speed = 100
		    motorB.forward()
		    motorB.speed = 100

		else:
		    destroy()