from machine import * from utime import * poti = ADC(0) led1 = Pin(16, Pin.OUT) led2 = Pin(14, Pin.OUT) led3 = Pin(12, Pin.OUT) # led4 = Pin(1, Pin.OUT) - TXD # led5 = Pin(3, Pin.OUT) - RXD # Pin 2 = eingebaute LED taster = Pin(2, Pin.IN, Pin.PULL_UP) tasterstatus = False zustand = 1 servo1 = PWM(Pin(0), freq=50) servo2 = PWM(Pin(4), freq=50) servo3 = PWM(Pin(5), freq=50) servo4 = PWM(Pin(13), freq=50) servo5 = PWM(Pin(15), freq=50) # "map" - Befehl wie beim # Potiwerte: 767 - 65535 # Servowerte: 25 (= -90°) bis 125 (= +90°) def convert(x, in_min, in_max, out_min, out_max): return (x - in_min) * (out_max - out_min) // (in_max - in_min) + out_min print("Zustand: " + str(zustand)) while True: if tasterstatus == False and taster.value() == 0: tasterstatus = True if zustand > 0 and zustand < 5: zustand = zustand + 1 print("Zustand: " + str(zustand)) else: zustand = 1 print("Zustand: " + str(zustand)) if taster.value() == 1: tasterstatus = False if zustand == 5: led3.value(1) led2.value(0) led1.value(1) potiwert = poti.read_u16() servowert = convert(potiwert, 767, 65535, 25, 125) servo5.duty(servowert) print("Servo Winkel: " + str(convert(servowert, 25, 125, -90, 90))) sleep(0.1) if zustand == 4: led3.value(0) led2.value(0) led1.value(1) potiwert = poti.read_u16() servowert = convert(potiwert, 767, 65535, 25, 125) servo4.duty(servowert) print("Servo Winkel: " + str(convert(servowert, 25, 125, -90, 90))) sleep(0.1) if zustand == 3: led3.value(1) led2.value(1) led1.value(0) potiwert = poti.read_u16() servowert = convert(potiwert, 767, 65535, 25, 125) servo3.duty(servowert) print("Servo Winkel: " + str(convert(servowert, 25, 125, -90, 90))) sleep(0.1) if zustand == 2: led3.value(0) led2.value(1) led1.value(0) potiwert = poti.read_u16() servowert = convert(potiwert, 767, 65535, 25, 75) servo2.duty(servowert) print("Servo Winkel: " + str(convert(servowert, 25, 75, -90, 0))) sleep(0.1) if zustand == 1: led3.value(1) led2.value(0) led1.value(0) potiwert = poti.read_u16() servowert = convert(potiwert, 767, 65535, 25, 125) servo1.duty(servowert) print("Servo Winkel: " + str(convert(servowert, 25, 125, -90, 90))) sleep(0.1)