【DigiKey好物畅享】+ Adafruit + RP2040 MarcoPad + HelloWord

1、编程方式

Adafruit + RP2040 MarcoPad主芯片是RP2040,编程方式有很多种:

  • C/C++方式(略微复杂,先不详细介绍)
    • Arduino
    • 自己搭建编译环境
  • Python方式
    • MicorPython环境
    • circuitpython环境

2、Python环境构建

  • 下载RP2040 MarcoPad官方uf2文件(地址:adafruit_macropad_rp2040) ,按下旋转编码器,连接USB,电脑显示fat32格式的U盘,将uf2文件复制到U盘中。
  • 电脑安装Thonny软件,选择正确的COM口,RP2040 MarcoPad就连接好了。
  • 下载RP2040 MarcoPad的library库。地址:macropad-circuitpython-library
  • 通过Thonny将需要的lib库上传到RP2040 MarcoPad中。

3、HelloWorld

print("HelloWorld")

点击运行。

4、键盘扫面,OLED显示

import time
from adafruit_macropad import MacroPad

macropad = MacroPad()

text_lines = macropad.display_text(title="MacroPad Info")

while True:
    key_event = macropad.keys.events.get()
    if key_event and key_event.pressed:
        text_lines[0].text = f"Key {key_event.key_number} pressed!"
    text_lines[1].text = f"Rotary encoder {macropad.encoder}"
    text_lines[2].text = f"Encoder switch: {macropad.encoder_switch}"
    text_lines.show()
    time.sleep(0.1)

效果: