Ledborg commandline
Forums:
Hello,
I have the script bellow.
#!/usr/bin/env python # Import library functions we need import time import wiringpi2 as wiringpi wiringpi.wiringPiSetup() import sys print sys.argv[1] print sys.argv[2] print sys.argv[3] # Setup software PWMs on the GPIO pins PIN_RED = 0 PIN_GREEN = 2 PIN_BLUE = 3 LED_MAX = 100 wiringpi.softPwmCreate(PIN_RED, 0, LED_MAX) wiringpi.softPwmCreate(PIN_GREEN, 0, LED_MAX) wiringpi.softPwmCreate(PIN_BLUE, 0, LED_MAX) wiringpi.softPwmWrite(PIN_RED, int(sys.argv[1])) wiringpi.softPwmWrite(PIN_GREEN, int(sys.argv[2])) wiringpi.softPwmWrite(PIN_BLUE, int(sys.argv[3])) time.sleep( 2.0 )
___________________________________________________________
want to change the collors by the commandline.
However when the script starts everything is fine.
but after the 2 seconds sleep there is a strange behavior.
when i start with all the colors on. there is only blue left.
if i choose a red/green mix there will be no color left on the end of the script.
it would be the best to only change the colors (so remove the first part that set all colors to 0)
all help would be welcome.
piborg
Thu, 03/24/2016 - 13:57
Permalink
wiringpi.softPwm
Unfortunately this is a limitation of how the software PWM in wiringpi works.
Put simply it need the script to continue running so that it can maintain the colour on the LedBorg.
One option is to only use the simple on/off controls as shown in the more basic examples: https://www.piborg.org/ledborg/lesson/1
This should maintain the colour after the script ends, but it will only allow you to have 7 colours plus off.
The other option is a bit more tricky and involves two scripts.
What you would have to do is have a script running constantly which controls the LedBorg when it is sent a new colour.
You will then need a second script which takes the command line values and sends them to the first script.
There is a simple example of passing data between scripts using UDP here:
https://wiki.python.org/moin/UdpCommunication
The very first example can be used for the command line script, simply fill in the correct data into
MESSAGE
.The second example is how you then receive the message, you would use the contents of
DATA
after therecvfrom
call to set the LedBorg colour.koos147
Sat, 04/02/2016 - 17:51
Permalink
Hey thanks for the help.
Hey thanks for the help.
I am not really a python engineer but with your suggestion and some help from google i created the following 2 scripts.
the deamon
the client script needs 3 arguments (RGB)
script.py 10 20 30
where Red = 10%
Green = 20%
Blue = 30%
Hope this will also help someone else.
Again thanks for your help.