差别
这里会显示出您选择的修订版和当前版本之间的差别。
两侧同时换到之前的修订记录 前一修订版 后一修订版 | 前一修订版 | ||
mp_quick_reference [2021/10/02 22:12] gongyusu [13. WS2812B控制] |
mp_quick_reference [2021/10/16 15:23] (当前版本) gongyusu |
||
---|---|---|---|
行 2: | 行 2: | ||
{{:pico_learningkit_functions.png|}}<WRAP centeralign> PICO学习板功能及对应的管脚</WRAP> | {{:pico_learningkit_functions.png|}}<WRAP centeralign> PICO学习板功能及对应的管脚</WRAP> | ||
- | ### 1. 通用的板卡控制 | + | #### 1. 通用的板卡控制 |
<code python> | <code python> | ||
import pyb | import pyb | ||
行 14: | 行 13: | ||
</code> | </code> | ||
- | ### 2. 延迟和定时 | + | #### 2. 延迟和定时 |
<code python> | <code python> | ||
行 27: | 行 26: | ||
- | ### 3. 内部LEDs | + | #### 3. LEDs |
<code python> | <code python> | ||
- | from pyb import LED | + | from machine import Pin |
- | led = LED(1) # 1=red, 2=green, 3=yellow, 4=blue | + | led_y = Pin(20,Pin.OUT) |
- | led.toggle() | + | led_r = Pin(26,Pin.OUT) |
- | led.on() | + | led_g = Pin(22,Pin.OUT) |
- | led.off() | + | led_b = Pin(21,Pin.OUT) |
- | # LEDs 3 and 4 support PWM intensity (0-255) | ||
- | LED(4).intensity() # get intensity | ||
- | LED(4).intensity(128) # set intensity to half | ||
</code> | </code> | ||
- | ### 4. 板上按键 | + | #### 4. 板上按键 |
<code python> | <code python> | ||
- | from pyb import Switch | + | import machine |
- | sw = Switch() | + | key1 = machine.Pin(12, machine.Pin.IN, machine.Pin.PULL_UP) |
- | sw.value() # returns True or False | + | key2 = machine.Pin(13, machine.Pin.IN, machine.Pin.PULL_UP) |
- | sw.callback(lambda: pyb.LED(1).toggle()) | + | |
</code> | </code> | ||
- | ### 5. 管脚和GPIO | + | #### 5. 管脚和GPIO |
<code python> | <code python> | ||
行 68: | 行 63: | ||
- | ### 6. 定时器 | + | #### 6. 定时器 |
<code python> | <code python> | ||
行 80: | 行 75: | ||
- | ### 7. PWM | + | #### 7. PWM |
<code python> | <code python> | ||
- | from pyb import Pin, Timer | + | import machine |
+ | import utime | ||
+ | beep = machine.PWM(machine.Pin(22)) | ||
+ | beep.freq(1000) #频率 | ||
+ | while True: | ||
+ | beep.duty_u16(100) #改变占空比改变蜂鸣器的响度 | ||
- | p = Pin('X1') # X1 has TIM2, CH1 | ||
- | tim = Timer(2, freq=1000) | ||
- | ch = tim.channel(1, Timer.PWM, pin=p) | ||
- | ch.pulse_width_percent(50) | ||
</code> | </code> | ||
- | ### 8. ADC | + | #### 8. ADC |
<code python> | <code python> | ||
行 102: | 行 98: | ||
- | ### 9. UART | + | #### 9. UART |
<code python> | <code python> | ||
行 113: | 行 109: | ||
- | ### 10. SPI总线 | + | #### 10. SPI总线 |
<code python> | <code python> | ||
行 125: | 行 121: | ||
- | ### 11. I2C总线 | + | #### 11. I2C总线 |
<code python> | <code python> | ||
行 143: | 行 139: | ||
- | ### 12. 姿态传感器 | + | #### 12. 姿态传感器 |
<code python> | <code python> | ||
行 153: | 行 149: | ||
- | ### 13. WS2812B控制 | + | #### 13. WS2812B控制 |
<code python> | <code python> | ||
行 160: | 行 156: | ||
- | ### 14. 蜂鸣器的控制 | + | #### 14. 蜂鸣器的控制 |
<code python> | <code python> |