Guest User

Untitled

a guest
Oct 18th, 2018
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.16 KB | None | 0 0
  1. #Raspberry Pi Alarmsysteem v1.0
  2. #Groepsproject CSN 2018 - Arjen, Julian, Ruben, Tom
  3.  
  4.  
  5. #Importing the modules we need.
  6. import time
  7. import RPi.GPIO as GPIO
  8.  
  9. #Assigning our global variables.
  10. LEDgrn = 17
  11. LEDred = 18
  12. ButTop = 6
  13. ButBot = 12
  14. thisPiReady = False
  15. thisPiListen = False
  16. thisPiTestAlarm = False
  17. thisPiAlarm = False
  18. otherPiReady = False
  19. otherPiListen = False
  20. otherPiAlarm = False
  21.  
  22. #Assigning the GPIO pins on the Raspberry Pi.
  23. GPIO.setwarnings(False) #We don't want to be notified of pin assignment conflicts.
  24. GPIO.setmode(GPIO.BCM)
  25. GPIO.setup(LEDgrn, GPIO.OUT)
  26. GPIO.setup(LEDred, GPIO.OUT)
  27. GPIO.setup(ButTop, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
  28. GPIO.setup(ButBot, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
  29.  
  30. #Defining all the functions we need.
  31. #First, we define our "sub-functions". These will be used inside of our main functions.
  32.  
  33.  
  34. #Next, we define our main functions.
  35. def piReady():
  36. # 'Function for the Raspberry Pi "ready-mode".'
  37. while True:
  38. GPIO.output(LEDgrn, 1)
  39. if otherPiListen == True:
  40. piListen()
  41. elif GPIO.input(ButTop) == 1:
  42. thisPiReady = False
  43. thisPiListen = True
  44. GPIO.output(LEDgrn, 0)
  45. break
  46. elif GPIO.input(ButBot) == 1:
  47. GPIO.output(LEDgrn, 0)
  48. break
  49. else:
  50. time.sleep(.1)
  51. continue
  52.  
  53. def piListen():
  54. # 'Function for the Raspberry Pi "listen-mode".'
  55. while True:
  56. GPIO.output(LEDgrn, 1)
  57. time.sleep(.5)
  58. GPIO.output(LEDgrn, 0)
  59. if otherPiAlarm == True:
  60. thisPiListen = False
  61. thisPiAlarm = True
  62. break
  63. elif GPIO.input(ButTop):
  64. thisPiListen = False
  65. thisPiReady = True
  66. GPIO.output(LEDgrn, 0)
  67. break
  68. elif GPIO.input(ButBot):
  69. thisPiListen = False
  70. thisPiTestAlarm = True
  71. GPIO.output(LEDgrn, 0)
  72. break
  73. else:
  74. continue
  75.  
  76. def piTestAlarm():
  77. # 'Function for the Raspberry Pi "test_alarm-mode".'
  78. alarmTimeOut = 0
  79. GPIO.output(LEDgrn, 0)
  80. GPIO.output(LEDred, 1)
  81. while True:
  82. if GPIO.input(ButTop):
  83. thisPiTestAlarm = False
  84. thisPiListen = True
  85. break
  86. elif alarmTimeOut >= 5:
  87. thisPiTestAlarm = False
  88. thisPiAlarm = True
  89. break
  90. else:
  91. alarmTimeOut += 1
  92.  
  93. def piAlarm():
  94. # 'Function for the Raspberry Pi "alarm-mode".'
  95. while True:
  96. GPIO.output(LEDred, 1)
  97. time.sleep(.25)
  98. GPIO.output(LEDred, 0)
  99. if GPIO.input(ButTop):
  100. thisPiAlarm = False
  101. thisPiListen = True
  102. break
  103. else:
  104. continue
  105.  
  106. #Start code
  107. thisPiReady = True
  108. try:
  109. while True:
  110. if thisPiReady == True:
  111. piReady()
  112. elif thisPiListen == True:
  113. #Sent thisPiListen = True over network.
  114. piListen()
  115. elif thisPiTestAlarm == True:
  116. piTestAlarm()
  117. elif thisPiAlarm == True:
  118. #Sent thisPiAlarm = True over network.
  119. piAlarm()
  120. else:
  121. time.sleep(.1)
  122. continue
  123.  
  124. except KeyboardInterrupt:
  125. GPIO.cleanup()
Add Comment
Please, Sign In to add comment