差别
这里会显示出您选择的修订版和当前版本之间的差别。
两侧同时换到之前的修订记录 前一修订版 后一修订版 | 前一修订版 | ||
mp_pwm_led [2023/08/01 08:52] group003 |
mp_pwm_led [2023/08/01 09:54] (当前版本) group003 |
||
---|---|---|---|
行 30: | 行 30: | ||
# led-pwm.py | # led-pwm.py | ||
- | # POT - Pico GPIO 26 ADC0 | + | # POT - Pico GPIO 28 ADC2 |
- | # RED LED - Pico GPIO 19 | + | # RED LED - Pico GPIO 25 |
# EETree Info&Tech 2021 | # EETree Info&Tech 2021 | ||
行 41: | 行 41: | ||
import utime | import utime | ||
- | led_red = machine.PWM(machine.Pin(19)) | + | led_red = machine.PWM(machine.Pin(25)) |
- | potentiometer = machine.ADC(26) | + | potentiometer = machine.ADC(28) |
led_red.freq(1000) | led_red.freq(1000) | ||
行 89: | 行 89: | ||
</code> | </code> | ||
PWM是软件PWM,它可以设置在任意管脚上。初步测试过Pin0, 15, 16等等。都具有相类似波形。 | PWM是软件PWM,它可以设置在任意管脚上。初步测试过Pin0, 15, 16等等。都具有相类似波形。 | ||
+ | |||
+ | |||
+ | |||
+ | ### 3. 呼吸灯的例子 | ||
+ | |||
+ | <code python> | ||
+ | from machine import Pin, PWM,Timer | ||
+ | |||
+ | LED = PWM(Pin(25)) | ||
+ | |||
+ | n = 0 | ||
+ | |||
+ | def breathing(t): | ||
+ | global n | ||
+ | LED.duty_u16(abs(32000- n*1000)) | ||
+ | n = (n + 1) % 64 | ||
+ | |||
+ | T0 = Timer(-1) | ||
+ | T0.init(period=20, mode=Timer.PERIODIC, callback=breathing) | ||
+ | </code> | ||
### 3. Maker.io上的文章 | ### 3. Maker.io上的文章 | ||
行 169: | 行 189: | ||
</code> | </code> | ||
- | **返回目录** | + | ## 返回目录 |
[[pico_micropython|MicroPython编程PICO训练板]] | [[pico_micropython|MicroPython编程PICO训练板]] |