差别

这里会显示出您选择的修订版和当前版本之间的差别。

到此差别页面的链接

两侧同时换到之前的修订记录 前一修订版
后一修订版
前一修订版
mp_key_led [2022/02/24 14:35]
gongyusu
mp_key_led [2023/07/31 15:59] (当前版本)
group003
行 155: 行 155:
 </​code>​ </​code>​
  
-修改引脚编号,将它从连接到Pico核心板内部LED的引脚25更改为连接到学习板上红色LED的引脚19。这个LED的名称也最好随之修改,比如改为led_red。程序中所有用到该LED的地方,都要把名字修改过来:​+修改引脚编号,将它从连接到Pico核心板内部LED的引脚25更改为连接到学习板上红色LED的引脚26。这个LED的名称也最好随之修改,比如改为led_red。程序中所有用到该LED的地方,都要把名字修改过来:​
 <code python> <code python>
 import machine import machine
 import utime import utime
  
-led_red = machine.Pin(19, machine.Pin.OUT)+led_red = machine.Pin(26, machine.Pin.OUT)
  
 while True:  while True: 
行 218: 行 218:
 import utime import utime
  
-key1 = machine.Pin(12,​ machine.Pin.IN,​ machine.Pin.PULL_DOWN)+key1 = machine.Pin(12,​ machine.Pin.IN,​ machine.Pin.PULL_UP)
 while True: while True:
-    if key1.value() == 1:+    if key1.value() == 0:
         print("​You pressed the button!"​)         print("​You pressed the button!"​)
         utime.sleep(2)         utime.sleep(2)
行 243: 行 243:
  
 <code python> <code python>
-led_red = machine.Pin(19, machine.Pin.OUT) +led_red = machine.Pin(26, machine.Pin.OUT) 
-key1 = machine.Pin(12,​ machine.Pin.IN,​ machine.Pin.PULL_DOWN)+key1 = machine.Pin(12,​ machine.Pin.IN,​ machine.Pin.PULL_UP)
 </​code>​ </​code>​
  
行 250: 行 250:
 <code python> <code python>
 while True: while True:
-    if key1.value() == 1:+    if key1.value() == 0:
 </​code>​ </​code>​
  
行 271: 行 271:
 import utime import utime
 led_red = machine.Pin(19,​ machine.Pin.OUT) led_red = machine.Pin(19,​ machine.Pin.OUT)
-key1 = machine.Pin(12,​ machine.Pin.IN,​ machine.Pin.PULL_DOWN)+key1 = machine.Pin(12,​ machine.Pin.IN,​ machine.Pin.PULL_UP)
 while True: while True:
-    if key1.value() == 1:+    if key1.value() == 0:
         led_red.value(1)         led_red.value(1)
         utime.sleep(2)         utime.sleep(2)
行 290: 行 290:
  
  
 +<WRAP center round tip 60%>
 +以下部分为其它与LED控制相关的参考案例。
 +</​WRAP>​
  
 ### 5. 案例汇总 ### 5. 案例汇总
行 298: 行 301:
 # rgb-blink.py # rgb-blink.py
  
-# RED LED - Pico GPIO 19 +# RED LED - Pico GPIO 26 
-# GREEN LED - Pico GPIO 18 +# GREEN LED - Pico GPIO 22 
-# BLUE LED - Pico GPIO 17 +# BLUE LED - Pico GPIO 21 
-# YELLOW LED - Pico GPIO 16 +# YELLOW LED - Pico GPIO 20  ​
 # EETree Info & Tech 2021 # EETree Info & Tech 2021
 # https://​www.eetree.cn # https://​www.eetree.cn
行 309: 行 312:
 import utime import utime
  
-led_red = machine.Pin(19, machine.Pin.OUT) +led_red = machine.Pin(26, machine.Pin.OUT) 
-led_green = machine.Pin(18, machine.Pin.OUT) +led_green = machine.Pin(22, machine.Pin.OUT) 
-led_blue = machine.Pin(17, machine.Pin.OUT) +led_blue = machine.Pin(21, machine.Pin.OUT) 
-led_yellow = machine.Pin(16,​machine.Pin.OUT)+led_yellow = machine.Pin(20,​machine.Pin.OUT)
  
  
行 382: 行 385:
 import utime import utime
  
