Ok. I'm going to add some snippets of my go and a little more description of what I want.
I have a script that reads the values from an Allen Bradley PLC using
PyComm. I have a graphical interface with the PLC and the Pi will read an integer for each color that is generated from the PLC. One for red, one for green and one for blue. (among several other things)
party_lib.py
Code: Select all
class RGB():
rgb_red = [100, 0, 0]
rgb_grn = [0, 100, 0]
rgb_blu = [0, 0, 100]
rgb_yel = [100, 100, 0]
rgb_mag = [100, 0, 100]
rgb_cyn = [0, 100, 100]
rgb_wht = [100, 100, 100]
rgb_org = [100, 50, 0]
rgb_pnk = [100, 0, 50]
I am then calling on this class to either give me a static color at will or a random color using other functions in the library.
micro_gui.py
Code: Select all
import party_lib
import party_2018
############### colors ##############################
red = party_lib.RGB.rgb_red
grn = party_lib.RGB.rgb_grn
blu = party_lib.RGB.rgb_blu
yel = party_lib.RGB.rgb_yel
mag = party_lib.RGB.rgb_mag
cyn = party_lib.RGB.rgb_cyn
wht = party_lib.RGB.rgb_wht
org = party_lib.RGB.rgb_org
pnk = party_lib.RGB.rgb_pnk
def Color_Set(value):
global color
global random
color = value
random = 0
while 1:
N7, F8 = PLC_Read(N7, F8)
#print(N7)
#print(F8)
mode = N7[0]
color = N7[1]
random = N7[3]
sock = N7[4]
bright = N7[5]
delay = F8[0]
if sock == 1:
party_2018.RGB([bright, 0, 0], bright)
print(bright)
elif sock == 2:
party_2018.RGB([0, bright, 0], bright)
elif sock == 3:
party_2018.RGB([0, 0, bright], bright)
if mode == 1 and random == 1 and color == 0 and num < cycles:
random_1 = party_lib.Random_1(bright)
party_lib.Mode_1(random_1, delay, cycles)
num = num + 1
elif mode ==1 and random == 2 and color == 0 and num < cycles:
random_2 = party_lib.Random_2()
party_lib.Mode_1(random_2, delay, cycles)
num = num + 1
elif mode ==1 and random == 0 and color == 1 and num < cycles:
colors = party_lib.Set_Colors(red, red, red, red, red, red, red)
party_lib.Mode_1(colors, delay, cycles)
num = num + 1
elif mode ==1 and random == 0 and color == 2 and num < cycles:
colors = party_lib.Set_Colors(grn, grn, grn, grn, grn, grn, grn)
party_lib.Mode_1(colors, delay, cycles)
num = num + 1
elif mode ==1 and random == 0 and color == 3 and num < cycles:
colors = party_lib.Set_Colors(blu, blu, blu, blu, blu, blu, blu)
party_lib.Mode_1(colors, delay, cycles)
num = num + 1
elif mode ==1 and random == 0 and color == 4 and num < cycles:
colors = party_lib.Set_Colors(yel, yel, yel, yel, yel, yel, yel)
party_lib.Mode_1(colors, delay, cycles)
num = num + 1
elif mode ==1 and random == 0 and color == 5 and num < cycles:
colors = party_lib.Set_Colors(mag, mag, mag, mag, mag, mag, mag)
party_lib.Mode_1(colors, delay, cycles)
num = num + 1
elif mode ==1 and random == 0 and color == 6 and num < cycles:
colors = party_lib.Set_Colors(cyn, cyn, cyn, cyn, cyn, cyn, cyn)
party_lib.Mode_1(colors, delay, cycles)
num = num + 1
elif mode ==1 and random == 0 and color == 7 and num < cycles:
colors = party_lib.Set_Colors(wht, wht, wht, wht, wht, wht, wht)
party_lib.Mode_1(colors, delay, cycles)
num = num + 1
elif mode ==1 and random == 0 and color == 8 and num < cycles:
colors = party_lib.Set_Colors(org, org, org, org, org, org, org)
party_lib.Mode_1(colors, delay, cycles)
num = num + 1
elif mode ==1 and random == 0 and color == 9 and num < cycles:
colors = party_lib.Set_Colors(pnk, pnk, pnk, pnk, pnk, pnk, pnk)
party_lib.Mode_1(colors, delay, cycles)
num = num + 1
num = 0
The intent is to be able to set the brightness of each color in the class using the bright variable coming from the PLC. I am really, really concerned about power consumption since I'm using ~ 38 strands of LEDs for this project and I want to be able to control that by adjusting the duty cycle of my PWMs on the fly.
FYI: I have up to seven different channels of LED strips. That why you see something like "colors = party_lib.Set_Colors(pnk, pnk, pnk, pnk, pnk, pnk, pnk)" If I need to add my entire code I can but it definitely shows my noobness lol.
In the mean time, I will give a go at some of the suggestions here and see what I can make work.
Thanks for the replys.