-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNima_finalproject.py
86 lines (80 loc) · 2.74 KB
/
Nima_finalproject.py
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
import sys
import RPi.GPIO as GPIO
import Adafruit_CharLCD as LCD
from time import sleep
import time;
import pyowm
import socket
import requests
GPIO.setmode(GPIO.BCM)
GPIO.setup(22,GPIO.IN,pull_up_down=GPIO.PUD_UP) #BUTTON
onOff = 1
# instantiate lcd and specify pins
lcd = LCD.Adafruit_CharLCD(rs=26, en=19,d4=13, d5=6, d6=5, d7=11,cols=16, lines=2)
lcd.clear()
#WEATHER
owm = pyowm.OWM('e90bc58e09805e568513d0b6940275ab')
observation = owm.weather_at_place('Vancouver,ca')
lcd.clear()
lcd.message("Hi, Click me!")
try:
while True:
input_state = GPIO.input(22)
if input_state==False:
sleep(1)
if onOff == 1: #TIME AND DATE
for x in range(0, 16):
lcd.move_right()
sleep(.1)
lcd.clear()
for x in range(0, 16):
lcd.move_right()
ts = time.localtime()
theTime = (time.strftime("%Y-%m-%d\n%I:%M %p", ts))
lcd.message(theTime)
sleep(1)
for x in range(0, 16):
lcd.move_left()
sleep(.1)
print(onOff)
elif onOff == 2: #Weather
for x in range(0, 16):
lcd.move_right()
sleep(.1)
lcd.clear()
for x in range(0, 16):
lcd.move_right()
w = observation.get_weather()
wTemp = str(w.get_temperature('celsius'))
wTempArray = wTemp.split(",")
wTempMsg = wTempArray[0].strip("{}").replace("'", "")
wDetail = str(w.get_status())
wMsg = (wTempMsg.strip() +" C\n"+wDetail)
lcd.message(wMsg)
sleep(1)
for x in range(0, 16):
lcd.move_left()
sleep(.1)
print(onOff)
else: #IP-ADDRESSES
for x in range(0, 16):
lcd.move_right()
sleep(.1)
lcd.clear()
for x in range(0, 16):
lcd.move_right()
localIP = socket.gethostbyname(socket.gethostname())
globalIP = requests.get('http://ip.42.pl/raw').text
ip = (localIP + "\n" + globalIP)
lcd.message(ip)
sleep(1)
for x in range(0, 16):
lcd.move_left()
sleep(.1)
print(onOff)
onOff=0
onOff+=1
except KeyboardInterrupt:
GPIO.cleanup()
finally:
lcd.clear()