HomeSpan - Led Strip
Hey, I know that this is the correct way of doing this:
SPAN_ACCESSORY("2RGB strip 1");
new EffectClass(13, 120);
...but I need to pass the class to another one. What I'm trying to achieve is this:
Neopixel_RGB get the HSV values from the HomeKit App.
That is passed to EffectClass that sends the info to the RGB strip with effects (EffectClass gets the HSV values, but I care only about brightness, since that defines the effect - 100% solid, 80% flashing, ...).
This is my current implemetation. Can I get help please? When I use this code it is displayed in the app as "not supported".
main.ino
#if defined(CONFIG_IDF_TARGET_ESP32)
#define NEOPIXEL_RGB_PIN 13
#define NEOPIXEL_RGBW_PIN 32
#define DOTSTAR_DATA_PIN 33
#define DOTSTAR_CLOCK_PIN 27
#define DEVICE_SUFFIX ""
#elif defined(CONFIG_IDF_TARGET_ESP32S2)
#define NEOPIXEL_RGB_PIN 17
#define NEOPIXEL_RGBW_PIN 38
#define DOTSTAR_DATA_PIN 3
#define DOTSTAR_CLOCK_PIN 7
#define DEVICE_SUFFIX "-S2"
#elif defined(CONFIG_IDF_TARGET_ESP32C3)
#define NEOPIXEL_RGB_PIN 0
#define NEOPIXEL_RGBW_PIN 3
#define DOTSTAR_DATA_PIN 7
#define DOTSTAR_CLOCK_PIN 2
#define DEVICE_SUFFIX "-C3"
#endif
#include "HomeSpan.h"
#include "LED.h"
#include "Effect.h"
#include <FastLED.h>
// EffectClass effect;
// NeoPixel_RGB led;
void setup() {
Serial.begin(115200);
homeSpan.begin(Category::Lighting,"RGB strips" DEVICE_SUFFIX);
SPAN_ACCESSORY(); // create Bridge (note this sketch uses the SPAN_ACCESSORY() macro, introduced in v1.5.1 --- see the HomeSpan API Reference for details on this convenience macro)
SPAN_ACCESSORY("2RGB strip 1");
EffectClass effect(13, 120); // create 8-LED NeoPixel RGB Strand with full color control
SPAN_ACCESSORY("2Effect Setter 1");
NeoPixel_RGB led(led, 13, 120); // create 8-LED NeoPixel RGB Strand with full color control
}
void loop() {
homeSpan.poll();
}
///////////////////////////////
LED.h
#ifndef NEOPIXEL_RGB_H
#define NEOPIXEL_RGB_H
#include <HomeSpan.h>
#include <FastLED.h>
class NeoPixel_RGB : public Service::LightBulb {
public:
Characteristic::On power{0, true};
Characteristic::Hue H{0, true};
Characteristic::Saturation S{0, true};
Characteristic::Brightness V{100, true};
NeoPixel_RGB(uint8_t pin, int nPixels); // Constructor declaration
boolean update() override;
private:
int nPixels;
Pixel *pixel;
};
NeoPixel_RGB::NeoPixel_RGB(uint8_t pin, int nPixels) : Service::LightBulb() {
this->nPixels = nPixels;
V.setRange(0, 100, 1);
pixel = new Pixel(pin);
update();
}
boolean NeoPixel_RGB::update() {
int p = power.getNewVal();
float h = H.getNewVal<float>();
float s = S.getNewVal<float>();
float v = V.getNewVal<float>();
Pixel::Color color;
pixel->set(color.HSV(h * p, s * p, v * p), nPixels);
return true;
}
#endif // NEOPIXEL_RGB_H
///////////////////////////////
Effect.h
#ifndef EFFECTCLASS_H
#define EFFECTCLASS_H
#include <HomeSpan.h>
#include <FastLED.h>
#include "LED.h"
struct EffectClass : Service::LightBulb {
Characteristic::On pwr{0,true};
Characteristic::Hue Hu{0,true};
Characteristic::Saturation Sa{0,true};
Characteristic::Brightness Br{100,true};
NeoPixel_RGB &neopixel;
EffectClass(NeoPixel_RGB &neopixel, int pin, int nPixels) : neopixel(neopixel), Service::LightBulb() {
Br.setRange(0, 100, 1);
update();
}
boolean update() override {
int pw = pwr.getNewVal();
float hu = Hu.getNewVal<float>();
float sa = Sa.getNewVal<float>();
float br = Br.getNewVal<float>();
Pixel::Color clr;
neopixel.power.setVal(pw);
neopixel.H.setVal(hu);
neopixel.S.setVal(sa);
neopixel.V.setVal(br);
return true;
}
};
#endif // EFFECTCLASS_H