Exemplo n.º 1
0
def my():
    wp.wiringPiSetupGpio()
    wp.wiringPiSetup()
    uls = Ultrasonic(20, 21)
    tesla = Tesla_motor(23, 18, 25, 24)
    tesla.allStop()
    while 1:
        distance = uls.distance()
        print(distance)
        if distance > 30:
            tesla.forwardDrive()
        #sleep(5)
        else:
            tesla.allStop()
Exemplo n.º 2
0
def loop():
    global lcd
    lcd = LCD()
    us = Ultrasonic(GPIO_TRIGGER, GPIO_ECHO)
    while True:
        distance = us.distance()
        if distance:
            lcd.message('distance:\n                ')
            print('distance:%0.2fcm' % distance)
            #lcd.clear()
            lcd.message('distance:\n%0.2fcm' % distance)
        else:
            print('Error')
        time.sleep(0.2)