-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDEV_LED.h
More file actions
48 lines (37 loc) · 1.5 KB
/
DEV_LED.h
File metadata and controls
48 lines (37 loc) · 1.5 KB
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
#include <Adafruit_NeoPixel.h>
#define LED_PIN 21 // 데이터 핀
#define NUM_LEDS 1 // 제어할 LED 수 (1개)
Adafruit_NeoPixel strip(NUM_LEDS, LED_PIN, NEO_GRB + NEO_KHZ800); // 21pin(SK6812)
struct DEV_RgbLED : Service::LightBulb {
SpanCharacteristic *power; // 전원 상태
SpanCharacteristic *H; // 색상 (Hue)
SpanCharacteristic *S; // 채도 (Saturation)
SpanCharacteristic *V; // 밝기 (Brightness)
DEV_RgbLED() : Service::LightBulb() {
power = new Characteristic::On();
H = new Characteristic::Hue(0); // 초기값 0
S = new Characteristic::Saturation(0); // 초기값 0%
V = new Characteristic::Brightness(100); // 초기값 100%
V->setRange(5, 100, 1); // 밝기 최소 5%, 최대 100%
strip.begin(); // NeoPixel 초기화
strip.show(); // LED를 초기화)
Serial.println("Configuring SK6812 RGB LED with NeoPixel");
}
boolean update() {
boolean p = power->getVal(); // 전원 상태
float h = H->getVal<float>();
float s = S->getVal<float>() / 100.0;
float v = V->getVal<float>() / 100.0;
float r, g, b;
LedPin::HSVtoRGB(h, s, v, &r, &g, &b); // HSV를 RGB로 변환 (0~1 범위)
uint8_t R = p * r * 255;
uint8_t G = p * g * 255;
uint8_t B = p * b * 255;
strip.setPixelColor(0, strip.Color(R, G, B));
strip.show();
char cBuf[128];
sprintf(cBuf, "RGB=(%d,%d,%d)\n", R, G, B);
Serial.print(cBuf);
return true;
}
};