Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import I2C_LCD_driver
- import time
- import dht11
- import datetime
- import RPi.GPIO as GPIO
- from keypad import keypad
- GPIO.setwarnings(False)
- GPIO.setmode(GPIO.BOARD)
- mylcd = I2C_LCD_driver.lcd()
- instance = dht11.DHT11(pin=4)
- mode = 0
- select = 0
- refresh = True
- GPIO.setup(38, GPIO.OUT)
- GPIO.setup(40, GPIO.OUT)
- PIN_TRIGGER = 35
- PIN_ECHO = 37
- GPIO.setup(PIN_TRIGGER, GPIO.OUT)
- GPIO.setup(PIN_ECHO, GPIO.IN)
- if __name__ == '__main__':
- kp = keypad(columnCount = 3)
- GPIO.output(PIN_TRIGGER, GPIO.LOW)
- print("Waiting for sensor to settle")
- time.sleep(2)
- #
- mylcd.lcd_display_string("Press any key", 1)
- try:
- while True:
- digit = kp.getKey()
- result = instance.read()
- if mode==0:
- if digit != None or refresh == True:
- refresh = False
- # navigation
- if digit==2:
- select = select-1
- if select<0:
- select = 3
- time.sleep(0.3)
- if digit==8:
- select = select+1
- if select>3:
- select = 0
- time.sleep(0.3)
- if digit==5:
- mode = select+1
- select = 0
- continue
- #
- # menu
- mylcd.lcd_clear()
- if select==0:
- mylcd.lcd_display_string("-> Temperatura", 1)
- mylcd.lcd_display_string("Wilgotnosc", 2)
- if select==1:
- mylcd.lcd_display_string("-> Wilgotnosc", 1)
- mylcd.lcd_display_string("Tajne haslo", 2)
- if select==2:
- mylcd.lcd_display_string("-> Tajne haslo", 1)
- mylcd.lcd_display_string("Odleglosc", 2)
- if select==3:
- mylcd.lcd_display_string("-> Odleglosc", 1)
- mylcd.lcd_display_string("Temperatura", 2)
- #print("Last valid input: " + str(datetime.datetime.now()))
- #print("menu")
- if mode==1:
- if result.is_valid():
- mylcd.lcd_clear()
- mylcd.lcd_display_string("%-3.1f C" % result.temperature)
- time.sleep(0.5)
- if digit != None:
- if digit=="#":
- mode = 0
- if mode==2:
- if result.is_valid():
- mylcd.lcd_clear()
- mylcd.lcd_display_string("%-3.1f %%" % result.humidity)
- time.sleep(0.5)
- if digit != None:
- if digit=="#":
- mode = 0
- if mode==3:
- time.sleep(0.4)
- passwd = []
- for i in range(4):
- mylcd.lcd_clear()
- digit = None
- if i==0:
- mylcd.lcd_display_string("Pass: ", 1)
- if i==1:
- mylcd.lcd_display_string("Pass: *", 1)
- if i==2:
- mylcd.lcd_display_string("Pass: **", 1)
- if i==3:
- mylcd.lcd_display_string("Pass: ***", 1)
- while digit == None:
- digit = kp.getKey()
- if digit == "#":
- mode = 0
- refresh = True
- continue
- passwd.append(digit)
- time.sleep(0.4)
- mylcd.lcd_clear()
- if passwd == [1, 2, 3, 4]:
- GPIO.output(38, 1)
- mylcd.lcd_display_string("GOOD", 1)
- else:
- GPIO.output(40, 1)
- mylcd.lcd_display_string("HEHE NOPE!", 1)
- time.sleep(2)
- GPIO.output(38, 0)
- GPIO.output(40, 0)
- mode = 0
- refresh = True
- if mode==4:
- mylcd.lcd_clear()
- GPIO.output(PIN_TRIGGER, GPIO.HIGH)
- time.sleep(0.00001)
- GPIO.output(PIN_TRIGGER, GPIO.LOW)
- while GPIO.input(PIN_ECHO)==0:
- pulse_start_time = time.time()
- while GPIO.input(PIN_ECHO)==1:
- pulse_end_time = time.time()
- pulse_duration = pulse_end_time - pulse_start_time
- distance = str(round(pulse_duration * 17150, 2))
- mylcd.lcd_display_string(distance, 1)
- time.sleep(0.4)
- digit = kp.getKey()
- if digit == "#":
- mode = 0
- refresh = True
- continue
- except KeyboardInterrupt:
- print("Cleanup")
- GPIO.cleanup()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement