philspitler
Posts: 17
Joined: Thu Apr 07, 2016 5:17 am

Changing HUE

Sun May 01, 2016 2:01 am

Hi, I am using a PiZero to control some LED strips but my python knowledge is minimal.

My issue is how to change the HUE of a color.

Currently my code to light up the LED is

Code: Select all

color = 0xFF0000  
strip.setPixelColor(1, color) 
This works great but what I want to do is to change the hue of the color before sending it to the LED.

My pseudo code would be something like this.

Code: Select all

color = 0xFF0000 
Convert color to HSV
Increment the hue
Convert back to hex
strip.setPixelColor(1, updatedColor)
But I have no idea where to really start.

I would love any advice.

Thanks.

Phil

User avatar
kusti8
Posts: 3439
Joined: Sat Dec 21, 2013 5:29 pm
Location: USA

Re: Changing HUE

Sun May 01, 2016 2:08 am

This library seems simple and promising. https://pypi.python.org/pypi/colour/
There are 10 types of people: those who understand binary and those who don't.

philspitler
Posts: 17
Joined: Thu Apr 07, 2016 5:17 am

Re: Changing HUE

Sun May 01, 2016 5:17 am

This looks great and exactly what I need.

I have it installed but I get an error when trying to send the color to my LEDs.

TypeError: an integer is required

Here is my code snipet:

Code: Select all

c = Color("#FF0000")
strip.setPixelColor(1, c) 

I have also tried.

Code: Select all

c = Color("#FF0000")
strip.setPixelColor(1, c.hex) 
Somehow I need to convert the color object back to an integer I think.

Any ideas?

Thanks.

Phil

DirkS
Posts: 10371
Joined: Tue Jun 19, 2012 9:46 pm
Location: Essex, UK

Re: Changing HUE

Sun May 01, 2016 11:00 am

Try

Code: Select all

c = Color(0xff0000)
strip.setPixelColor(1, c) 

philspitler
Posts: 17
Joined: Thu Apr 07, 2016 5:17 am

Re: Changing HUE

Sun May 01, 2016 7:45 pm

Nope, that gives me a different error. It seems like the color library needs a different way to declare the color.

Here is the error output.

Code: Select all

File "disMon.py", line 39, in <module>
    c = Color(0xff0000)
  File "/usr/local/lib/python2.7/dist-packages/colour.py", line 972, in __init__
    self.web = color if color else 'black'
  File "/usr/local/lib/python2.7/dist-packages/colour.py", line 990, in __setattr__
    fc(value)
  File "/usr/local/lib/python2.7/dist-packages/colour.py", line 1071, in set_web
    self.hex = web2hex(value)
  File "/usr/local/lib/python2.7/dist-packages/colour.py", line 656, in web2hex
    if web.startswith('#'):
AttributeError: 'int' object has no attribute 'startswith'

Return to “Python”