Last active
August 29, 2015 13:56
-
-
Save pdp7/9183145 to your computer and use it in GitHub Desktop.
bbb rotary encoder in python
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
https://github.com/guyc/py-gaugette | |
# pip install wiringpi | |
http://www.alexanderhiam.com/wp-content/uploads/2013/01/beaglebone_pinout1.png | |
https://github.com/adafruit/adafruit-beaglebone-io-python/blob/master/source/common.c | |
root@beaglebone:~/py-gaugette/samples# export PYTHONPATH=$PYTHONPATH:~/py-gaugette | |
root@beaglebone:~/py-gaugette/samples# nice -n -10 rtl_fm -f 91.5e6 -M wbfm -r 48000 - | aplay -r 48k -f S16_LE | |
root@beaglebone:~/py-gaugette/gaugette# git diff | |
diff --git a/gaugette/switch.py b/gaugette/switch.py | |
index f57e3d5..cb61410 100755 | |
--- a/gaugette/switch.py | |
+++ b/gaugette/switch.py | |
@@ -1,24 +1,13 @@ | |
-import wiringpi2 | |
+import gaugette.gpio | |
+ | |
class Switch: | |
- def __init__(self, pin, pullUp=True): | |
+ def __init__(self, pin): | |
self.pin = pin | |
- self.pullUp = pullUp | |
- self.gpio = wiringpi2.GPIO(wiringpi2.GPIO.WPI_MODE_PINS) | |
- self.gpio.pinMode(self.pin, self.gpio.INPUT) | |
- if self.pullUp: | |
- self.gpio.pullUpDnControl(self.pin, self.gpio.PUD_UP) | |
- else: | |
- self.gpio.pullUpDnControl(self.pin, self.gpio.PUD_DOWN) | |
+ self.gpio = gaugette.gpio.GPIO() | |
+ self.gpio.setup(self.pin, self.gpio.IN, self.gpio.PUD_UP) | |
def get_state(self): | |
state = self.gpio.digitalRead(self.pin) | |
- if self.pullUp: | |
- # If we are pulling up and switching | |
- # to ground, state will be 1 when the switch is open, and 0 | |
- # when it is closed. We invert the value here to a more | |
- # conventional representation of 0:open, 1:closed. | |
- return 1-state | |
- else: | |
- return state | |
+ return 1-state |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment