-
Notifications
You must be signed in to change notification settings - Fork 0
/
laikrodis.py
67 lines (46 loc) · 1.27 KB
/
laikrodis.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
import RPi.GPIO as GPIO
import time
from datetime import datetime
from astral import Astral
# 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11
outputs = [2, 3, 4, 14, 15, 17, 18, 27, 22, 23, 24, 10]
borderLamps = 19
GPIO.setmode(GPIO.BCM)
GPIO.setup(outputs, GPIO.OUT)
GPIO.setup(borderLamps, GPIO.OUT)
def show_time_v1():
while True:
hour = datetime.now().hour
a = Astral()
a.solar_depression = 'civil'
sun = a['Vilnius'].sun(date=datetime.now(), local=True)
sunrise = sun['sunrise'].time().hour + 0
sunset = sun['sunset'].time().hour - 0
if(hour<=sunrise or hour>=sunset):
GPIO.output(borderLamps, GPIO.HIGH)
if hour > 12:
hour = hour - 12 - 1
elif hour > 0:
hour = hour - 1
else:
hour = 11
for output in outputs:
GPIO.output(output, GPIO.LOW)
GPIO.output(outputs[hour], GPIO.HIGH)
print("Lamp (0..11): " + str(hour) )
else:
GPIO.output(borderLamps, GPIO.LOW)
for output in outputs:
GPIO.output(output, GPIO.LOW)
print("Turned OFF. Sunrise: " + str(sunrise) + " Sunset: " + str(sunset))
time.sleep(3)
def test():
while True:
for output in outputs:
GPIO.output(output, GPIO.HIGH)
time.sleep(0.1)
for output in outputs:
GPIO.output(output, GPIO.LOW)
time.sleep(0.1)
show_time_v1()
#test()