import subprocess import sys, inspect, os import wiringpi from time import sleep #from multiprocessing import Process #import lirc from pyudmx import pyudmx # def send_dmx(dev, red, green, blue, dimmer): # """ # Send a set of RGB values to the light # """ # cv = [0 for v in range(0, 512)] # cv[0] = dimmer # cv[1] = red # cv[2] = green # cv[3] = blue # sent = dev.send_multi_value(1, cv) # return sent # # GPIO pin_kugel = 2 pin_sun = 4 pin_pir = 0 def setDmxScene(scene): cv = [0 for v in range(0, 512)] scenes = { "fadecolors":[255,255,255,255,255,192], "plain-red":[255,255,0,0,0,0], "strobe":[190,255,255,255,0,0], "nini":[120,0,255,255,0,224], "black":[0,0,0,0,0,0] } errorcode = [240,255,0,0,0,0] for index, val in enumerate(scenes.get(scene,errorcode)): cv[index] = val dev.send_multi_value(1, cv) def setKugel(state): if state == 'on': wiringpi.digitalWrite(pin_kugel, 0) if state == 'off': wiringpi.digitalWrite(pin_kugel, 1) def setSun(state): if state == 'off': wiringpi.digitalWrite(pin_sun, 0) if state == 'on': wiringpi.digitalWrite(pin_sun, 1) def setMusic(action, scene): if action == "play": if not scene: scene = defaulscene musicdir = os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe()))) + "/music/" + scene for (path, dirnames, filenames) in os.walk(musicdir): #folders.extend(os.path.join(path, name) for name in dirnames) for name in filenames: file = os.path.join(path, name) #os.system("mpg123 " + "'" + file + "'") #os.system("") subprocess.run(["mpg123", file]) def bootstrap(): wiringpi.wiringPiSetup() wiringpi.pinMode(pin_kugel, 1) # set Relay Disokugel mode to OUTPUT wiringpi.pinMode(pin_sun, 1) # set Relay Sun mode to OUTPUT # TODO: Set pin! wiringpi.pinMode(pin_pir, 0) # set PIR Sensor mode to INPUT setSun('off') setKugel('off') bootstrap() dev = pyudmx.uDMXDevice() dev.open() pirstate = wiringpi.digitalRead(6) defaultscene = 1 while True: # if PIR-State changes if wiringpi.digitalRead(pin_pir) != pirstate: pirstate = wiringpi.digitalRead(pin_pir) print('pirstate: ', pirstate) if pirstate == 1: setSun('off') setKugel('on') setDmxScene('fadecolors') sleep(1) sleep(1) # setMusic('play', '1') sleep(20) else: setSun('on') setDmxScene('black') sleep(1) setKugel('off') sleep(1) dev.close()