2017-07-05 00:05:34 +00:00
|
|
|
#include <Homie.h>
|
2018-12-06 23:38:15 +00:00
|
|
|
// https://github.com/adafruit/Adafruit_NeoMatrix // Adafruit_GFX.h
|
|
|
|
#include "Adafruit_NeoMatrix.h"
|
|
|
|
#include <Adafruit_GFX.h>
|
2017-07-05 00:05:34 +00:00
|
|
|
#include <Adafruit_NeoPixel.h>
|
2018-12-06 23:38:15 +00:00
|
|
|
|
2019-08-02 21:18:01 +00:00
|
|
|
|
2017-07-05 00:05:34 +00:00
|
|
|
#include <ArduinoOTA.h>
|
|
|
|
#include "NeoPatterns.h"
|
2019-08-02 21:18:01 +00:00
|
|
|
|
|
|
|
#include <WiFiUdp.h>
|
2017-07-05 00:05:34 +00:00
|
|
|
#ifdef __AVR__
|
|
|
|
#include <avr/power.h>
|
|
|
|
#endif
|
|
|
|
|
2018-12-06 23:38:15 +00:00
|
|
|
#define PIN D2 //data pin for ws2812 (pixelbox @ ctdo: PIN 2) // Für pixelpad: Pin2
|
2017-07-05 00:05:34 +00:00
|
|
|
#define NUMPIXELS 64
|
|
|
|
|
|
|
|
NeoPatterns strip = NeoPatterns(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800, &StripComplete);
|
2018-12-06 23:38:15 +00:00
|
|
|
|
|
|
|
Adafruit_NeoMatrix matrix = Adafruit_NeoMatrix(8, 8, PIN,
|
|
|
|
NEO_MATRIX_BOTTOM + NEO_MATRIX_LEFT +
|
|
|
|
NEO_MATRIX_COLUMNS + NEO_MATRIX_ZIGZAG,
|
|
|
|
NEO_GRB + NEO_KHZ800);
|
|
|
|
|
2019-08-02 21:18:01 +00:00
|
|
|
WiFiUDP Udp;
|
|
|
|
unsigned int localUdpPort = 4210; // local port to listen on
|
|
|
|
char incomingPacket[255]; // buffer for incoming packets
|
|
|
|
|
2018-12-06 23:38:15 +00:00
|
|
|
const uint16_t colors[] = {
|
|
|
|
matrix.Color(255, 0, 0), matrix.Color(0, 255, 0), matrix.Color(0, 0, 255)
|
|
|
|
};
|
|
|
|
|
|
|
|
int x = matrix.width();
|
|
|
|
int pass = 0;
|
2017-07-05 00:05:34 +00:00
|
|
|
|
|
|
|
bool stopAfterCompletion;
|
2019-07-02 16:34:45 +00:00
|
|
|
int effect = 0;
|
2019-07-18 18:09:16 +00:00
|
|
|
int curBrightness = 255;
|
2017-07-05 00:05:34 +00:00
|
|
|
|
|
|
|
void StripComplete() {
|
|
|
|
if (stopAfterCompletion)
|
|
|
|
{
|
|
|
|
strip.IconComplete();
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
HomieNode homieNode("pixel", "commands");
|
|
|
|
|
|
|
|
bool onSetColor(const HomieRange& range, const String& value) {
|
|
|
|
if (!range.isRange || range.index < 0 || range.index > 1) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
switch (range.index) {
|
|
|
|
case 0:
|
|
|
|
strip.SetColor1(value.toInt());
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
strip.SetColor2(value.toInt());
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
homieNode.setProperty("color_" + String(range.index)).send(value);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool onSetPixel(const HomieRange& range, const String& value) {
|
|
|
|
if (!range.isRange) {
|
|
|
|
strip.None();
|
|
|
|
strip.ColorSet(value.toInt());
|
|
|
|
homieNode.setProperty("pixel").send(value);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if (range.index < 0 || range.index > strip.numPixels() - 1) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
strip.None();
|
|
|
|
strip.setPixelColor(range.index, value.toInt());
|
|
|
|
strip.show();
|
|
|
|
homieNode.setProperty("pixel_" + String(range.index)).send(value);
|
|
|
|
}
|
|
|
|
|
2019-07-02 18:29:09 +00:00
|
|
|
bool onSetVU(const HomieRange& range, const String& value) {
|
|
|
|
strip.Stop(); // Do not show any "effects" anymore
|
|
|
|
strip.clear(); // All pixels to black
|
|
|
|
String remaining = value;
|
|
|
|
String current;
|
|
|
|
int i = 0;
|
|
|
|
do
|
|
|
|
{
|
|
|
|
if (remaining.length() == 1)
|
|
|
|
{
|
2019-08-02 21:18:01 +00:00
|
|
|
current = remaining.substring(0, 1);
|
2019-07-02 18:29:09 +00:00
|
|
|
} else {
|
2019-08-02 21:18:01 +00:00
|
|
|
current = remaining.substring(0, 2);
|
2019-07-02 18:29:09 +00:00
|
|
|
}
|
|
|
|
int currentvalue = (int) strtol(¤t[0], NULL, 10);
|
|
|
|
// White peak
|
2019-08-02 21:18:01 +00:00
|
|
|
strip.setPixelColor(strip.numToPos(56 + i - currentvalue * 8), 16777215); // White dot
|
2019-07-02 18:29:09 +00:00
|
|
|
// Shaded bar "below" the peak
|
2019-08-02 21:18:01 +00:00
|
|
|
if (currentvalue > 0)
|
2019-07-02 18:29:09 +00:00
|
|
|
{
|
2019-08-02 21:18:01 +00:00
|
|
|
for (int j = currentvalue - 1; j > -1; j--)
|
2019-07-02 18:29:09 +00:00
|
|
|
{
|
2019-08-02 21:18:01 +00:00
|
|
|
strip.setPixelColor(strip.numToPos(56 + i - j * 8), 4276545); // Greyscale
|
2019-07-02 18:29:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
i++;
|
|
|
|
remaining = remaining.substring(2);
|
2019-08-02 21:18:01 +00:00
|
|
|
} while (remaining.length() > 0); // TODO: Not bigger than strip
|
2019-07-02 18:29:09 +00:00
|
|
|
strip.show();
|
|
|
|
homieNode.setProperty("VU_" + String(range.index)).send(value);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-07-05 00:05:34 +00:00
|
|
|
bool onSetBrightness(const HomieRange& range, const String& value) {
|
|
|
|
long brightness = value.toInt();
|
2019-07-18 18:09:16 +00:00
|
|
|
setBrightness(brightness);
|
|
|
|
homieNode.setProperty("brightness").send(value);
|
|
|
|
curBrightness = brightness;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool setBrightness(long brightness) {
|
2017-07-05 00:05:34 +00:00
|
|
|
if (brightness < 0 || brightness > 255) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
strip.setBrightness(brightness);
|
2018-12-06 23:38:15 +00:00
|
|
|
matrix.setBrightness(brightness);
|
2017-07-05 00:05:34 +00:00
|
|
|
strip.show();
|
2018-12-06 23:38:15 +00:00
|
|
|
matrix.show();
|
2017-07-05 00:05:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool onSetPixels(const HomieRange& range, const String& value) {
|
|
|
|
|
|
|
|
String remaining = value;
|
|
|
|
int i = 0;
|
|
|
|
// Kein Effekt
|
|
|
|
strip.Stop();
|
|
|
|
do {
|
|
|
|
String current = remaining.substring(0, 7);
|
|
|
|
Homie.getLogger() << i << ":" << current << endl;
|
|
|
|
uint32_t currentcolor = strip.parseColor(current);
|
|
|
|
|
|
|
|
strip.setPixelColor(strip.numToPos(i), currentcolor);
|
|
|
|
i++;
|
|
|
|
|
|
|
|
remaining = remaining.substring(7);
|
|
|
|
|
|
|
|
} while (remaining.length() > 2 && (i < strip.numPixels()));
|
|
|
|
Homie.getLogger() << " filling rest with black" << endl;
|
|
|
|
while (i < strip.numPixels()) {
|
|
|
|
strip.setPixelColor(strip.numToPos(i), strip.Color(0, 0, 0));
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
|
|
|
|
strip.show();
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool onSetEffect(const HomieRange& range, const String& value) {
|
|
|
|
stopAfterCompletion = false;
|
|
|
|
String effect = value;
|
2018-12-06 23:38:15 +00:00
|
|
|
String firstfourbytes;
|
|
|
|
if (value.length() > 3)
|
|
|
|
{
|
2019-08-02 21:18:01 +00:00
|
|
|
firstfourbytes = value.substring(0, 4);
|
2018-12-06 23:38:15 +00:00
|
|
|
} else {
|
|
|
|
firstfourbytes = value;
|
2017-07-05 00:05:34 +00:00
|
|
|
}
|
2018-12-06 23:38:15 +00:00
|
|
|
effect.toLowerCase();
|
|
|
|
|
|
|
|
if (firstfourbytes == "text") {
|
2017-07-05 00:05:34 +00:00
|
|
|
int sep = value.indexOf("|");
|
2018-12-06 23:38:15 +00:00
|
|
|
if (sep > 0) {
|
|
|
|
// Parameter given: Acceptable text command
|
|
|
|
// Deactivate NeoPattern
|
|
|
|
strip.None();
|
|
|
|
String command = value.substring(0, sep);
|
2019-08-02 21:18:01 +00:00
|
|
|
String parameters = value.substring(sep + 1);
|
2018-12-06 23:38:15 +00:00
|
|
|
|
|
|
|
int sep2 = parameters.indexOf("|");
|
|
|
|
if (sep2 > 0) {
|
|
|
|
// Interval was given
|
|
|
|
String stext = parameters.substring(0, sep2);
|
2019-03-17 17:15:02 +00:00
|
|
|
String sinterval = parameters.substring(sep2 + 1);
|
2018-12-06 23:38:15 +00:00
|
|
|
|
|
|
|
int sep3 = sinterval.indexOf("|");
|
|
|
|
if (sep3 > 0) {
|
|
|
|
// Color was given
|
|
|
|
int iinterval = sinterval.substring(0, sep3).toInt();
|
|
|
|
String scolor = sinterval.substring(sep3 + 1);
|
2019-03-17 17:15:02 +00:00
|
|
|
homieNode.setProperty("scrollinfo").send("Scroll with interval " + sinterval.substring(0, sep3) + " and color " + sinterval.substring(sep3 + 1));
|
2018-12-06 23:38:15 +00:00
|
|
|
matrix.ScrollText(stext, iinterval, scolor);
|
|
|
|
} else {
|
2019-03-17 17:15:02 +00:00
|
|
|
homieNode.setProperty("scrollinfo").send("Scroll with interval " + parameters.substring(sep2 + 1));
|
2018-12-06 23:38:15 +00:00
|
|
|
int iinterval = parameters.substring(sep2 + 1).toInt();
|
|
|
|
matrix.ScrollText(stext, iinterval);
|
|
|
|
}
|
|
|
|
} else {
|
2019-03-17 17:15:02 +00:00
|
|
|
homieNode.setProperty("scrollinfo").send("Just scroll");
|
2018-12-06 23:38:15 +00:00
|
|
|
matrix.ScrollText(parameters);
|
2017-07-05 00:05:34 +00:00
|
|
|
}
|
2018-12-06 23:38:15 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// Deactivate Matrix
|
|
|
|
matrix.None();
|
|
|
|
if (effect == "scanner") {
|
|
|
|
strip.Scanner(strip.Color(255, 0, 0));
|
|
|
|
}
|
|
|
|
else if (effect == "randomscanner") {
|
|
|
|
strip.Scanner(strip.Color(255, 0, 0), 40, true);
|
|
|
|
}
|
|
|
|
else if (effect == "larsonspiral") {
|
|
|
|
strip.Scanner(strip.Color(255, 0, 0), 40, true, true);
|
|
|
|
}
|
|
|
|
else if (effect == "rainbowcycle") {
|
|
|
|
strip.RainbowCycle(50);
|
|
|
|
}
|
|
|
|
else if (effect == "theaterchase" || effect == "chase") {
|
|
|
|
strip.TheaterChase(strip.Color(255, 0, 0), strip.Color(0, 0, 255), 100);
|
|
|
|
}
|
|
|
|
else if (effect == "fade") {
|
|
|
|
strip.Fade(strip.Color(255, 0, 0), strip.Color(0, 0, 255), 200, 100);
|
|
|
|
}
|
|
|
|
else if (effect == "randomfade") {
|
|
|
|
strip.RandomFade();
|
|
|
|
}
|
|
|
|
else if (effect == "random") {
|
|
|
|
strip.Random();
|
|
|
|
}
|
|
|
|
else if (effect == "smooth") { //example: smooth|[wheelspeed]|[smoothing]|[strength] wheelspeed=1-255, smoothing=0-100, strength=1-255
|
|
|
|
strip.Smooth(16, 80, 50, 40);
|
|
|
|
}
|
|
|
|
else if (effect == "plasma") {
|
|
|
|
strip.Plasma();
|
2017-07-05 00:05:34 +00:00
|
|
|
}
|
|
|
|
else {
|
2018-12-06 23:38:15 +00:00
|
|
|
// Test whether command with parameters was sent
|
|
|
|
int sep = value.indexOf("|");
|
|
|
|
String command = value.substring(0, sep);
|
|
|
|
String parameters = value.substring(sep + 1);
|
|
|
|
if (command.equals("fill")) {
|
|
|
|
strip.ColorSetParameters(parameters);
|
|
|
|
}
|
|
|
|
else if (command.equals("randomfade")) {
|
|
|
|
int sepparam = parameters.indexOf("|");
|
|
|
|
int p1 = parameters.substring(0, sepparam).toInt();
|
|
|
|
if (p1 <= 0) {
|
|
|
|
p1 = 5;
|
|
|
|
}
|
|
|
|
strip.RandomFadeSingle(p1);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
strip.None();
|
|
|
|
}
|
2017-07-05 00:05:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
homieNode.setProperty("effect").send(value);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool onSetIcon(const HomieRange& range, const String& value) {
|
|
|
|
stopAfterCompletion = true;
|
|
|
|
if (value[0] == '#') { //color given
|
|
|
|
strip.Icon(value.substring(7)[0], value.substring(0, 6));
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
strip.Icon(value[0]);
|
|
|
|
}
|
|
|
|
homieNode.setProperty("icon").send(value);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool onSetClear(const HomieRange& range, const String& value) {
|
|
|
|
strip.None();
|
|
|
|
strip.clear();
|
|
|
|
strip.show();
|
|
|
|
homieNode.setProperty("clear").send(value);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool onSetLength(const HomieRange& range, const String& value) {
|
|
|
|
strip.None();
|
|
|
|
strip.clear();
|
|
|
|
strip.show();
|
|
|
|
int newLength = value.toInt();
|
|
|
|
if (newLength > 0) {
|
|
|
|
strip.updateLength(newLength);
|
|
|
|
}
|
|
|
|
homieNode.setProperty("length").send(value);
|
|
|
|
}
|
|
|
|
|
|
|
|
void loopHandler() {
|
|
|
|
strip.Update();
|
2018-12-06 23:38:15 +00:00
|
|
|
matrix.Update();
|
2017-07-05 00:05:34 +00:00
|
|
|
}
|
|
|
|
|
2019-07-18 18:09:16 +00:00
|
|
|
|
2019-08-02 21:18:01 +00:00
|
|
|
bool NextPrev(bool next = false) {
|
2019-07-18 18:09:16 +00:00
|
|
|
if (next) {
|
|
|
|
effect++;
|
2019-08-02 21:18:01 +00:00
|
|
|
if (effect > 10) {
|
|
|
|
effect = 0;
|
|
|
|
}
|
2019-07-18 18:09:16 +00:00
|
|
|
} else {
|
|
|
|
effect--;
|
2019-08-02 21:18:01 +00:00
|
|
|
if (effect < 0) {
|
|
|
|
effect = 10;
|
|
|
|
}
|
2019-07-18 18:09:16 +00:00
|
|
|
}
|
2019-07-02 16:34:45 +00:00
|
|
|
switch (effect)
|
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
matrix.None();
|
|
|
|
strip.Scanner(strip.Color(255, 0, 0), 40, true, true);
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
matrix.None();
|
|
|
|
strip.Scanner(strip.Color(255, 0, 0));
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
matrix.None();
|
|
|
|
strip.Scanner(strip.Color(255, 0, 0), 40, true);
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
matrix.None();
|
|
|
|
strip.Scanner(strip.Color(255, 0, 0), 40, true, true);
|
|
|
|
break;
|
|
|
|
case 4:
|
|
|
|
matrix.None();
|
|
|
|
strip.RainbowCycle(50);
|
|
|
|
break;
|
|
|
|
case 5:
|
|
|
|
matrix.None();
|
|
|
|
strip.TheaterChase(strip.Color(255, 0, 0), strip.Color(0, 0, 255), 100);
|
|
|
|
break;
|
|
|
|
case 6:
|
|
|
|
matrix.None();
|
|
|
|
strip.Fade(strip.Color(255, 0, 0), strip.Color(0, 0, 255), 200, 100);
|
|
|
|
break;
|
|
|
|
case 7:
|
|
|
|
matrix.None();
|
|
|
|
strip.RandomFade();
|
|
|
|
break;
|
|
|
|
case 8:
|
|
|
|
matrix.None();
|
|
|
|
strip.Smooth(16, 80, 50, 40);
|
|
|
|
break;
|
|
|
|
case 9:
|
|
|
|
matrix.None();
|
|
|
|
strip.Plasma();
|
|
|
|
break;
|
|
|
|
case 10:
|
|
|
|
strip.None();
|
|
|
|
matrix.ScrollText("CTDO");
|
|
|
|
break;
|
2019-08-02 21:18:01 +00:00
|
|
|
}
|
2019-07-02 16:34:45 +00:00
|
|
|
}
|
|
|
|
|
2019-07-18 18:09:16 +00:00
|
|
|
|
|
|
|
bool onSetCommand(const HomieRange& range, const String& value) {
|
|
|
|
if (value == "next")
|
|
|
|
{
|
|
|
|
NextPrev(true);
|
|
|
|
} else if (value == "prev") {
|
|
|
|
NextPrev(false);
|
|
|
|
} else if (value == "darker") {
|
|
|
|
curBrightness -= 40;
|
2019-08-02 21:18:01 +00:00
|
|
|
if (curBrightness < 0) {
|
|
|
|
curBrightness = 0;
|
|
|
|
}
|
2019-07-18 18:09:16 +00:00
|
|
|
setBrightness(curBrightness);
|
|
|
|
} else if (value == "brighter") {
|
|
|
|
curBrightness += 40;
|
2019-08-02 21:18:01 +00:00
|
|
|
if (curBrightness > 255) {
|
|
|
|
curBrightness = 255;
|
|
|
|
}
|
2019-07-18 18:09:16 +00:00
|
|
|
setBrightness(curBrightness);
|
|
|
|
} else if (value == "toggle") {
|
2019-08-02 21:18:01 +00:00
|
|
|
if (curBrightness > 0) {
|
|
|
|
curBrightness = 0;
|
|
|
|
} else {
|
|
|
|
curBrightness = 255;
|
|
|
|
}
|
2019-07-18 18:09:16 +00:00
|
|
|
setBrightness(curBrightness);
|
|
|
|
}
|
|
|
|
homieNode.setProperty("command").send(value);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2017-07-05 00:05:34 +00:00
|
|
|
void setup() {
|
|
|
|
Serial.begin(115200);
|
|
|
|
|
2019-07-18 18:09:16 +00:00
|
|
|
Homie_setFirmware("pixelbox", "1.2.0");
|
2017-07-05 00:05:34 +00:00
|
|
|
Homie.setLoopFunction(loopHandler);
|
|
|
|
|
|
|
|
homieNode.advertiseRange("pixel", 0, NUMPIXELS - 1).settable(onSetPixel);
|
|
|
|
homieNode.advertiseRange("color", 0, 1).settable(onSetColor);
|
|
|
|
homieNode.advertise("brightness").settable(onSetBrightness);
|
|
|
|
homieNode.advertise("effect").settable(onSetEffect);
|
|
|
|
homieNode.advertise("clear").settable(onSetClear);
|
|
|
|
homieNode.advertise("length").settable(onSetLength);
|
|
|
|
homieNode.advertise("icon").settable(onSetIcon);
|
2019-07-18 18:09:16 +00:00
|
|
|
homieNode.advertise("command").settable(onSetCommand);
|
2018-12-06 23:38:15 +00:00
|
|
|
homieNode.advertiseRange("pixels", 0, (NUMPIXELS - 1) * 7).settable(onSetPixels);
|
2019-08-02 21:18:01 +00:00
|
|
|
homieNode.advertiseRange("vu", 0, sqrt(NUMPIXELS) - 1).settable(onSetVU);
|
2017-07-05 00:05:34 +00:00
|
|
|
|
|
|
|
strip.begin();
|
|
|
|
strip.clear();
|
|
|
|
// strip.setBrightness(64);
|
2019-03-17 17:15:02 +00:00
|
|
|
strip.setBrightness(255); // HEEELLLLLLL :)
|
|
|
|
// strip.setBrightness(10); // DEBUG!
|
2017-07-05 00:05:34 +00:00
|
|
|
strip.show();
|
|
|
|
stopAfterCompletion = false; // Default
|
2019-07-02 16:34:45 +00:00
|
|
|
effect = 0;
|
2017-07-05 00:05:34 +00:00
|
|
|
|
2019-03-17 17:15:02 +00:00
|
|
|
Homie.setup();
|
|
|
|
|
2019-07-18 18:09:16 +00:00
|
|
|
ArduinoOTA.setHostname("pixelbox");
|
2017-07-05 00:05:34 +00:00
|
|
|
ArduinoOTA.onStart([]() {
|
|
|
|
strip.clear();
|
|
|
|
strip.setBrightness(64);
|
|
|
|
});
|
|
|
|
ArduinoOTA.onEnd([]() {
|
|
|
|
strip.clear();
|
|
|
|
});
|
|
|
|
ArduinoOTA.onProgress([](unsigned int progress, unsigned int total) {
|
|
|
|
strip.setPixelColor(progress / (total / NUMPIXELS), strip.Color(100, 0, 0));
|
|
|
|
strip.show();
|
|
|
|
});
|
|
|
|
ArduinoOTA.begin();
|
2018-12-06 23:38:15 +00:00
|
|
|
matrix.begin();
|
|
|
|
matrix.setTextWrap(false);
|
2019-03-17 17:15:02 +00:00
|
|
|
matrix.setBrightness(255);
|
2019-07-18 18:09:16 +00:00
|
|
|
|
|
|
|
strip.Plasma(); // Default effect
|
2019-08-02 21:18:01 +00:00
|
|
|
Udp.begin(localUdpPort);
|
|
|
|
|
2017-07-05 00:05:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void loop() {
|
|
|
|
Homie.loop();
|
|
|
|
ArduinoOTA.handle();
|
2019-08-02 21:18:01 +00:00
|
|
|
//UDP
|
|
|
|
int packetSize = Udp.parsePacket();
|
|
|
|
if (packetSize)
|
|
|
|
{
|
|
|
|
// receive incoming UDP packets
|
|
|
|
// Serial.printf("Received %d bytes from %s, port %d\n", packetSize, Udp.remoteIP().toString().c_str(), Udp.remotePort());
|
|
|
|
int len = Udp.read(incomingPacket, 255);
|
|
|
|
if (len > 0)
|
|
|
|
{
|
|
|
|
// Serial.printf("Size: %d", len);
|
|
|
|
if (len == 192)
|
|
|
|
{
|
|
|
|
// Serial.printf("UDP packet contents: %s\n", incomingPacket);
|
|
|
|
int i = 0;
|
|
|
|
// Kein Effekt
|
|
|
|
strip.Stop();
|
|
|
|
for (int i=0; i<193; i=i+3)
|
|
|
|
{
|
|
|
|
// Serial.printf("Pixel %d to R %d - G %d - B %d\n", i/3, incomingPacket[i], incomingPacket[i+1], incomingPacket[i+2]);
|
|
|
|
strip.setPixelColor(strip.numToPos(i/3), incomingPacket[i], incomingPacket[i+1], incomingPacket[i+2]);
|
|
|
|
}
|
|
|
|
strip.show();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
//uint16_t data=incomingPacket[0]<<8 | incomingPacket[1];
|
|
|
|
|
|
|
|
//printBinary(mapData(data));
|
|
|
|
//shiftRelais(mapData(data));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2017-07-05 00:05:34 +00:00
|
|
|
}
|