for anyone interested in using ledstrips controlled by domoticz, i made the following sketch..
Code: Select all
// Example sketch showing how to control an RGB Led Strip.
// This example will not remember the last rgb color set after power failure.
#include <MySensor.h>
#include <SPI.h>
#include "Adafruit_NeoPixel.h"
#define NUMPIXELS 4 // Number of connected pixels on a single datapin
#define PIN 4 // Digital output pin
#define node 254 //254 for testing purpose
#define CHILD_ID 0
Adafruit_NeoPixel strip = Adafruit_NeoPixel(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);
long RGB_values[3] = {0,0,0};
MySensor gw;
void setup()
{
gw.begin(incomingMessage, node, true);
gw.sendSketchInfo("RGB Node", "1.0");
gw.present(CHILD_ID, S_RGB_LIGHT);
strip.begin();
strip.show(); // Update the strip, to start they are all 'off'
}
void loop()
{
gw.process();
}
void incomingMessage(const MyMessage &message) {
if (message.type==V_RGB) {
// starting to process the hex code
String hexstring = message.getString(); //here goes the hex color code coming from through MySensors (like FF9A00)
long number = (long) strtol( &hexstring[0], NULL, 16);
RGB_values[0] = number >> 16;
RGB_values[1] = number >> 8 & 0xFF;
RGB_values[2] = number & 0xFF;
colorWipe(Color(RGB_values[0],RGB_values[1],RGB_values[2]), 60);
}
if (message.type==V_DIMMER) {
strip.setBrightness(round((2.55*message.getInt())));
strip.show();
}
if (message.type==V_LIGHT) {
if (message.getInt() == 0) {
strip.clear();
strip.show();
}
}
}
void colorWipe(uint32_t c, uint8_t wait) {
int i;
for (i=0; i < strip.numPixels(); i++) {
strip.setPixelColor(i, c);
strip.show();
delay(wait);
}
}
/* Helper functions */
// Create a 15 bit color value from R,G,B
uint32_t Color(byte r, byte g, byte b)
{
uint32_t c;
c = r;
c <<= 8;
c |= g;
c <<= 8;
c |= b;
return c;
}
there is no lightshow added (disco button) as i have no need for this, only a fast pixel by pixel color change when choosing another color.
there is a minor issue in domoticz (by design i understand) preventing the use of the full color range, domoticz only sends the values from the slider or bright-white (rgb #ffffff), nothing in between.
can anyone suggest a fix or workaround for this?
cheers,
yuri