-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclockbrightness.py
91 lines (72 loc) · 1.88 KB
/
clockbrightness.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
87
88
89
90
91
import time
import board
import busio
import adafruit_tsl2591
import RPi.GPIO as GPIO
import subprocess
#import os
# Initialize the I2C bus.
i2c = busio.I2C(board.SCL, board.SDA)
#GPIO.setup(18, GPIO.OUT) # Set GPIO pin 12 to output mode.
#pwm = GPIO.PWM(18, 90) # Initialize PWM on pwmPin 100Hz frequency2C(board.SCL, board.SDA)
#pwm.start(100) #Start the PWM at 100%
# Initialize the sensor.
sensor = adafruit_tsl2591.TSL2591(i2c)
#maxBrightness = 100
#bedBrightness = 10
#minBrightness = 2
brightness = "NULL"
lightsOn = 200000
lightsBed = 100000
lightsOff = 10000
smooth1 = 0
smooth2 = 0
smooth3 = 0
smoothed = 0
def checkBrightness():
temp = 0
temp = sensor.visible
print("Temp: ",temp)
if temp > lightsOn:
temp = lightsOn
# if temp > lightsOn:
# return lightsOn
# elif temp < lightsOn and temp > lightsOff:
# return lightsBed
# elif temp < lightsOff:
# return lightsOff
return temp
while True:
i = 0
smoothed = 0
while i < 3:
print (i)
i += 1
smoothed = smoothed + checkBrightness()
# smooth1 = sensor.visible
print("Smooth",i,": ",smoothed)
time.sleep(1)
# smoothed = smoothed + checkBrightness()
# smooth2 = sensor.visible + smooth1
# print("Smooth2: ",smoothed)
# time.sleep(5)
# smoothed = smoothed + checkBrightness()
# smooth3 = sensor.visible + smooth2
# print("Smooth3: ",smoothed)
reading = smoothed//3
print("Reading: ",reading)
if reading >= lightsOn:
brightness="High"
elif reading < lightsOn and reading > lightsOff:
brightness="Med"
elif reading < lightsOff:
brightness="Low"
print("Brightness: ",brightness)
str1 = "/bin/echo " + brightness + " > /tmp/brightness"
print("Command: ", str1)
output = subprocess.call(str1, shell=True)
# with open('/tmp/brightness', 'w') as file:
# file.write(brightness)
# file.write("\n")
# file.close()
time.sleep(1)