-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaction.py
41 lines (34 loc) · 1.06 KB
/
action.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
import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BOARD)
BED_LIGHT = 3
BED_FAN = 18
BED_AC = 11
LIVING_LIGHT = 16
LIVING_FAN = 5
GPIO.setup(BED_LIGHT, GPIO.OUT)
GPIO.setup(BED_FAN, GPIO.OUT)
GPIO.setup(BED_AC, GPIO.OUT)
GPIO.setup(LIVING_LIGHT, GPIO.OUT)
GPIO.setup(LIVING_FAN, GPIO.OUT)
PWM_BED_LIGHT = GPIO.PWM(BED_LIGHT, 50)
PWM_BED_FAN = GPIO.PWM(BED_FAN, 50)
PWM_BED_AC = GPIO.PWM(BED_AC, 50)
PWM_LIVING_LIGHT = GPIO.PWM(LIVING_LIGHT, 50)
PWM_LIVING_FAN = GPIO.PWM(LIVING_FAN, 50)
PWM_BED_LIGHT.start(0)
PWM_BED_FAN.start(0)
PWM_BED_AC.start(0)
PWM_LIVING_LIGHT.start(0)
PWM_LIVING_FAN.start(0)
def action(pin_no, state):
if (pin_no == BED_LIGHT):
PWM_BED_LIGHT.ChangeDutyCycle(state)
elif (pin_no == BED_FAN):
PWM_BED_LIGHT.ChangeDutyCycle(state)
elif (pin_no == BED_AC):
state = (state * 100)/28
PWM_BED_LIGHT.ChangeDutyCycle(state)
elif (pin_no == LIVING_LIGHT):
PWM_BED_LIGHT.ChangeDutyCycle(state)
elif (pin_no == LIVING_FAN):
PWM_BED_LIGHT.ChangeDutyCycle(state)