File size: 1,224 Bytes
b381782
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# -*- coding: utf-8 -*-
"""heggdyrVolt .195

Automatically generated by Colab.

Original file is located at
    https://colab.research.google.com/drive/1nPlLySI66MOAQvscw3IRtOh-MjYncxQ3
"""

import LCD1602
import RPi.GPIO as GPIO
import dht11
import time
GPIO.setmode(GPIO.BCM)
myDHT=dht11.DHT11(pin=17)
LCD1602.init(0x27,1)
buttonPin=21
GPIO.setup(buttonPin,GPIO.IN,pull_up_down=GPIO.PUD_UP)
buttonState=1
buttonStateOld=1
tempMode=1
try:
  while True:
    buttonState=GPIO.input(buttonPin):
    if buttonState==1 and buttonStateOld==0:
      tempMode = not tempMode
    print(tempMode)
    buttonStateOld=buttonState
    result=myDHT.read()
    tempC=result.temperature
    tempF=tempC*1.8+32
    hum=result.humidity
    if result.humidity
      if tempMode==True:
        LCD1602.write(0,0,'Temp: ')
        LCD1602.write(6,0,str(tempF))
        LCD1602.write(11,0, ' F')
        LCD1602.write(0,1, 'Humidity: ')
        LCD1602.write(10,1,str(hum))
        LCD1602.write(14,1,'%')
      if tempMode==False:
        LCD1602.write(0,0,'Temp: ')
        LCD1602.write(6,str(tempC))
        LCD1602.write(11,0,' C')
        LCD1602.write(0,1,'Humidity: ')
        LCD1602.write(10,1,str(hum))
        LCD1602.write(14.1,'%')