aboutsummaryrefslogtreecommitdiffstats
path: root/System/test_Motor.py
diff options
context:
space:
mode:
authorRaspberry Pi <raspberrypi@umn.edu>2019-12-02 20:27:29 -0600
committerRaspberry Pi <raspberrypi@umn.edu>2019-12-02 20:27:29 -0600
commit0fe6f542246dd150b4793df18253ed6d4a443264 (patch)
tree254849abf6bb3be93bb67380d519363fbd957546 /System/test_Motor.py
parentMinor tweaks to PI.py to get working seamlessly with web server - tested and ... (diff)
downloadee4511w-0fe6f542246dd150b4793df18253ed6d4a443264.tar
ee4511w-0fe6f542246dd150b4793df18253ed6d4a443264.tar.gz
ee4511w-0fe6f542246dd150b4793df18253ed6d4a443264.tar.bz2
ee4511w-0fe6f542246dd150b4793df18253ed6d4a443264.tar.lz
ee4511w-0fe6f542246dd150b4793df18253ed6d4a443264.tar.xz
ee4511w-0fe6f542246dd150b4793df18253ed6d4a443264.tar.zst
ee4511w-0fe6f542246dd150b4793df18253ed6d4a443264.zip
Update test files to do GPIO cleanup on completion (ex: encoders don't work if GPIO.cleanup is not performed). Add system destructor and add GPIO.cleanup to that too. Everything appears to be working still.
Diffstat (limited to 'System/test_Motor.py')
-rwxr-xr-xSystem/test_Motor.py28
1 files changed, 17 insertions, 11 deletions
diff --git a/System/test_Motor.py b/System/test_Motor.py
index 80cff1e..f48b6ee 100755
--- a/System/test_Motor.py
+++ b/System/test_Motor.py
@@ -1,5 +1,6 @@
from motor import Motor
import time
+import RPi.GPIO as GPIO
# Decide which pins to hook up to on the Pi before running
speed_pin = 17
@@ -10,14 +11,19 @@ m = Motor(speed_pin, forward_pin, reverse_pin)
dir = 'ascending'
speed = 0.0
-while 1:
- if speed >= 15.0:
- dir = 'descending'
- elif speed <= -15.0:
- dir = 'ascending'
- if dir == 'ascending':
- speed = speed + 2.0
- else:
- speed = speed - 2.0
- m.move(speed)
- time.sleep(0.1) \ No newline at end of file
+try:
+ while 1:
+ if speed >= 15.0:
+ dir = 'descending'
+ elif speed <= -15.0:
+ dir = 'ascending'
+ if dir == 'ascending':
+ speed = speed + 2.0
+ else:
+ speed = speed - 2.0
+ m.move(speed)
+ time.sleep(0.1)
+except:
+ print("Program killed by Ctrl-C")
+finally:
+ GPIO.cleanup() \ No newline at end of file