led.h
1 #pragma once 2 3 #include <stdint.h> 4 5 struct Color { 6 uint8_t r, g, b; 7 }; 8 9 namespace colors { 10 constexpr Color Black = {0, 0, 0}; 11 constexpr Color Red = {255, 0, 0}; 12 constexpr Color Green = {0, 128, 0}; 13 constexpr Color Blue = {0, 0, 255}; 14 constexpr Color Yellow = {255, 255, 0}; 15 constexpr Color Cyan = {0, 255, 255}; 16 constexpr Color Magenta = {255, 0, 255}; 17 constexpr Color White = {255, 255, 255}; 18 constexpr Color Gold = {255, 215, 0}; 19 constexpr Color DarkOrange = {255, 140, 0}; 20 constexpr Color BlueViolet = {138, 43, 226}; 21 } 22 23 class Led { 24 public: 25 bool init(); 26 void set(const Color &color); 27 void set(uint8_t r, uint8_t g, uint8_t b); 28 void setHSV(uint8_t hue, uint8_t saturation, uint8_t value); 29 void off(); 30 void fadeIn(const Color &color, uint32_t duration_ms); 31 void fadeOut(const Color &color, uint32_t duration_ms); 32 void glow(uint32_t duration_ms); 33 34 void setBrightness(uint8_t b); 35 uint8_t getBrightness(); 36 Color getColor(); 37 }; 38 39 extern Led LED; 40 41 #ifdef PIO_UNIT_TESTING 42 namespace programs::led { void test(); } 43 #endif