-
Notifications
You must be signed in to change notification settings - Fork 0
/
tv_controls.py
44 lines (35 loc) · 966 Bytes
/
tv_controls.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
import RPi.GPIO as GPIO
import time
from constants import *
GPIO.setmode(GPIO.BCM)
for i in range(len(inputs)):
GPIO.setup(inputs[i], GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.setup(outputs[i], GPIO.OUT)
def toggle_power():
GPIO.output(POWER_OUT, GPIO.LOW)
time.sleep(POWER_TOGGLE_INIT_SLEEP)
GPIO.output(POWER_OUT, GPIO.HIGH)
time.sleep(POWER_TOGGLE_INIT_SLEEP)
GPIO.output(POWER_OUT, GPIO.LOW)
time.sleep(POWER_TOGGLE_SLEEP)
GPIO.output(POWER_OUT, GPIO.HIGH)
def adjust_volume(volume_steps):
pin = VOLUME_UP_OUT
if volume_steps < 0:
pin = VOLUME_DOWN_OUT
volume_steps = abs(volume_steps)
GPIO.output(pin, GPIO.LOW)
time.sleep(INIT_SLEEP)
GPIO.output(pin, GPIO.HIGH)
time.sleep(INIT_SLEEP)
for i in range(volume_steps):
GPIO.output(pin, GPIO.LOW)
time.sleep(AFTER_SLEEP)
GPIO.output(pin, GPIO.HIGH)
if i % 5 == 0:
time.sleep(AFTER_SLEEP*3)
else:
time.sleep(AFTER_SLEEP)
def cleanup():
print('Cleaning up')
GPIO.cleanup()