Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #Raspberry Pi Alarmsysteem v1.0
- #Groepsproject CSN 2018 - Arjen, Julian, Ruben, Tom
- #Importing the modules we need.
- import time
- import RPi.GPIO as GPIO
- #Assigning our global variables.
- LEDgrn = 17
- LEDred = 18
- ButTop = 6
- ButBot = 12
- thisPiReady = False
- thisPiListen = False
- thisPiTestAlarm = False
- thisPiAlarm = False
- otherPiReady = False
- otherPiListen = False
- otherPiAlarm = False
- #Assigning the GPIO pins on the Raspberry Pi.
- GPIO.setwarnings(False) #We don't want to be notified of pin assignment conflicts.
- GPIO.setmode(GPIO.BCM)
- GPIO.setup(LEDgrn, GPIO.OUT)
- GPIO.setup(LEDred, GPIO.OUT)
- GPIO.setup(ButTop, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
- GPIO.setup(ButBot, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
- #Defining all the functions we need.
- #First, we define our "sub-functions". These will be used inside of our main functions.
- #Next, we define our main functions.
- def piReady():
- # 'Function for the Raspberry Pi "ready-mode".'
- while True:
- GPIO.output(LEDgrn, 1)
- if otherPiListen == True:
- piListen()
- elif GPIO.input(ButTop) == 1:
- thisPiReady = False
- thisPiListen = True
- GPIO.output(LEDgrn, 0)
- break
- elif GPIO.input(ButBot) == 1:
- GPIO.output(LEDgrn, 0)
- break
- else:
- time.sleep(.1)
- continue
- def piListen():
- # 'Function for the Raspberry Pi "listen-mode".'
- while True:
- GPIO.output(LEDgrn, 1)
- time.sleep(.5)
- GPIO.output(LEDgrn, 0)
- if otherPiAlarm == True:
- thisPiListen = False
- thisPiAlarm = True
- break
- elif GPIO.input(ButTop):
- thisPiListen = False
- thisPiReady = True
- GPIO.output(LEDgrn, 0)
- break
- elif GPIO.input(ButBot):
- thisPiListen = False
- thisPiTestAlarm = True
- GPIO.output(LEDgrn, 0)
- break
- else:
- continue
- def piTestAlarm():
- # 'Function for the Raspberry Pi "test_alarm-mode".'
- alarmTimeOut = 0
- GPIO.output(LEDgrn, 0)
- GPIO.output(LEDred, 1)
- while True:
- if GPIO.input(ButTop):
- thisPiTestAlarm = False
- thisPiListen = True
- break
- elif alarmTimeOut >= 5:
- thisPiTestAlarm = False
- thisPiAlarm = True
- break
- else:
- alarmTimeOut += 1
- def piAlarm():
- # 'Function for the Raspberry Pi "alarm-mode".'
- while True:
- GPIO.output(LEDred, 1)
- time.sleep(.25)
- GPIO.output(LEDred, 0)
- if GPIO.input(ButTop):
- thisPiAlarm = False
- thisPiListen = True
- break
- else:
- continue
- #Start code
- thisPiReady = True
- try:
- while True:
- if thisPiReady == True:
- piReady()
- elif thisPiListen == True:
- #Sent thisPiListen = True over network.
- piListen()
- elif thisPiTestAlarm == True:
- piTestAlarm()
- elif thisPiAlarm == True:
- #Sent thisPiAlarm = True over network.
- piAlarm()
- else:
- time.sleep(.1)
- continue
- except KeyboardInterrupt:
- GPIO.cleanup()
Add Comment
Please, Sign In to add comment