Advertisement
Guest User

Untitled

a guest
Aug 20th, 2018
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.52 KB | None | 0 0
  1. # bombe.py
  2. import RPi.GPIO as GPIO
  3. from time import sleep
  4. from random import randint
  5. import subprocess
  6.  
  7.  
  8. draht1 =
  9. draht2 =
  10. draht3 =
  11. kontrollstrom =
  12. nebel =
  13. pause = 1
  14. motor =
  15. countdown = 7200
  16. LCD_WIDTH = 16
  17. LCD_LINE_1 = 0x80
  18. LCD_LINE_2 = 0xC0
  19. LCD_CHR = True
  20. LCD_CMD = False
  21. E_PULSE = 0.00005
  22. E_DELAY = 0.00005
  23. pause = 1
  24.  
  25. GPIO.cleanup()
  26. GPIO.setmode(GPIO.BCM)
  27. GPIO.setup(draht1, GPIO.IN)
  28. GPIO.setup(draht2, GPIO.IN)
  29. GPIO.setup(draht3, GPIO.IN)
  30. GPIO.setup(blinkled, GPIO.OUT)
  31. GPIO.setup(nebel, GPIO.OUT)
  32. GPIO.setup(motor, GPIO.OUT)
  33. GPIO.setup(kontrollstrom, GPIO.IN)
  34. GPIO.setup(LCD_E, GPIO.OUT)
  35. GPIO.setup(LCD_RS, GPIO.OUT)
  36. GPIO.setup(LCD_D4, GPIO.OUT)
  37. GPIO.setup(LCD_D5, GPIO.OUT)
  38. GPIO.setup(LCD_D6, GPIO.OUT)
  39. GPIO.setup(LCD_D7, GPIO.OUT)
  40.  
  41. def lcd_enable():
  42. sleep(E_DELAY)
  43. GPIO.output(LCD_E, True)
  44. sleep(E_PULSE)
  45. GPIO.output(LCD_E, False)
  46. sleep(E_DELAY)
  47.  
  48. def lcd_string(message):
  49. message = message.ljust(LCD_WIDTH," ")
  50. for i in range(LCD_WIDTH):
  51. lcd_byte(ord(message[i]),LCD_CHR)
  52.  
  53. LCD_INIT = [0x33, 0x32, 0x28, 0x0C, 0x06, 0x01]
  54. for i in LCD_INIT:
  55. lcd_byte(i,LCD_CMD)
  56. time.sleep(0.01)
  57.  
  58. def lcd_byte(bits, mode):
  59. GPIO.output(LCD_RS, mode)
  60. GPIO.output(LCD_D4, bits&0x10==0x10)
  61. GPIO.output(LCD_D5, bits&0x20==0x20)
  62. GPIO.output(LCD_D6, bits&0x40==0x40)
  63. GPIO.output(LCD_D7, bits&0x80==0x80)
  64. lcd_enable()
  65. GPIO.output(LCD_D4, bits&0x01==0x01)
  66. GPIO.output(LCD_D5, bits&0x02==0x02)
  67. GPIO.output(LCD_D6, bits&0x04==0x04)
  68. GPIO.output(LCD_D7, bits&0x08==0x08)
  69. lcd_enable()
  70.  
  71. while GPIO.input(kontrollstrom) == True:
  72. lcd_byte(LCD_LINE_1, LCD_CMD)
  73. lcd_string("Das ist eine Bombe")
  74. lcd_byte(LCD_LINE_2, LCD_CMD)
  75. lcd_string(str(countdown))
  76. if !(GPIO.input(draht1)==True & GPIO.input(draht2)==True & GPIO.input(draht3)==True):
  77. if countdown >> 600:
  78. countdown = 600
  79. pause = 0.5
  80.  
  81. if GPIO.input(draht1)==True ^ GPIO.input(draht2)==True ^ GPIO.input(draht3)==True:
  82. b = randint(1,2)
  83. if b == 1:
  84. GPIO.output(nebel, True)
  85. else:
  86. GPIO.output(motor, True)
  87. sleep(10)
  88. GPIO.output(motor, False)
  89.  
  90. if GPIO.input(draht1)==False & GPIO.input(draht2)==False & GPIO.input(draht3)==False:
  91. GPIO.output(motor, True)
  92. sleep(10)
  93. GPIO.output(motor, False)
  94. sleep(pause)
  95. countdown = countdown - 1
  96.  
  97.  
  98. GPIO.output(motor, True)
  99. sleep(10)
  100. GPIO.output(motor, False)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement