Skip to content
Snippets Groups Projects
Commit f539b655 authored by Jess Ward's avatar Jess Ward
Browse files

import from snapcast and set variables

parent ab96ad46
No related branches found
No related tags found
No related merge requests found
import RPi.GPIO as GPIO import RPi.GPIO as GPIO
import time import time
import snapcast.control import snapcast.control
from snapcast import get_snapcast_client
from snapcast import add_server
SENSOR_PIN = 7 SENSOR_PIN = 7
MUTE_BRIGHTNESS = 0.1
def dark_mute():
'''Runs measure_brightness and prints output'''
server = snapcast.control.Snapserver(add_server(),
snapcast.control.CONTROL_PORT)
client = get_snapcast_client(server)
GPIO.setmode(GPIO.BOARD)
try:
while True:
# TODO: track current state, don't send constant updates
brightness = measure_brightness(SENSOR_PIN)
if brightness < MUTE_BRIGHTNESS:
client.muted = True
else:
client.muted = False
except KeyboardInterrupt:
pass
finally:
GPIO.cleanup()
def measure_brightness(pin_to_circuit): def measure_brightness(pin_to_circuit):
...@@ -18,18 +41,7 @@ def measure_brightness(pin_to_circuit): ...@@ -18,18 +41,7 @@ def measure_brightness(pin_to_circuit):
while (GPIO.input(pin_to_circuit) == GPIO.LOW): while (GPIO.input(pin_to_circuit) == GPIO.LOW):
charge_time += 1 charge_time += 1
return 1/charge_time return 1000/charge_time
def dark_mute():
GPIO.setmode(GPIO.BOARD)
try:
while True:
print(measure_brightness(SENSOR_PIN))
except KeyboardInterrupt:
pass
finally:
GPIO.cleanup()
if __name__ == '__main__': if __name__ == '__main__':
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment