12.7

一、PGIO配置

from pyb import Pin

1. GPIO输出

 引脚:X1~X12, Y1~Y12

 模式mode = Pin.OUT_PP                推挽输出

Pin.OUT_OD                                    - 开环控制,OC输出

p_out = Pin('X1', Pin.OUT_PP)

p_out.high()                                           # 置高

p_out.low()                                            # 置低

 GPIO输入

# 引脚:X1~X12, Y1~Y12

# 模式mode = Pin.IN - 输入引脚

# 拉动pull = Pin.PULL_NONE - 无电阻;

#            Pin.PULL_UP  - 有上拉电阻;

#            Pin.PULL_DOWN - 有下拉电阻.

p_in = Pin('X2', Pin.IN, Pin.PULL_UP)

r = p_in.value()

二、Servo

from pyb import Servo

# 引脚:X1~X4 =1~4

s1 = Servo("X1")      # X1引脚

s1.angle(45)        # 转到45度,参数范围-90~+90

s1.angle(-60, 1500) # 转到 -60度,在1500ms时间内。

s1.speed(50)        # 设置速度(-100~100)

v = s1.speed()      # 无参数,则返回当前速度

三、ExtInt引脚外部中断

from pyb import  ExtInt

# 引脚:X1~X12, Y1~Y12

# pyb.ExtInt(pin, mode, pull, callback)

# mode = ExtInt.IRQ_RISING  - 上升沿

#        ExtInt.IRQ_FALLING - 下降沿

#        ExtInt.IRQ_RISING_FALLING - 上升和下降沿

# pull = Pin.PULL_NONE - 无拉电阻

#        Pin.PULL_UP  - 有上拉电阻

#        Pin.PULL_DOWN - 有下拉电阻

# callback = 中断回调函数,有一个参数,中断线。

ext = ExtInt(Pin('Y1'), ExtInt.IRQ_RISING, Pin.PULL_DOWN, callback) #配置中断引脚

ext.swint() # 软件触发中断

## ExtInt类方法:

# ext.disalbe()  # 关中断

# ext.enable()  # 开中断

# ext.line()    # 返回中断线

# ext.swint()    # 软件触发中断

# ext.regs()    # 清空配置中断寄存器

你可能感兴趣的:(12.7)