Skip to content

Instantly share code, notes, and snippets.

@Rumidom
Last active November 5, 2024 01:11
Show Gist options
  • Select an option

  • Save Rumidom/3f7ff00435322fa159e4a4f1e9080f6b to your computer and use it in GitHub Desktop.

Select an option

Save Rumidom/3f7ff00435322fa159e4a4f1e9080f6b to your computer and use it in GitHub Desktop.
rotary test.py
from machine import Pin
rotaryA = Pin(3, Pin.IN, Pin.PULL_UP)
rotaryB = Pin(4, Pin.IN, Pin.PULL_UP)
i = 0
Aflag = False
Bflag = False
dirflag = False
def rotaryA_interrupt(pin):
global i
global dirflag
global Bflag
bread = rotaryB.value()
if rotaryB.value():
dirflag = True
else:
dirflag = False
if Bflag:
if dirflag:
i += 1
else:
i -= 1
Bflag = False
print(i)
def rotaryB_interrupt(pin):
global Bflag
Bflag = True
rotaryA.irq(trigger=Pin.IRQ_RISING, handler=rotaryA_interrupt)
rotaryB.irq(trigger=Pin.IRQ_FALLING, handler=rotaryB_interrupt)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment