差别
这里会显示出您选择的修订版和当前版本之间的差别。
两侧同时换到之前的修订记录 前一修订版 | |||
rotaryencoder [2023/07/25 09:50] zhangzuhao [示例] |
rotaryencoder [2023/07/25 09:52] (当前版本) zhangzuhao |
||
---|---|---|---|
行 78: | 行 78: | ||
5. Amazon: https://www.amazon.com/ | 5. Amazon: https://www.amazon.com/ | ||
======示例====== | ======示例====== | ||
- | |||
- | from encoder import Encoder | ||
- | from machine import Pin ,PwM, SPI | ||
- | |||
- | from ssd1306 import SSD1306_SPI | ||
- | |||
- | |||
- | from sprite import DataDisplayScreen | ||
- | |||
- | from EC11 import EC11 | ||
- | |||
- | led0 = PwM(Pin(16),freq = 200000,duty = 0) | ||
- | |||
- | led1 = PwM(Pin(17),freq = 200000,duty = 0) | ||
- | |||
- | # 。Pin1(GND):一个接地引脚。 | ||
- | |||
- | # . Pin2(vcC):与3.3V或5V一起工作的正电压电源引脚。 | ||
- | |||
- | # . Pin3(sW):这是低电平有效按钮开关。按下旋钮后,电压将为低。 | ||
- | |||
- | # 。DT (Output B):类似于时钟输出,但是它以90°相移滞后时钟。所以,这个输出可以用来决定旋转的方向。 | ||
- | |||
- | # 。CLK (Output-A):这是主输出信号,用于确定旋转量。每次,编码器中的旋钮都会通过一个棘爪向任何方向转动。"CLK'的输出将经历一个高周期&之后的低周期。 | ||
- | |||
- | e = Encoder(0,1,Pin.PULL_UP ,max_val=10000,min_val=-10000) | ||
- | |||
- | eButton = Pin(13,Pin.IN,pull = Pin.PULL_uP) | ||
- | |||
- | |||
- | # 初始化spi总线 | ||
- | |||
- | # 初始化oled显示 | ||
- | |||
- | spi = SPI(1, 100000, mosi=Pin(pin_cfg.spi1_mosi), sck=Pin(pin_cfg.spi1_sck)) | ||
- | |||
- | oled = SSD1306_SPI(128, 64, spi, Pin(pin_cfg.spi1_dc),Pin(pin_cfg.spi1_rstn), Pin(pin_cfg.spi1_cs)) | ||
- | |||
- | |||
- | dds1 = DataDisplayScreen(y = 40,delta = 1,height = 0.5) | ||
- | |||
- | def show( ): | ||
- | |||
- | dds1.draw(display) | ||
- | | ||
- | display.show() | ||
- | | ||
- | value = 0 | ||
- | |||
- | while True: | ||
- | |||
- | display.fil1(0) | ||
- | | ||
- | # if e.value < value: | ||
- | |||
- | # print( '---') | ||
- | |||
- | display.text(str(e.value) ,0,0) | ||
- | | ||
- | if not eButton.value(): | ||
- | | ||
- | display.text("Button" ,0,8) | ||
- | | ||
- | dds1re.value | ||
- | | ||
- | value = e.value | ||
- | | ||
- | # dds2+ea.value() | ||
- | |||
- | show() | ||
- | '' | ||