Pico Led Controller 1.0.3
A project to control LEDs using Raspberry Pi Pico W
hsv.c File Reference
#include "hsv.h"
#include "urgb.h"

Go to the source code of this file.

Functions

uint32_t hsv_to_rgb (uint16_t h, uint8_t s, uint8_t v)
 Convert HSV to RGB. More...
 

Function Documentation

◆ hsv_to_rgb()

uint32_t hsv_to_rgb ( uint16_t  h,
uint8_t  s,
uint8_t  v 
)

Convert HSV to RGB.

Parameters
hhue
ssaturation
vvalue
Returns
: RGB 32-bit color

Definition at line 5 of file hsv.c.

6 {
7  float hf = h / 60.0f;
8  float sf = s / 255.0f;
9  float vf = v / 255.0f;
10 
11  int i = (int)hf % 6;
12  float f = hf - (int)hf;
13  uint8_t p = (uint8_t)(vf * (1.0f - sf) * 255);
14  uint8_t q = (uint8_t)(vf * (1.0f - sf * f) * 255);
15  uint8_t t = (uint8_t)(vf * (1.0f - sf * (1.0f - f)) * 255);
16  uint8_t vi = (uint8_t)(vf * 255);
17 
18  uint8_t r, g, b;
19  switch (i) {
20  case 0:
21  r = vi;
22  g = t;
23  b = p;
24  break;
25  case 1:
26  r = q;
27  g = vi;
28  b = p;
29  break;
30  case 2:
31  r = p;
32  g = vi;
33  b = t;
34  break;
35  case 3:
36  r = p;
37  g = q;
38  b = vi;
39  break;
40  case 4:
41  r = t;
42  g = p;
43  b = vi;
44  break;
45  case 5:
46  r = vi;
47  g = p;
48  b = q;
49  break;
50  default:
51  r = 0;
52  g = 0;
53  b = 0;
54  break;
55  }
56  return URGB(r, g, b);
57 }
#define URGB(r, g, b)
Definition: urgb.h:6

References URGB.

Referenced by apply_rainbow_cycle_effect(), apply_rainbow_wheel_effect(), and set_rainbow_spectrum().