差别

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

到此差别页面的链接

两侧同时换到之前的修订记录 前一修订版
后一修订版
前一修订版
mp_key_led [2022/02/24 14:48]
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)
行 301: 行 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
行 312: 行 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)
  
  
行 385: 行 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"​)
     ​     ​
行 403: 行 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
行 414: 行 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):​
行 431: 行 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:
行 444: 行 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
行 456: 行 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)