-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtemp_logger.py
More file actions
94 lines (78 loc) · 2.03 KB
/
temp_logger.py
File metadata and controls
94 lines (78 loc) · 2.03 KB
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
__author__ = 'netwokz'
# Raspberry Pi Temperature Logger Stephen M Deane Jr
# www.thepowerofpi.com 6/5/2015
import time
import datetime
import weather
import Adafruit_CharLCD as LCD
import RPi.GPIO as io
# Raspberry Pi pin configuration:
lcd_rs = 27
lcd_en = 22
lcd_d4 = 25
lcd_d5 = 24
lcd_d6 = 23
lcd_d7 = 18
lcd_backlight = 4 # Currently not used
doorSwitch = 12
relayPin = 16
# Define LCD column and row size for 16x2 LCD.
lcd_columns = 16
lcd_rows = 2
# String Templates
mTemp = "Temperature: "
mHum = "Humidity: "
# Button Setup
io.setmode(io.BCM)
io.setup(20, io.IN, pull_up_down=io.PUD_UP)
io.setup(21, io.IN, pull_up_down=io.PUD_UP)
io.setup(doorSwitch,io.IN,pull_up_down=io.PUD_UP)
io.setup(relayPin, io.OUT)
isGarageClosed = False
mLastView = 0 # 0 = temp, 1 = Garage
# Initialize the LCD using the pins above.
lcd = LCD.Adafruit_CharLCD(lcd_rs, lcd_en, lcd_d4, lcd_d5, lcd_d6, lcd_d7, lcd_columns, lcd_rows, lcd_backlight)
def temperature():
temp = weather.return_weather()
return temp
def showTemp():
outvalue = temperature()
lcd.clear()
lcd.message(mTemp + str(outvalue[0]) + "F \n" + mHum + str(outvalue[1]) + "% ")
mLastView = 0
def showGarage():
activateGarage()
lcd.clear()
mClosed = "Closed"
mOpen = "Open"
garage = ""
if isGarageClosed == True:
garage = "Garage is Closed"
else:
garage = "Garage is Open"
lcd.message(garage)
mLastView = 1
def showView():
if mLastView == 0:
showTemp()
elif mLastView == 1:
showGarage()
def activateGarage():
io.output(relayPin, 0)
time.sleep(1)
io.output(relayPin, 1)
try:
while True:
temp = io.input(20)
garage = io.input(21)
if temp == False:
showTemp()
elif garage == False:
showGarage()
if io.input(doorSwitch):
isGarageClosed = False
else:
isGarageClosed = True
#showView()
except KeyboardInterrupt:
lcd.clear()