2016-12-18 21:17:09 +00:00
|
|
|
#include <Homie.h>
|
2016-12-18 20:15:32 +00:00
|
|
|
// homie lib from: https://github.com/marvinroger/homie-esp8266/
|
2016-12-18 21:17:09 +00:00
|
|
|
#include <Adafruit_NeoPixel.h>
|
|
|
|
#ifdef __AVR__
|
|
|
|
#include <avr/power.h>
|
|
|
|
#endif
|
2016-12-18 20:15:32 +00:00
|
|
|
|
2016-12-18 21:17:09 +00:00
|
|
|
#define PIN 2 //data pin for ws2812
|
2016-12-18 20:15:32 +00:00
|
|
|
|
2016-12-18 21:17:09 +00:00
|
|
|
Adafruit_NeoPixel strip = Adafruit_NeoPixel(64, PIN, NEO_GRB + NEO_KHZ800);
|
2016-12-18 20:15:32 +00:00
|
|
|
|
2016-12-18 21:17:09 +00:00
|
|
|
HomieNode homieNode("pixel", "commands");
|
|
|
|
|
|
|
|
void led_fill(uint32_t c)
|
|
|
|
{
|
|
|
|
for (int i=0; i < strip.numPixels(); i++) {
|
|
|
|
strip.setPixelColor(i, c); //turn every third pixel on
|
|
|
|
}
|
|
|
|
strip.show();
|
|
|
|
}
|
2016-12-18 20:15:32 +00:00
|
|
|
|
|
|
|
bool effectHandler(const HomieRange& range, const String& value) {
|
|
|
|
int sep = value.indexOf("|");
|
|
|
|
|
|
|
|
|
|
|
|
|
2016-12-18 21:17:09 +00:00
|
|
|
Homie.getLogger() << "-> " << value << endl;
|
|
|
|
|
|
|
|
//Serial.print("->"); Serial.println(value);
|
|
|
|
|
|
|
|
if (value.charAt(0)=='#'){ //solid fill
|
|
|
|
String color=value.substring(1);
|
|
|
|
int number = (int) strtol( &color[0], NULL, 16);
|
2016-12-18 20:15:32 +00:00
|
|
|
|
2016-12-18 21:17:09 +00:00
|
|
|
|
|
|
|
// Split them up into r, g, b values
|
|
|
|
int r = number >> 16;
|
|
|
|
int g = number >> 8 & 0xFF;
|
|
|
|
int b = number & 0xFF;
|
|
|
|
Homie.getLogger() << "r=" << r << " g=" << g << " b=" << b << endl;
|
|
|
|
//Serial.print("r=");Serial.print(r);
|
|
|
|
//Serial.print(" g=");Serial.print(g);
|
|
|
|
//Serial.print(" b=");Serial.println(b);
|
|
|
|
|
|
|
|
led_fill(strip.Color(r, g, b));
|
2016-12-18 20:15:32 +00:00
|
|
|
}
|
2016-12-18 21:17:09 +00:00
|
|
|
|
2016-12-18 20:15:32 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool pixelsHandler(const HomieRange& range, const String& value) {
|
|
|
|
int sep = value.indexOf("|");
|
|
|
|
|
|
|
|
|
|
|
|
if(sep > 0) {
|
|
|
|
|
|
|
|
//Homie.getLogger() << "scroll " << value << " wait " << wait << endl;
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
//Homie.getLogger() << "scroll " << value << endl;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void setup() {
|
|
|
|
Serial.begin(115200);
|
|
|
|
Serial << endl << endl;
|
|
|
|
|
|
|
|
|
|
|
|
Homie_setFirmware("pixelprojektor", "1.0.0");
|
|
|
|
|
2016-12-18 21:17:09 +00:00
|
|
|
homieNode.advertise("effect").settable(effectHandler);
|
|
|
|
homieNode.advertise("pixels").settable(pixelsHandler);
|
2016-12-18 20:15:32 +00:00
|
|
|
|
2016-12-18 21:17:09 +00:00
|
|
|
strip.begin();
|
|
|
|
strip.show(); // Initialize all pixels to 'off'
|
|
|
|
|
|
|
|
led_fill(strip.Color(0, 0, 0));
|
2016-12-18 20:15:32 +00:00
|
|
|
|
|
|
|
Homie.setup();
|
2016-12-18 21:17:09 +00:00
|
|
|
|
|
|
|
|
2016-12-18 20:15:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void loop() {
|
|
|
|
Homie.loop();
|
|
|
|
long currentMillis = millis();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2016-12-18 21:17:09 +00:00
|
|
|
|
|
|
|
|
|
|
|
|