From 716ce0c0762937e8bf77659ee6e19254bd2a4558 Mon Sep 17 00:00:00 2001 From: starcalc Date: Sun, 17 Mar 2019 18:14:00 +0100 Subject: [PATCH] Farbiger Text --- Adafruit_NeoMatrix.cpp | 33 +++++++++++++++++++++------------ Adafruit_NeoMatrix.h | 6 ++++-- 2 files changed, 25 insertions(+), 14 deletions(-) diff --git a/Adafruit_NeoMatrix.cpp b/Adafruit_NeoMatrix.cpp index 82860a2..1007533 100644 --- a/Adafruit_NeoMatrix.cpp +++ b/Adafruit_NeoMatrix.cpp @@ -214,27 +214,23 @@ void Adafruit_NeoMatrix::setRemapFunction(uint16_t (*fn)(uint16_t, uint16_t)) { void Adafruit_NeoMatrix::Update() { if (active) { - if ((millis() - lastUpdate) > Interval) // time to update + unsigned long current = millis(); + if ((current - lastUpdate) > Interval) // time to update { - lastUpdate = millis(); - // Next Interval step for text scroll - Serial.print(scrolltextpos); + Serial.print(current); Serial.print(" - "); - Serial.println((8 * scrolltext.length() + 10)); + Serial.println(lastUpdate); + lastUpdate = millis(); + // Next Interval step for text scroll scrolltextpos--; int16_t maxpos = 8 * scrolltext.length() + 10; if (scrolltextpos < -(maxpos)) { - Serial.println(); - Serial.print(scrolltextpos); - Serial.print(" is smaller than: "); - Serial.println(-(maxpos)); scrolltextpos = width(); } fillScreen(0); setCursor(scrolltextpos, 0); print(scrolltext); show(); - } else { delay(1); } @@ -242,13 +238,13 @@ void Adafruit_NeoMatrix::Update() { } void Adafruit_NeoMatrix::ScrollText(String text, uint16_t interval, String color) { - Serial.print("Scrolltext triggered: "); - Serial.println(text); active = true; Interval = interval; scrolltext = text; scrolltextpos = width(); + setTextColor(parseColor(color)); fillScreen(0); + // set Text Color setCursor(scrolltextpos, 0); print(scrolltext); if (--scrolltextpos < -(5 * scrolltext.length() + 10)) { @@ -260,3 +256,16 @@ void Adafruit_NeoMatrix::ScrollText(String text, uint16_t interval, String color void Adafruit_NeoMatrix::None() { active = false; } + +uint32_t Adafruit_NeoMatrix::parseColor(String value) { + if (value.charAt(0) == '#') { //solid fill + String color = value.substring(1); + int number = (int) strtol( &color[0], NULL, 16); + // Split them up into r, g, b values + int r = number >> 16; + int g = number >> 8 & 0xFF; + int b = number & 0xFF; + return Color(r, g, b); + } + return 0; +} diff --git a/Adafruit_NeoMatrix.h b/Adafruit_NeoMatrix.h index e3778a6..2ac17f4 100644 --- a/Adafruit_NeoMatrix.h +++ b/Adafruit_NeoMatrix.h @@ -86,11 +86,13 @@ class Adafruit_NeoMatrix : public Adafruit_GFX, public Adafruit_NeoPixel { setRemapFunction(uint16_t (*fn)(uint16_t, uint16_t)), Update(), None(), - ScrollText(String text, uint16_t Interval = 60, String color); + ScrollText(String text, uint16_t Interval = 60, String color = "#FFFFFF"); static uint16_t Color(uint8_t r, uint8_t g, uint8_t b); + uint32_t parseColor(String value); + boolean active = false; private: @@ -108,7 +110,7 @@ class Adafruit_NeoMatrix : public Adafruit_GFX, public Adafruit_NeoPixel { int16_t scrolltextpos; uint16_t Interval; // milliseconds between updates - uint16_t lastUpdate; // last update of position + unsigned long lastUpdate; // last update of position };