Last active
June 21, 2018 09:48
-
-
Save nkenna/f4a3dc7bf672f2a969ac632e1647417e to your computer and use it in GitHub Desktop.
Lights controlled by PWM
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import RPi.GPIO as GPIO | |
from numpy import interp | |
p = GPIO.PWM(pinNetwork, 50) # set Frequece to 1KHz | |
p.start(0) | |
bedroom = GPIO.PWM(pinBedroomLight, 50) # set Frequece to 1KHz | |
bedroom.start(0) | |
sittingroom = GPIO.PWM(pinSittingRoomLight, 50) # set Frequece to 1KHz | |
sittingroom.start(0) | |
securitylite = GPIO.PWM(pinSecurityLight, 50) # set Frequece to 1KHz | |
securitylite.start(0) | |
garagelite = GPIO.PWM(pinGarageLight, 50) | |
garagelite.start(0) | |
# pubnub channels | |
BEDROOM_LIGHT = 'BEDROOM_LIGHT' | |
SITTINGROOM_LIGHT = 'SITTINGROOM_LIGHT' | |
GARAGE_LIGHT = 'GARAGE_LIGHT' | |
SECURITY_LIGHT = 'SECURITY_LIGHT' | |
elif message.channel == BEDROOM_LIGHT: | |
b = int(payload) | |
b = interp(b,[0,100],[0,100]) | |
bedroom.ChangeDutyCycle(b) | |
elif message.channel == SITTINGROOM_LIGHT: | |
s = int(payload) | |
s = interp(s,[0,100],[0,100]) | |
sittingroom.ChangeDutyCycle(s) | |
elif message.channel == SECURITY_LIGHT: | |
se = int(payload) | |
se = interp(se,[0,100],[0,100]) | |
securitylite.ChangeDutyCycle(se) | |
elif message.channel == GARAGE_LIGHT: | |
ga = int(payload) | |
ga = interp(ga,[0,100],[0,100]) | |
garagelite.ChangeDutyCycle(ga) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment