Umbenennung intern zu pixelbox, Matrix hinzugefügt, Text-Scrolleffekt hinzugefügt
This commit is contained in:
parent
51d621526b
commit
9275db4e3c
|
@ -1,15 +1,37 @@
|
|||
#include <Homie.h>
|
||||
// https://github.com/adafruit/Adafruit_NeoMatrix // Adafruit_GFX.h
|
||||
#include "Adafruit_NeoMatrix.h"
|
||||
#include <Adafruit_GFX.h>
|
||||
#include <Adafruit_NeoPixel.h>
|
||||
|
||||
#include <ArduinoOTA.h>
|
||||
#include "NeoPatterns.h"
|
||||
#ifdef __AVR__
|
||||
#include <avr/power.h>
|
||||
#endif
|
||||
|
||||
#define PIN D2 //data pin for ws2812 (pixelprojektor @ ctdo: PIN 2) // Für pixelpad: Pin2
|
||||
#define PIN D2 //data pin for ws2812 (pixelbox @ ctdo: PIN 2) // Für pixelpad: Pin2
|
||||
#define NUMPIXELS 64
|
||||
|
||||
NeoPatterns strip = NeoPatterns(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800, &StripComplete);
|
||||
/*
|
||||
Adafruit_NeoMatrix matrix = Adafruit_NeoMatrix(8, 8, PIN,
|
||||
NEO_MATRIX_TOP + NEO_MATRIX_LEFT +
|
||||
NEO_MATRIX_COLUMNS + NEO_MATRIX_ZIGZAG,
|
||||
NEO_GRB + NEO_GRB + NEO_KHZ800);
|
||||
*/
|
||||
|
||||
Adafruit_NeoMatrix matrix = Adafruit_NeoMatrix(8, 8, PIN,
|
||||
NEO_MATRIX_BOTTOM + NEO_MATRIX_LEFT +
|
||||
NEO_MATRIX_COLUMNS + NEO_MATRIX_ZIGZAG,
|
||||
NEO_GRB + NEO_KHZ800);
|
||||
|
||||
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;
|
||||
|
||||
bool stopAfterCompletion;
|
||||
|
||||
|
@ -23,7 +45,6 @@ void StripComplete() {
|
|||
|
||||
HomieNode homieNode("pixel", "commands");
|
||||
|
||||
|
||||
bool onSetColor(const HomieRange& range, const String& value) {
|
||||
if (!range.isRange || range.index < 0 || range.index > 1) {
|
||||
return false;
|
||||
|
@ -61,7 +82,9 @@ bool onSetBrightness(const HomieRange& range, const String& value) {
|
|||
return false;
|
||||
}
|
||||
strip.setBrightness(brightness);
|
||||
matrix.setBrightness(brightness);
|
||||
strip.show();
|
||||
matrix.show();
|
||||
homieNode.setProperty("brightness").send(value);
|
||||
}
|
||||
|
||||
|
@ -96,7 +119,48 @@ bool onSetPixels(const HomieRange& range, const String& value) {
|
|||
bool onSetEffect(const HomieRange& range, const String& value) {
|
||||
stopAfterCompletion = false;
|
||||
String effect = value;
|
||||
String firstfourbytes;
|
||||
if (value.length() > 3)
|
||||
{
|
||||
firstfourbytes = value.substring(0,4);
|
||||
} else {
|
||||
firstfourbytes = value;
|
||||
}
|
||||
effect.toLowerCase();
|
||||
|
||||
if (firstfourbytes == "text") {
|
||||
int sep = value.indexOf("|");
|
||||
if (sep > 0) {
|
||||
// Parameter given: Acceptable text command
|
||||
// Deactivate NeoPattern
|
||||
strip.None();
|
||||
String command = value.substring(0, sep);
|
||||
String parameters = value.substring(sep+1);
|
||||
|
||||
int sep2 = parameters.indexOf("|");
|
||||
if (sep2 > 0) {
|
||||
// Interval was given
|
||||
String stext = parameters.substring(0, sep2);
|
||||
String sinterval = parameters.substring(sep2 + 1).toInt();
|
||||
|
||||
int sep3 = sinterval.indexOf("|");
|
||||
if (sep3 > 0) {
|
||||
// Color was given
|
||||
int iinterval = sinterval.substring(0, sep3).toInt();
|
||||
String scolor = sinterval.substring(sep3 + 1);
|
||||
matrix.ScrollText(stext, iinterval, scolor);
|
||||
} else {
|
||||
int iinterval = parameters.substring(sep2 + 1).toInt();
|
||||
matrix.ScrollText(stext, iinterval);
|
||||
|
||||
}
|
||||
} else {
|
||||
matrix.ScrollText(parameters);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// Deactivate Matrix
|
||||
matrix.None();
|
||||
if (effect == "scanner") {
|
||||
strip.Scanner(strip.Color(255, 0, 0));
|
||||
}
|
||||
|
@ -147,6 +211,7 @@ bool onSetEffect(const HomieRange& range, const String& value) {
|
|||
strip.None();
|
||||
}
|
||||
}
|
||||
}
|
||||
homieNode.setProperty("effect").send(value);
|
||||
}
|
||||
|
||||
|
@ -161,13 +226,6 @@ bool onSetIcon(const HomieRange& range, const String& value) {
|
|||
homieNode.setProperty("icon").send(value);
|
||||
}
|
||||
|
||||
bool onSetText(const HomieRange& range, const String& value) {
|
||||
stopAfterCompletion = true;
|
||||
strip.Text(" " + value + " ", 500);
|
||||
homieNode.setProperty("text").send(value);
|
||||
}
|
||||
|
||||
|
||||
bool onSetClear(const HomieRange& range, const String& value) {
|
||||
strip.None();
|
||||
strip.clear();
|
||||
|
@ -188,19 +246,19 @@ bool onSetLength(const HomieRange& range, const String& value) {
|
|||
|
||||
void loopHandler() {
|
||||
strip.Update();
|
||||
matrix.Update();
|
||||
}
|
||||
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
|
||||
Homie_setFirmware("pixelprojektor", "1.0.0");
|
||||
Homie_setFirmware("pixelbox", "1.1.0");
|
||||
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("text").settable(onSetText);
|
||||
homieNode.advertise("clear").settable(onSetClear);
|
||||
homieNode.advertise("length").settable(onSetLength);
|
||||
homieNode.advertise("icon").settable(onSetIcon);
|
||||
|
@ -215,9 +273,9 @@ void setup() {
|
|||
strip.setBrightness(10); // DEBUG!
|
||||
strip.show();
|
||||
stopAfterCompletion = false; // Default
|
||||
// strip.Plasma(); // Default effect
|
||||
strip.Plasma(); // Default effect
|
||||
|
||||
ArduinoOTA.setHostname("pixelprojektor");
|
||||
ArduinoOTA.setHostname("pixelbox");
|
||||
ArduinoOTA.onStart([]() {
|
||||
strip.clear();
|
||||
strip.setBrightness(64);
|
||||
|
@ -230,6 +288,9 @@ void setup() {
|
|||
strip.show();
|
||||
});
|
||||
ArduinoOTA.begin();
|
||||
matrix.begin();
|
||||
matrix.setTextWrap(false);
|
||||
matrix.setBrightness(32);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
|
|
Loading…
Reference in New Issue