-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #37 from cpu20/master
Adding callback functionality to the rotary encoder
- Loading branch information
Showing
4 changed files
with
58 additions
and
1 deletion.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# Sample code for both the RotaryEncoder class and the Switch class. | ||
# The common pin for the encoder should be wired to ground. | ||
# The sw_pin should be shorted to ground by the switch. | ||
|
||
import time | ||
import gaugette.gpio | ||
import gaugette.rotary_encoder | ||
|
||
# Rotary encoder pins | ||
A_PIN = 23 | ||
B_PIN = 22 | ||
|
||
def rotated(direction): | ||
print("Rotated ", direction) | ||
|
||
gpio = gaugette.gpio.GPIO() | ||
encoder = gaugette.rotary_encoder.RotaryEncoder(gpio, A_PIN, B_PIN, rotated) | ||
encoder.start() | ||
|
||
while True: | ||
time.sleep(100) |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# Sample code for both the RotaryEncoder class and the Switch class. | ||
# The common pin for the encoder should be wired to ground. | ||
# The sw_pin should be shorted to ground by the switch. | ||
|
||
import time | ||
import gaugette.gpio | ||
import gaugette.switch | ||
|
||
SW_PIN = 21 | ||
|
||
def pushed(): | ||
print("Switch pushed!") | ||
|
||
gpio = gaugette.gpio.GPIO() | ||
sw = gaugette.switch.Switch(gpio, SW_PIN) | ||
# Calls pushed() on a falling edge | ||
sw.enable_isr(gpio.EDGE_FALLING, pushed) | ||
|
||
while True: | ||
time.sleep(100) |