Umbenennung intern zu pixelbox, Matrix hinzugefügt, Text-Scrolleffekt hinzugefügt

This commit is contained in:
starcalc 2018-12-07 00:38:15 +01:00
parent 51d621526b
commit 9275db4e3c
1 changed files with 119 additions and 58 deletions

View File

@ -1,15 +1,37 @@
#include <Homie.h> #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 <Adafruit_NeoPixel.h>
#include <ArduinoOTA.h> #include <ArduinoOTA.h>
#include "NeoPatterns.h" #include "NeoPatterns.h"
#ifdef __AVR__ #ifdef __AVR__
#include <avr/power.h> #include <avr/power.h>
#endif #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 #define NUMPIXELS 64
NeoPatterns strip = NeoPatterns(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800, &StripComplete); 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; bool stopAfterCompletion;
@ -23,7 +45,6 @@ void StripComplete() {
HomieNode homieNode("pixel", "commands"); HomieNode homieNode("pixel", "commands");
bool onSetColor(const HomieRange& range, const String& value) { bool onSetColor(const HomieRange& range, const String& value) {
if (!range.isRange || range.index < 0 || range.index > 1) { if (!range.isRange || range.index < 0 || range.index > 1) {
return false; return false;
@ -61,7 +82,9 @@ bool onSetBrightness(const HomieRange& range, const String& value) {
return false; return false;
} }
strip.setBrightness(brightness); strip.setBrightness(brightness);
matrix.setBrightness(brightness);
strip.show(); strip.show();
matrix.show();
homieNode.setProperty("brightness").send(value); homieNode.setProperty("brightness").send(value);
} }
@ -96,55 +119,97 @@ bool onSetPixels(const HomieRange& range, const String& value) {
bool onSetEffect(const HomieRange& range, const String& value) { bool onSetEffect(const HomieRange& range, const String& value) {
stopAfterCompletion = false; stopAfterCompletion = false;
String effect = value; String effect = value;
String firstfourbytes;
if (value.length() > 3)
{
firstfourbytes = value.substring(0,4);
} else {
firstfourbytes = value;
}
effect.toLowerCase(); effect.toLowerCase();
if (effect == "scanner") {
strip.Scanner(strip.Color(255, 0, 0)); if (firstfourbytes == "text") {
}
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();
}
else {
// Test whether command with parameters was sent
int sep = value.indexOf("|"); int sep = value.indexOf("|");
String command = value.substring(0, sep); if (sep > 0) {
String parameters = value.substring(sep + 1); // Parameter given: Acceptable text command
if (command.equals("fill")) { // Deactivate NeoPattern
strip.ColorSetParameters(parameters); strip.None();
} String command = value.substring(0, sep);
else if (command.equals("randomfade")) { String parameters = value.substring(sep+1);
int sepparam = parameters.indexOf("|");
int p1 = parameters.substring(0, sepparam).toInt(); int sep2 = parameters.indexOf("|");
if (p1 <= 0) { if (sep2 > 0) {
p1 = 5; // 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);
} }
strip.RandomFadeSingle(p1); }
} 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();
} }
else { else {
strip.None(); // 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();
}
} }
} }
homieNode.setProperty("effect").send(value); homieNode.setProperty("effect").send(value);
@ -161,13 +226,6 @@ bool onSetIcon(const HomieRange& range, const String& value) {
homieNode.setProperty("icon").send(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) { bool onSetClear(const HomieRange& range, const String& value) {
strip.None(); strip.None();
strip.clear(); strip.clear();
@ -188,23 +246,23 @@ bool onSetLength(const HomieRange& range, const String& value) {
void loopHandler() { void loopHandler() {
strip.Update(); strip.Update();
matrix.Update();
} }
void setup() { void setup() {
Serial.begin(115200); Serial.begin(115200);
Homie_setFirmware("pixelprojektor", "1.0.0"); Homie_setFirmware("pixelbox", "1.1.0");
Homie.setLoopFunction(loopHandler); Homie.setLoopFunction(loopHandler);
homieNode.advertiseRange("pixel", 0, NUMPIXELS - 1).settable(onSetPixel); homieNode.advertiseRange("pixel", 0, NUMPIXELS - 1).settable(onSetPixel);
homieNode.advertiseRange("color", 0, 1).settable(onSetColor); homieNode.advertiseRange("color", 0, 1).settable(onSetColor);
homieNode.advertise("brightness").settable(onSetBrightness); homieNode.advertise("brightness").settable(onSetBrightness);
homieNode.advertise("effect").settable(onSetEffect); homieNode.advertise("effect").settable(onSetEffect);
homieNode.advertise("text").settable(onSetText);
homieNode.advertise("clear").settable(onSetClear); homieNode.advertise("clear").settable(onSetClear);
homieNode.advertise("length").settable(onSetLength); homieNode.advertise("length").settable(onSetLength);
homieNode.advertise("icon").settable(onSetIcon); homieNode.advertise("icon").settable(onSetIcon);
homieNode.advertiseRange("pixels", 0, (NUMPIXELS - 1)*7).settable(onSetPixels); homieNode.advertiseRange("pixels", 0, (NUMPIXELS - 1) * 7).settable(onSetPixels);
Homie.setup(); Homie.setup();
@ -215,9 +273,9 @@ void setup() {
strip.setBrightness(10); // DEBUG! strip.setBrightness(10); // DEBUG!
strip.show(); strip.show();
stopAfterCompletion = false; // Default stopAfterCompletion = false; // Default
// strip.Plasma(); // Default effect strip.Plasma(); // Default effect
ArduinoOTA.setHostname("pixelprojektor"); ArduinoOTA.setHostname("pixelbox");
ArduinoOTA.onStart([]() { ArduinoOTA.onStart([]() {
strip.clear(); strip.clear();
strip.setBrightness(64); strip.setBrightness(64);
@ -230,6 +288,9 @@ void setup() {
strip.show(); strip.show();
}); });
ArduinoOTA.begin(); ArduinoOTA.begin();
matrix.begin();
matrix.setTextWrap(false);
matrix.setBrightness(32);
} }
void loop() { void loop() {