Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # bombe.py
- import RPi.GPIO as GPIO
- from time import sleep
- from random import randint
- import subprocess
- draht1 =
- draht2 =
- draht3 =
- kontrollstrom =
- nebel =
- pause = 1
- motor =
- countdown = 7200
- LCD_WIDTH = 16
- LCD_LINE_1 = 0x80
- LCD_LINE_2 = 0xC0
- LCD_CHR = True
- LCD_CMD = False
- E_PULSE = 0.00005
- E_DELAY = 0.00005
- pause = 1
- GPIO.cleanup()
- GPIO.setmode(GPIO.BCM)
- GPIO.setup(draht1, GPIO.IN)
- GPIO.setup(draht2, GPIO.IN)
- GPIO.setup(draht3, GPIO.IN)
- GPIO.setup(blinkled, GPIO.OUT)
- GPIO.setup(nebel, GPIO.OUT)
- GPIO.setup(motor, GPIO.OUT)
- GPIO.setup(kontrollstrom, GPIO.IN)
- GPIO.setup(LCD_E, GPIO.OUT)
- GPIO.setup(LCD_RS, GPIO.OUT)
- GPIO.setup(LCD_D4, GPIO.OUT)
- GPIO.setup(LCD_D5, GPIO.OUT)
- GPIO.setup(LCD_D6, GPIO.OUT)
- GPIO.setup(LCD_D7, GPIO.OUT)
- def lcd_enable():
- sleep(E_DELAY)
- GPIO.output(LCD_E, True)
- sleep(E_PULSE)
- GPIO.output(LCD_E, False)
- sleep(E_DELAY)
- def lcd_string(message):
- message = message.ljust(LCD_WIDTH," ")
- for i in range(LCD_WIDTH):
- lcd_byte(ord(message[i]),LCD_CHR)
- LCD_INIT = [0x33, 0x32, 0x28, 0x0C, 0x06, 0x01]
- for i in LCD_INIT:
- lcd_byte(i,LCD_CMD)
- time.sleep(0.01)
- def lcd_byte(bits, mode):
- GPIO.output(LCD_RS, mode)
- GPIO.output(LCD_D4, bits&0x10==0x10)
- GPIO.output(LCD_D5, bits&0x20==0x20)
- GPIO.output(LCD_D6, bits&0x40==0x40)
- GPIO.output(LCD_D7, bits&0x80==0x80)
- lcd_enable()
- GPIO.output(LCD_D4, bits&0x01==0x01)
- GPIO.output(LCD_D5, bits&0x02==0x02)
- GPIO.output(LCD_D6, bits&0x04==0x04)
- GPIO.output(LCD_D7, bits&0x08==0x08)
- lcd_enable()
- while GPIO.input(kontrollstrom) == True:
- lcd_byte(LCD_LINE_1, LCD_CMD)
- lcd_string("Das ist eine Bombe")
- lcd_byte(LCD_LINE_2, LCD_CMD)
- lcd_string(str(countdown))
- if !(GPIO.input(draht1)==True & GPIO.input(draht2)==True & GPIO.input(draht3)==True):
- if countdown >> 600:
- countdown = 600
- pause = 0.5
- if GPIO.input(draht1)==True ^ GPIO.input(draht2)==True ^ GPIO.input(draht3)==True:
- b = randint(1,2)
- if b == 1:
- GPIO.output(nebel, True)
- else:
- GPIO.output(motor, True)
- sleep(10)
- GPIO.output(motor, False)
- if GPIO.input(draht1)==False & GPIO.input(draht2)==False & GPIO.input(draht3)==False:
- GPIO.output(motor, True)
- sleep(10)
- GPIO.output(motor, False)
- sleep(pause)
- countdown = countdown - 1
- GPIO.output(motor, True)
- sleep(10)
- GPIO.output(motor, False)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement