-
Notifications
You must be signed in to change notification settings - Fork 0
/
job.py
54 lines (39 loc) · 1.26 KB
/
job.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import RPi.GPIO as GPIO
from os.path import exists
import sys
import json
import time
# -----------------------------------------
# ----------------------------------------- DEFINE PINS
# -----------------------------------------
ledPin = 16 # GPIO 23
btnPin = 12 # GPIO 18
# -----------------------------------------
# ----------------------------------------- FUNCTIONS
# -----------------------------------------
# cleanup GPIO pins && exit script with defined error code
def exitSave(exitCode = 0):
GPIO.cleanup()
sys.exit(exitCode)
# setup GPIO pins
def configureGPIO():
GPIO.setwarnings(False)
GPIO.setmode(GPIO.BOARD)
# configure led
GPIO.setup(ledPin, GPIO.OUT)
# configure button
GPIO.setup(btnPin, GPIO.IN)
# -----------------------------------------
# ----------------------------------------- SCRIPT
# -----------------------------------------
configureGPIO()
lastState = GPIO.input(btnPin)
GPIO.output(ledPin, lastState)
while True:
currentState = GPIO.input(btnPin)
if(lastState != currentState):
lastState = currentState
# if the switch is on, red led indicates the device is armed
GPIO.output(ledPin, currentState)
time.sleep(0.1)
exitSave()