Exemple #1
0
def xugu():
    global value, ret, types
    while True:
        if ret == 0:
            xugu_pin = Pin(pin, Pin.IN)
            value = xugu_pin.read_digital()
            ret = None
        if ret == 1:
            xugu_pin = Pin(pin, Pin.ANALOG)
            value = xugu_pin.read_analog()
            ret = None
        if types in type_D_list:
            xugu_pin = Pin(pin, Pin.OUT)
            if value == 0:
                xugu_pin.write_digital(value)
            else:
                value = 1
                xugu_pin.write_digital(value)
            types = None
        if types in type_A_list:
            xugu_pin = Pin(pin, Pin.OUT)
            xugu_pin.write_analog(value)
            types = None
        if types in type_S_list:
            xugu_servo = Servo(pin)
            xugu_servo.write_angle(value)
            types = None
Exemple #2
0
from xugu import Pin  # 从xugu库中导入Pin类
p = Pin(10, Pin.OUT)  # 初始化10号引脚设置为输出模式
p.write_analog(128)  # 给引脚设置模拟值128
Exemple #3
0
from xugu import Pin                     #从xugu库中导入Pin类
p = Pin("A0",Pin.ANALOG)                 #创建Pin对象,并初始化A0引脚
p10 = Pin(10,Pin.PWM)                    #创建Pin对象,并初始化10号引脚
p10.write_analog(int(p.read_analog()/4)) #根据A0的模拟电位值,设置对应引脚的电位值