差别
这里会显示出您选择的修订版和当前版本之间的差别。
两侧同时换到之前的修订记录 前一修订版 后一修订版 | 前一修订版 | ||
mp_quick_reference [2021/10/02 22:25] gongyusu [3. LEDs] |
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 machine import Pin | from machine import Pin | ||
- | led_y = Pin(16,Pin.OUT) | + | led_y = Pin(20,Pin.OUT) |
- | led_r = Pin(19,Pin.OUT) | + | led_r = Pin(26,Pin.OUT) |
- | led_g = Pin(18,Pin.OUT) | + | led_g = Pin(22,Pin.OUT) |
- | led_b = Pin(17,Pin.OUT) | + | led_b = Pin(21,Pin.OUT) |
</code> | </code> | ||
- | ### 4. 板上按键 | + | #### 4. 板上按键 |
<code python> | <code python> | ||
行 50: | 行 49: | ||
- | ### 5. 管脚和GPIO | + | #### 5. 管脚和GPIO |
<code python> | <code python> | ||
行 64: | 行 63: | ||
- | ### 6. 定时器 | + | #### 6. 定时器 |
<code python> | <code python> | ||
行 76: | 行 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> | ||
行 98: | 行 98: | ||
- | ### 9. UART | + | #### 9. UART |
<code python> | <code python> | ||
行 109: | 行 109: | ||
- | ### 10. SPI总线 | + | #### 10. SPI总线 |
<code python> | <code python> | ||
行 121: | 行 121: | ||
- | ### 11. I2C总线 | + | #### 11. I2C总线 |
<code python> | <code python> | ||
行 139: | 行 139: | ||
- | ### 12. 姿态传感器 | + | #### 12. 姿态传感器 |
<code python> | <code python> | ||
行 149: | 行 149: | ||
- | ### 13. WS2812B控制 | + | #### 13. WS2812B控制 |
<code python> | <code python> | ||
行 156: | 行 156: | ||
- | ### 14. 蜂鸣器的控制 | + | #### 14. 蜂鸣器的控制 |
<code python> | <code python> |