Ejemplo n.º 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
Ejemplo n.º 2
0
from xugu import Pin  #从xugu库中导入Pin类
import time  #导入时间模块
pin = Pin(4, Pin.IN)  #创建Pin对象
test = 30
while test > 0:
    value = pin.read_digital()  #读取对应Pin脚的电平值
    if value:
        print("find human!!!")  #电平为1代表发现人
    else:
        print("no human!!!")  #电平为0代表没发现人
    time.sleep(1)  #睡眠1秒
    test -= 1
Ejemplo n.º 3
0
from xugu import Pin, SerialMgt  # 从 xugu 库中导入 Pin、SerialMgt 类
import time  # 导入时间模块
p = Pin(4, Pin.IN)  # 初始化 4 号引脚,设置为数字输入模式
ser = SerialMgt()  #初始化串口
while True:
    value = p.read_digital()  # 读取 4 号引脚电平信息,赋值给 value
    print(value)  # 将value的值打印到终端上
    ser.write(str(value).encode())  # 将value的值写入到串口
    time.sleep(0.1)  # 持续100ms