Skip to content

Commit 7a13ae2

Browse files
committed
adds cleanup after interrupt
1 parent ecdd475 commit 7a13ae2

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

mcp3008/adafruit_mcp3008.py

+9-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,8 @@ def readadc(adcnum, clockpin, mosipin, misopin, cspin):
6767
readings = []
6868
average = 0
6969

70-
while True:
70+
try:
71+
while True:
7172
trim_pot = readadc(potentiometer_adc, SPICLK, SPIMOSI, SPIMISO, SPICS) # read the analog pin
7273

7374
pot_adjust = abs(trim_pot - last_read) # how much has it changed since the last read?
@@ -95,3 +96,10 @@ def readadc(adcnum, clockpin, mosipin, misopin, cspin):
9596
readings = []
9697
# hang out and do nothing for a half second
9798
time.sleep(0.0005)
99+
except KeyboardInterrupt:
100+
print "Interrupted"
101+
except Exception as error:
102+
print "Other error or exception occurred \n", str(error)
103+
finally:
104+
print "Running GPIO.cleanup()"
105+
GPIO.cleanup()

0 commit comments

Comments
 (0)