feat: rewrite NeoPattern example
This commit is contained in:
45
examples/neopattern/NeoPixelConfig.h
Normal file
45
examples/neopattern/NeoPixelConfig.h
Normal file
@@ -0,0 +1,45 @@
|
||||
#ifndef __NEOPIXEL_CONFIG__
|
||||
#define __NEOPIXEL_CONFIG__
|
||||
|
||||
#include <ArduinoJson.h>
|
||||
|
||||
struct NeoPixelConfig
|
||||
{
|
||||
// Configuration constants
|
||||
static constexpr int DEFAULT_PIN = 2;
|
||||
static constexpr int DEFAULT_LENGTH = 8;
|
||||
static constexpr int DEFAULT_BRIGHTNESS = 100;
|
||||
static constexpr int DEFAULT_UPDATE_INTERVAL = 100;
|
||||
static constexpr int DEFAULT_COLOR = 0xFF0000; // Red
|
||||
|
||||
int pin = DEFAULT_PIN;
|
||||
int length = DEFAULT_LENGTH;
|
||||
int brightness = DEFAULT_BRIGHTNESS;
|
||||
int updateInterval = DEFAULT_UPDATE_INTERVAL;
|
||||
int defaultColor = DEFAULT_COLOR;
|
||||
|
||||
NeoPixelConfig() = default;
|
||||
|
||||
NeoPixelConfig(int p, int l, int b, int interval, int color = DEFAULT_COLOR)
|
||||
: pin(p), length(l), brightness(b), updateInterval(interval), defaultColor(color) {}
|
||||
|
||||
void mapJsonObject(JsonObject &root) const
|
||||
{
|
||||
root["pin"] = pin;
|
||||
root["length"] = length;
|
||||
root["brightness"] = brightness;
|
||||
root["updateInterval"] = updateInterval;
|
||||
root["defaultColor"] = defaultColor;
|
||||
}
|
||||
|
||||
void fromJsonObject(JsonObject &json)
|
||||
{
|
||||
pin = json["pin"] | pin;
|
||||
length = json["length"] | length;
|
||||
brightness = json["brightness"] | brightness;
|
||||
updateInterval = json["updateInterval"] | updateInterval;
|
||||
defaultColor = json["defaultColor"] | defaultColor;
|
||||
}
|
||||
};
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user