Farbiger Text

This commit is contained in:
starcalc 2019-03-17 18:14:00 +01:00
parent fc4c478c30
commit 716ce0c076
2 changed files with 25 additions and 14 deletions

View File

@ -214,27 +214,23 @@ void Adafruit_NeoMatrix::setRemapFunction(uint16_t (*fn)(uint16_t, uint16_t)) {
void Adafruit_NeoMatrix::Update() { void Adafruit_NeoMatrix::Update() {
if (active) if (active)
{ {
if ((millis() - lastUpdate) > Interval) // time to update unsigned long current = millis();
if ((current - lastUpdate) > Interval) // time to update
{ {
lastUpdate = millis(); Serial.print(current);
// Next Interval step for text scroll
Serial.print(scrolltextpos);
Serial.print(" - "); Serial.print(" - ");
Serial.println((8 * scrolltext.length() + 10)); Serial.println(lastUpdate);
lastUpdate = millis();
// Next Interval step for text scroll
scrolltextpos--; scrolltextpos--;
int16_t maxpos = 8 * scrolltext.length() + 10; int16_t maxpos = 8 * scrolltext.length() + 10;
if (scrolltextpos < -(maxpos)) { if (scrolltextpos < -(maxpos)) {
Serial.println();
Serial.print(scrolltextpos);
Serial.print(" is smaller than: ");
Serial.println(-(maxpos));
scrolltextpos = width(); scrolltextpos = width();
} }
fillScreen(0); fillScreen(0);
setCursor(scrolltextpos, 0); setCursor(scrolltextpos, 0);
print(scrolltext); print(scrolltext);
show(); show();
} else { } else {
delay(1); delay(1);
} }
@ -242,13 +238,13 @@ void Adafruit_NeoMatrix::Update() {
} }
void Adafruit_NeoMatrix::ScrollText(String text, uint16_t interval, String color) { void Adafruit_NeoMatrix::ScrollText(String text, uint16_t interval, String color) {
Serial.print("Scrolltext triggered: ");
Serial.println(text);
active = true; active = true;
Interval = interval; Interval = interval;
scrolltext = text; scrolltext = text;
scrolltextpos = width(); scrolltextpos = width();
setTextColor(parseColor(color));
fillScreen(0); fillScreen(0);
// set Text Color
setCursor(scrolltextpos, 0); setCursor(scrolltextpos, 0);
print(scrolltext); print(scrolltext);
if (--scrolltextpos < -(5 * scrolltext.length() + 10)) { 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() { void Adafruit_NeoMatrix::None() {
active = false; 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;
}

View File

@ -86,11 +86,13 @@ class Adafruit_NeoMatrix : public Adafruit_GFX, public Adafruit_NeoPixel {
setRemapFunction(uint16_t (*fn)(uint16_t, uint16_t)), setRemapFunction(uint16_t (*fn)(uint16_t, uint16_t)),
Update(), Update(),
None(), None(),
ScrollText(String text, uint16_t Interval = 60, String color); ScrollText(String text, uint16_t Interval = 60, String color = "#FFFFFF");
static uint16_t static uint16_t
Color(uint8_t r, uint8_t g, uint8_t b); Color(uint8_t r, uint8_t g, uint8_t b);
uint32_t parseColor(String value);
boolean active = false; boolean active = false;
private: private:
@ -108,7 +110,7 @@ class Adafruit_NeoMatrix : public Adafruit_GFX, public Adafruit_NeoPixel {
int16_t scrolltextpos; int16_t scrolltextpos;
uint16_t Interval; // milliseconds between updates uint16_t Interval; // milliseconds between updates
uint16_t lastUpdate; // last update of position unsigned long lastUpdate; // last update of position
}; };