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() {
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;
}

View File

@ -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
};