差别
这里会显示出您选择的修订版和当前版本之间的差别。
两侧同时换到之前的修订记录 前一修订版 后一修订版 | 前一修订版 | ||
mp_quick_reference [2021/10/02 22:21] gongyusu [4. 板上按键] |
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 |
- | import utime | + | |
- | led = Pin(25,Pin.OUT) | + | led_y = Pin(20,Pin.OUT) |
- | while True: | + | led_r = Pin(26,Pin.OUT) |
- | led.value(1) | + | led_g = Pin(22,Pin.OUT) |
- | utime.sleep(2) | + | led_b = Pin(21,Pin.OUT) |
- | led.value(0) | + | |
- | utime.sleep(1) | + | |
</code> | </code> | ||
- | ### 4. 板上按键 | + | #### 4. 板上按键 |
<code python> | <code python> | ||
import machine | import machine | ||
- | import utime | ||
- | button = machine.Pin(12, machine.Pin.IN, machine.Pin.PULL_UP) //12、13 | ||
- | led = machine.Pin(16,machine.Pin.OUT) | ||
- | while True: | ||
- | if button.value() == 1: | ||
- | led.value(0) | ||
- | utime.sleep(1) | ||
- | print("You not pressed the button!") | ||
- | else: | ||
- | print("You pressed the button!") | ||
- | led.value(1) | ||
- | utime.sleep(1) | ||
+ | key1 = machine.Pin(12, machine.Pin.IN, machine.Pin.PULL_UP) | ||
+ | key2 = machine.Pin(13, machine.Pin.IN, machine.Pin.PULL_UP) | ||
</code> | </code> | ||
- | ### 5. 管脚和GPIO | + | #### 5. 管脚和GPIO |
<code python> | <code python> | ||
行 76: | 行 63: | ||
- | ### 6. 定时器 | + | #### 6. 定时器 |
<code python> | <code python> | ||
行 88: | 行 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> | ||
行 110: | 行 98: | ||
- | ### 9. UART | + | #### 9. UART |
<code python> | <code python> | ||
行 121: | 行 109: | ||
- | ### 10. SPI总线 | + | #### 10. SPI总线 |
<code python> | <code python> | ||
行 133: | 行 121: | ||
- | ### 11. I2C总线 | + | #### 11. I2C总线 |
<code python> | <code python> | ||
行 151: | 行 139: | ||
- | ### 12. 姿态传感器 | + | #### 12. 姿态传感器 |
<code python> | <code python> | ||
行 161: | 行 149: | ||
- | ### 13. WS2812B控制 | + | #### 13. WS2812B控制 |
<code python> | <code python> | ||
行 168: | 行 156: | ||
- | ### 14. 蜂鸣器的控制 | + | #### 14. 蜂鸣器的控制 |
<code python> | <code python> |