Forum: PC-Programmierung LED color cycling


von phyton newbi (Gast)


Lesenswert?

Hello currently this is my phyton function for cycling through a led 
stripe with all colors:
1
def cycleLights(self):
2
                t = threading.currentThread()
3
                head  = 0               # Index of first 'on' pixel
4
                tail  = -10             # Index of last 'off' pixel
5
                color = 0xFF0000        # 'On' color (starts red)
6
7
                while getattr(t, "do_run", True):
8
                        self.strip.setPixelColor(head, color) # Turn on 'head' pixel
9
                        self.strip.setPixelColor(tail, 0)     # Turn off 'tail'
10
                        self.strip.show()                     # Refresh strip
11
                        time.sleep(1.0 / 80)             # Pause 20 milliseconds (~50 fps)
12
13
                        head += 1                        # Advance head position
14
                        if(head >= self.numpixels):           # Off end of strip?
15
                                head    = 0              # Reset to start
16
                                color >>= 1              # Red->green->blue->black
17
                                if(color == 0): color = 0xFF0000 # If black, reset to red
18
19
                        tail += 1                        # Advance tail position
20
                        if(tail >= self.numpixels): tail = 0  # Off end? Reset


But i didn't get all colors how can I achiev to circly through the whole 
spectrum???

von Jim M. (turboj)


Lesenswert?

That is much simpler to calculate in HSV color space, since you only 
change the hue value.

So select a color in hsv by changing hue, then translate back to RGB in 
order to control the LEDs.

von guest (Gast)


Lesenswert?

Thin about that line:
1
color >>= 1
and what color values it produce.

Bitte melde dich an um einen Beitrag zu schreiben. Anmeldung ist kostenlos und dauert nur eine Minute.
Bestehender Account
Schon ein Account bei Google/GoogleMail? Keine Anmeldung erforderlich!
Mit Google-Account einloggen
Noch kein Account? Hier anmelden.