Last active
November 5, 2024 01:11
-
-
Save Rumidom/3f7ff00435322fa159e4a4f1e9080f6b to your computer and use it in GitHub Desktop.
rotary test.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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