5770| 0
|
BPI-PicoW-S3使用增量型旋转编码器[CircuitPython] |
BPI-Pico-S3 与 Raspberry Pi Pico 板尺寸相同,搭载ESP32S3芯片,8M flash,4层PCB,电镀半孔工艺,陶瓷天线,支持 2.4 GHz Wi-Fi 和 Bluetooth® LE 双模无线通信,是一款专为物联网开发和Maker DIY设计的开发板。 出厂内置 tinyUF2 + CircuitPython,推荐使用Mu编辑器上手CircuitPython开发。 BiliBili视频 https://www.bilibili.com/video/BV1yd4y1t75R 硬件接口示意图使用增量型旋转编码器接线参考
import board import digitalio dt = digitalio.DigitalInOut(board.GP0) clk = digitalio.DigitalInOut(board.GP1) dt.switch_to_input() clk.switch_to_input() dt_last_value = 0 clk_last_value = 0 while True: if dt.value != dt_last_value or clk.value != clk_last_value: dt_last_value = int(dt.value) clk_last_value = int(clk.value) print((dt_last_value,clk_last_value))
import board import digitalio dt = digitalio.DigitalInOut(board.GP0) clk = digitalio.DigitalInOut(board.GP1) dt.switch_to_input() clk.switch_to_input() dt_last_value = 0 clk_last_value = 0 count = 0 while True: if dt.value != dt_last_value or clk.value != clk_last_value: dt_last_value = int(dt.value) clk_last_value = int(clk.value) print((dt_last_value,clk_last_value)) if (dt_last_value,clk_last_value) == (1,1): print('--',count_1,'--') count += 1
由此可设计一个顺时针旋转使计数+1,逆时针旋转使计数-1的程序,并加入消抖除错的功能。 import boardimport digitalio import time dt = digitalio.DigitalInOut(board.GP0) clk = digitalio.DigitalInOut(board.GP1) dt.switch_to_input() clk.switch_to_input() dt_last_value = 0 clk_last_value = 0 count = 0 start_sign = 0 clockwise_sign = 0 while True: if dt.value != dt_last_value or clk.value != clk_last_value: dt_last_value = int(dt.value) clk_last_value = int(clk.value) print((dt_last_value,clk_last_value)) if start_sign == 0 and (dt_last_value,clk_last_value) == (0,0): start_sign = 1 elif start_sign == 1: if (dt_last_value,clk_last_value) == (1, 0): clockwise_sign = 1 elif (dt_last_value,clk_last_value) == (0, 1): clockwise_sign = -1 elif (dt_last_value,clk_last_value) == (1, 1): count = count + clockwise_sign clockwise_sign = 0 start_sign = 0 print('--',count,'--')
import board encoder = rotaryio.IncrementalEncoder(board.GP0,board.GP1) last_position = 0 while True: position = encoder.position if position != last_position: print(position) last_position = position BPI-PicoW-S3 + CircuitPython 教程聚合链接:https://forum.banana-pi.org.cn/t/topic/3986?u=wind_ BPI-PicoW-S3 wiki 页面:https://wiki.banana-pi.org/BPI-PicoW-S3 购买BPI-PicoW-S3:
|
© 2013-2024 Comsenz Inc. Powered by Discuz! X3.4 Licensed