aboutsummaryrefslogtreecommitdiffstats
path: root/System/test_Encoder.py
diff options
context:
space:
mode:
Diffstat (limited to 'System/test_Encoder.py')
-rwxr-xr-xSystem/test_Encoder.py13
1 files changed, 10 insertions, 3 deletions
diff --git a/System/test_Encoder.py b/System/test_Encoder.py
index b667cc1..d0b7ef8 100755
--- a/System/test_Encoder.py
+++ b/System/test_Encoder.py
@@ -1,5 +1,6 @@
from encoder import Encoder
import time
+import RPi.GPIO as GPIO
# Decide which pins to hook up to on the Pi before running
clk_pin = 2
@@ -9,6 +10,12 @@ data_pin = 3
e = Encoder(clk_pin, cs_pin, data_pin)
e.set_zero()
-while(1):
- print(e.read_position('Degrees'))
- time.sleep(0.001) \ No newline at end of file
+try:
+ while(1):
+ print(e.read_position('Degrees'))
+ time.sleep(0.001)
+except:
+ print("Program killed by Ctrl-C")
+finally:
+ # Perform GPIO cleanup. Things may get weird otherwise...
+ GPIO.cleanup()