-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHardware-LEDTester-Arduino.ino
77 lines (69 loc) · 1.22 KB
/
Hardware-LEDTester-Arduino.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#include <Adafruit_NeoPixel.h>
static const uint16_t LedCount = 1;
static const uint8_t LedDataPinNumber = 6;
static const neoPixelType LedType = NEO_KHZ800 | NEO_GRB;
static Adafruit_NeoPixel leds(LedCount, LedDataPinNumber, LedType);
static float wrap(float value, float max)
{
return value - max * floor(value / max);
}
static void HSV2RGB(float h, float s, float v, uint8_t &r, uint8_t &g, uint8_t &b)
{
h *= 6.f;
int sector = (int)h;
float f = h - sector;
uint8_t V = (uint8_t)(v * 255.f);
uint8_t p = (uint8_t)(V * (1.f - s));
uint8_t q = (uint8_t)(V * (1.f - s * f));
uint8_t t = (uint8_t)(V * (1.f - s * (1.f - f)));
switch (sector % 6)
{
case 0:
r = V;
g = t;
b = p;
break;
case 1:
r = q;
g = V;
b = p;
break;
case 2:
r = p;
g = V;
b = t;
break;
case 3:
r = p;
g = q;
b = V;
break;
case 4:
r = t;
g = p;
b = V;
break;
case 5:
r = V;
g = p;
b = q;
break;
}
}
void setup()
{
leds.begin();
leds.setBrightness(255);
}
static float h = 0.f;
static float s = 1.f;
static float v = 1.f;
static const float hIncrement = 0.0001f;
void loop()
{
h = wrap(h + hIncrement, 1.f);
uint8_t r, g, b;
HSV2RGB(h, s, v, r, g, b);
leds.setPixelColor(0, r, g, b);
leds.show();
}