-key1 = machine.Pin(12,​ machine.Pin.IN,​ machine.Pin.PULL_DOWN)+key1 = machine.Pin(12,​ machine.Pin.IN,​ machine.Pin.PULL_UP)
 key2 = machine.Pin(13,​ machine.Pin.IN,​ machine.Pin.PULL_UP) key2 = machine.Pin(13,​ machine.Pin.IN,​ machine.Pin.PULL_UP)
  
 while True: while True:
-    if key1.value() == 1:+    if key1.value() == 0:
         print("​key1 pressed"​)         print("​key1 pressed"​)
     ​     ​
行 400: 行 403:
 # interrrupt-toggle-demo.py # interrrupt-toggle-demo.py
  
-# RED LED - Pico GPIO 19 +# RED LED - Pico GPIO 26 
-# GREEN LED - Pico GPIO 18+# GREEN LED - Pico GPIO 22
  
 # KEY1 - Pico GPIO 12 # KEY1 - Pico GPIO 12
行 411: 行 414:
 import utime import utime
  
-led_red = machine.Pin(19, machine.Pin.OUT) +led_red = machine.Pin(26, machine.Pin.OUT) 
-led_green = machine.Pin(18, machine.Pin.OUT)+led_green = machine.Pin(22, machine.Pin.OUT)
  
 led_red.value(0) led_red.value(0)
 led_green.value(0) led_green.value(0)
  
-key1 = machine.Pin(12,​ machine.Pin.IN,​ machine.Pin.PULL_DOWN)+key1 = machine.Pin(12,​ machine.Pin.IN,​ machine.Pin.PULL_UP)
  
 def int_handler(pin):​ def int_handler(pin):​
行 428: 行 431:
     key1.irq(handler=int_handler)     key1.irq(handler=int_handler)
  
-button_red.irq(trigger=machine.Pin.IRQ_RISING, handler=int_handler)+key1.irq(trigger=machine.Pin.IRQ_FALLING ​, handler=int_handler)
  
 while True: while True:
行 441: 行 444:
 # switch-led-demo.py # switch-led-demo.py
  
-# RED LED - Pico GPIO 19 +# RED LED - Pico GPIO 26 
-# GREEN LED - Pico GPIO 18 +# GREEN LED - Pico GPIO 22 
-# BLUE LED - Pico GPIO 17+# BLUE LED - Pico GPIO 21
  
 # BLACK BUTTON - Pico GPIO 2 - Pin 4 # BLACK BUTTON - Pico GPIO 2 - Pin 4
行 453: 行 456:
 import utime import utime
  
-led_red = machine.Pin(19, machine.Pin.OUT) +led_red = machine.Pin(26, machine.Pin.OUT) 
-led_green = machine.Pin(18, machine.Pin.OUT) +led_green = machine.Pin(22, machine.Pin.OUT) 
-led_blue = machine.Pin(17, machine.Pin.OUT)+led_blue = machine.Pin(21, machine.Pin.OUT)
  
 led_red.value(0) led_red.value(0)
行 503: 行 506:
  
 </​code>​ </​code>​
- 
-来自FPGA4FUN上的介绍 
-理想的LED控制是电流源,控制器的引脚是电压控制的,所以一个简单的解决方案是添加一个电阻与LED串联,电阻的阻值从100Ω到1KΩ都很常见。 
- 
-LED (Light Emitting Diode)是一种半导体器件,当电流通过它时,它就会发光。LED符号看起来像一个二极管,有一个阳极(+)和阴极(-)。 
-一个LED就像一个二极管,用一种方式导电,用另一种方式阻挡。 
- 
-像所有二极管一样,它也有一个阈值电压。普通红色LED的阈值电压约为2.0V。2.0V以下不发光(无电流通过LED)。在2.0V以上,LED导电,光强度取决于通过LED的电流。 
- 
-LED有两个不能超过的物理极限:​ 
-最大正向电流(即最大光强)。最大值通常是几个10的mA。 
-最大反向电压(即使当LED被反向偏置时没有电流通过,也不要反向偏置太多)。反向电压限制通常为5V…比普通二极管低得多!