Пример #1
0
def Main():
    try:    
        lastColor = 'green'
        distanceActions = DistanceActions(trigger, echo)
        servoActions = Actions()
        while True:
            distance = distanceActions.TakeDistance()
            print(distance)
            if(distance <= minDistance):
                GPIO.output(ledRojo, GPIO.HIGH)
                GPIO.output(ledAmarillo, GPIO.LOW)
                GPIO.output(ledVerde, GPIO.LOW)
                if(lastColor != 'red'):
                    servoActions.Deg0(servo)
                lastColor = 'red'
            else:
                if(distance >= minDistance and distance <= midDistance):
                    GPIO.output(ledRojo, GPIO.LOW)
                    GPIO.output(ledAmarillo, GPIO.HIGH)
                    GPIO.output(ledVerde, GPIO.LOW)
                    if(lastColor != 'yellow'):
                        servoActions.Deg90(servo)
                    lastColor = 'yellow'
                else:
                    GPIO.output(ledRojo, GPIO.LOW)
                    GPIO.output(ledAmarillo, GPIO.LOW)
                    GPIO.output(ledVerde, GPIO.HIGH)
                    if(lastColor != 'green'):
                        servoActions.Deg180(servo)
                    lastColor = 'green'
            time.sleep(0.3)
    except (KeyboardInterrupt, SystemExit):
        raise
    finally:  
        GPIO.cleanup()