Added exit function
This commit is contained in:
parent
ccf7f710ec
commit
b5a3c17b57
1 changed files with 11 additions and 4 deletions
15
raspicar.py
15
raspicar.py
|
@ -1,4 +1,5 @@
|
||||||
import time
|
import time
|
||||||
|
import atexit
|
||||||
import board
|
import board
|
||||||
import RPi.GPIO as GPIO
|
import RPi.GPIO as GPIO
|
||||||
|
|
||||||
|
@ -29,6 +30,14 @@ def handlePushButton(button):
|
||||||
display.print(" :"+str(CHANNEL)+"-")
|
display.print(" :"+str(CHANNEL)+"-")
|
||||||
|
|
||||||
|
|
||||||
|
# On exit
|
||||||
|
def handleExit():
|
||||||
|
print("GoodBye!")
|
||||||
|
display.print("--:--")
|
||||||
|
sleep(2)
|
||||||
|
display.fill(0)
|
||||||
|
|
||||||
|
|
||||||
# Init program
|
# Init program
|
||||||
def init():
|
def init():
|
||||||
# Set display
|
# Set display
|
||||||
|
@ -114,12 +123,10 @@ def main():
|
||||||
time.sleep(10)
|
time.sleep(10)
|
||||||
|
|
||||||
|
|
||||||
|
atexit.register(handleExit)
|
||||||
|
|
||||||
if __name__ =='__main__':
|
if __name__ =='__main__':
|
||||||
try:
|
try:
|
||||||
main()
|
main()
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
display.print("--:--")
|
|
||||||
print("GoodBye!")
|
|
||||||
|
|
Loading…
Reference in a new issue