W
W
Werewolfe2020-06-04 14:58:58
Python
Werewolfe, 2020-06-04 14:58:58

How to implement a smooth change of RGB LED color values?

Hello!
Please tell me how to properly organize a smooth color transfer to the LED.
At the moment, it is implemented in such a way that i takes values ​​from a tuple, transfers them to the tape and falls asleep for N times. However, in this way it turns out not a smooth color change, I want to achieve smoothness. Only G,B values ​​change.
The values ​​increase until the middle of the day, then decrease.

Changing values ​​per step

G B
0 0
6 0
6 0
5 0
5 0
6 18
5 15
5 11
5 10
5 9
4 9
4 7
4 8
4 7
4 7
3 6
4 7
3 6
3 6
3 6
3 5
3 6
2 5
3 5
2 6
3 4
2 5
2 5
2 4
2 5
2 4
2 4
2 4
2 4
2 4
1 4
2 4
2 3
1 4
2 3


Current Code
light_color_list = ((255, 109, 0),  #R, G, B 
                    (255, 115, 0),
                    (255, 121, 0),
                    (255, 126, 0),
                    (255, 131, 0),
                    (255, 137, 18),
                    (255, 142, 33),
                    (255, 147, 44),
                    (255, 152, 54),
                    (255, 157, 63),
                    (255, 161, 72),
                    (255, 165, 79),
                    (255, 169, 87),
                    (255, 173, 94),
                    (255, 177, 101),
                    (255, 180, 107),
                    (255, 184, 114),
                    (255, 187, 120),
                    (255, 190, 126),
                    (255, 193, 132),
                    (255, 196, 137),
                    (255, 199, 143),
                    (255, 201, 148),
                    (255, 204, 153),
                    (255, 206, 159),
                    (255, 209, 163),
                    (255, 211, 168),
                    (255, 213, 173),
                    (255, 215, 177),
                    (255, 217, 182),
                    (255, 219, 186),
                    (255, 221, 190),
                    (255, 223, 194),
                    (255, 225, 198),
                    (255, 227, 202),
                    (255, 228, 206),
                    (255, 230, 210),
                    (255, 232, 213),
                    (255, 233, 217),
                    (255, 235, 220))
def sunset(count, timer):
''' Часть кода намеренно пропущена ''' 
    sleep = (day_length - sec) // len(light_color_list) # Время рассчитывается исходя из длинны дня (может быть разная в зависимости от координат заданных. 
    while i < parts + 1:
        led(light_color_list[i])
        i += 1
        time.sleep_ms(sleep)

How else is it possible to do this?
Preferably without third-party libraries, since the code is in micropython.
I hope I made my point clear.
Thanks in advance!

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
alex1478, 2020-06-04
@Werewolfe

Use HSV for the color, change the hue from 0 to 360 (or whatever color range you want), up/down 1 at a time. After each change, convert HSV to RGB and send to tape.
There is a simple algorithm, you can write it yourself, without libraries.

G
Grigory Boev, 2020-06-05
@ProgrammerForever

That's right they said - here HSV is best suited. A long time ago I did functions for Pascal, in that branch in C they posted something similar. Look, it will be useful for implementation.
Functions for converting RGB >> HSV

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question