[分享] circuitpython 编程的提示和技巧

dcexpert   2021-6-17 20:04 楼主

circuitpython 编程的一些技巧和提示:


Read an digital input as a Button

import board
from digitalio import DigitalInOut, Pull
button = DigitalInOut(board.D3) # defaults to input
button.pull = Pull.UP # turn on internal pull-up resistor
print(button.value)  # False == pressed

 Read a Potentiometer

import board
import analogio
potknob = analogio.AnalogIn(board.A1)
position = potknob.value  # ranges from 0-65535
pos = potknob.value // 256  # make 0-255 range

 

游客,如果您要查看本帖隐藏内容请回复

回复评论 (1)

circuitpython 编程的提示和技巧,太好啊

点赞  2024-11-9 22:48
电子工程世界版权所有 京B2-20211791 京ICP备10001474号-1 京公网安备 11010802033920号
    写回复