美文网首页
树莓派pico vscodecode micropython 环

树莓派pico vscodecode micropython 环

作者: skkily | 来源:发表于2024-08-07 09:49 被阅读0次
  1. vscode code的micropython开发环境推荐安装扩展 micropico

  2. 板载led闪烁示例

    from machine import Pin
    from time import sleep
    
    led = Pin('LED', Pin.OUT)
    print('Blinking LED Example')
    
    while True:
      led.value(not led.value())
      sleep(0.5)
      
    

    执行步骤如下:


    image.png
  1. gpio触发中断, 读取数据gpio高低电平示例:

    from machine import Pin
    from time import sleep
    
    cs1 = Pin('GP20', Pin.IN) #设置GPIO20输入
    pin1 = Pin('GP21', Pin.IN) #设置GPIO21输入
    
    def cs1_callback(pin: Pin): #中断回调函数
        val = pin1.value() #获得GPIO21的电平值
        if val:
            print("high")
        else:
            print("low")
        sleep(1)
    
    cs1.irq(trigger=Pin.IRQ_FALLING, handler=cs1_callback) #设置GPIO20的回调出发函数, 下降沿触发
    
    while True: #设置死循环, 防止程序退出
        pass
    

相关文章

网友评论

      本文标题:树莓派pico vscodecode micropython 环

      本文链接:https://www.haomeiwen.com/subject/rgmqkjtx.html