Textscroller - läuft noch falschrum, aber der Zwischenzustand ist wert, eingecheckt zu werden. :)
This commit is contained in:
parent
fab3b693aa
commit
a1e273a248
156
NeoPatterns.cpp
156
NeoPatterns.cpp
|
@ -491,39 +491,146 @@ void NeoPatterns::Text(String text, uint8_t interval)
|
||||||
ActivePattern = TEXT;
|
ActivePattern = TEXT;
|
||||||
Interval = interval;
|
Interval = interval;
|
||||||
// textlength*8
|
// textlength*8
|
||||||
TotalSteps = text.length()*8;
|
TotalSteps = (text.length()-1 ) * 9;
|
||||||
Index = TotalSteps;
|
Index = TotalSteps;
|
||||||
|
// Index = 0;
|
||||||
Text1 = text;
|
Text1 = text;
|
||||||
// FontChar = fontchar;
|
// FontChar = fontchar;
|
||||||
Direction = REVERSE;
|
Direction = REVERSE;
|
||||||
Color1 = 255*255*255;
|
Color1 = 16711680;
|
||||||
textposition = 0;
|
textposition = 0;
|
||||||
|
// charposition = 0;
|
||||||
charposition = 0;
|
charposition = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void NeoPatterns::TextUpdate()
|
void NeoPatterns::TextUpdate()
|
||||||
{
|
{
|
||||||
|
/*
|
||||||
|
uint8_t _r = (uint8_t)(Color1 >> 16);
|
||||||
|
uint8_t _g = (uint8_t)(Color1 >> 8);
|
||||||
|
uint8_t _b = (uint8_t)Color1;
|
||||||
|
Direction = FORWARD;
|
||||||
|
Serial.println(Index);
|
||||||
|
setPixelColor(xyToSimplePos(0,Index), Color(100, 0, 0));
|
||||||
|
TotalSteps = 8;
|
||||||
|
Increment();
|
||||||
|
show();
|
||||||
|
return;
|
||||||
|
*/
|
||||||
|
|
||||||
// textposition++;
|
// textposition++;
|
||||||
|
uint8_t FontChar = Text1[textposition];
|
||||||
|
uint8_t FontCharNext = Text1[textposition + 1];
|
||||||
|
|
||||||
|
// This will only work for 8*8-Pixel Displays, 64 Pixels
|
||||||
|
// The pixel 0,0 is on the lower right (the control access is there)
|
||||||
|
|
||||||
|
// textposition: position within text
|
||||||
|
// charposition: position of the current ("textposition") character, what is being shown of "this" character
|
||||||
|
int charx = 0;
|
||||||
|
|
||||||
|
// Walk through the whole matrix and display the matching pixel of the character which is supposed to be on charposition
|
||||||
|
|
||||||
|
// _ _ _
|
||||||
|
// _ _ _
|
||||||
|
// _ _ _
|
||||||
|
//
|
||||||
|
// I _ _
|
||||||
|
// I _ _
|
||||||
|
// I _ _
|
||||||
|
//
|
||||||
|
// _ I _
|
||||||
|
// _ I _
|
||||||
|
// _ I _
|
||||||
|
//
|
||||||
|
// 2,2 1,2 0,2
|
||||||
|
// 2,1 1,1 0,1
|
||||||
|
// 2,0 1,0 0,0
|
||||||
|
//
|
||||||
|
// 8 7 6
|
||||||
|
// 3 4 5
|
||||||
|
// 2 1 0
|
||||||
|
//
|
||||||
|
|
||||||
|
clear();
|
||||||
|
for (int x = 0; x < 8; x++) {
|
||||||
|
//charx = 8 - x;
|
||||||
|
for (int y = 0; y < 8; y++) {
|
||||||
|
int currentpos = xyToSimplePos(x,y);
|
||||||
|
// if (charx > charposition) {
|
||||||
|
// x > 8-charposition
|
||||||
|
if (8-x>charposition) {
|
||||||
|
// Display the first character
|
||||||
|
uint64_t mask = 1LL << (uint64_t)charxyToPos(charposition+x, y);
|
||||||
|
Serial.print(".");
|
||||||
|
Serial.print(charposition+x);
|
||||||
|
Serial.print("=");
|
||||||
|
Serial.print(charxyToPos(charposition+x, y));
|
||||||
|
if ( (font[FontChar]&mask) == 0) {
|
||||||
|
setPixelColor(currentpos, Color(0, 0, 100)); //bit is 0 at pos i
|
||||||
|
} else {
|
||||||
|
uint8_t _r = (uint8_t)(Color1 >> 16);
|
||||||
|
uint8_t _g = (uint8_t)(Color1 >> 8);
|
||||||
|
uint8_t _b = (uint8_t)Color1;
|
||||||
|
setPixelColor(currentpos, Color(_r, _g, _b)); //bit is 1 at pos i
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// Display the second character
|
||||||
|
uint64_t mask = 1LL << (uint64_t)charxyToPos(charposition+x-9, y);
|
||||||
|
if ( (font[FontCharNext]&mask) == 0) {
|
||||||
|
setPixelColor(currentpos, Color(0, 100, 0)); //bit is 0 at pos i
|
||||||
|
} else {
|
||||||
|
uint8_t _r = (uint8_t)(Color1 >> 16);
|
||||||
|
uint8_t _g = (uint8_t)(Color1 >> 8);
|
||||||
|
uint8_t _b = (uint8_t)Color1;
|
||||||
|
setPixelColor(currentpos, Color(_r, _g, _b)); //bit is 1 at pos i
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Serial.println();
|
||||||
|
|
||||||
|
/*
|
||||||
|
// First char
|
||||||
|
for (int x = 0; x < 8-charposition; x++) { // Scroll the first char from right to left
|
||||||
|
for (int y = 0; y < 8; y++) {
|
||||||
|
uint64_t mask = 1LL << (uint64_t)charxyToPos(x, y);
|
||||||
|
if ( (font[FontChar]&mask) == 0) {
|
||||||
|
setPixelColor(xyToSimplePos(x, y), Color(0, 0, 100)); //bit is 0 at pos i
|
||||||
|
} else {
|
||||||
|
uint8_t _r = (uint8_t)(Color1 >> 16);
|
||||||
|
uint8_t _g = (uint8_t)(Color1 >> 8);
|
||||||
|
uint8_t _b = (uint8_t)Color1;
|
||||||
|
setPixelColor(xyToSimplePos(x, y), Color(_r, _g, _b)); //bit is 1 at pos i
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Second char
|
||||||
|
for (int x = 8-charposition; x < 8; x++) {
|
||||||
|
for (int y = 0; y < 8; y++) {
|
||||||
|
uint64_t mask = 1LL << (uint64_t)charxyToPos(x, y);
|
||||||
|
// uint64_t mask = 1LL << (uint64_t)(x+y);
|
||||||
|
if ( (font[FontCharNext]&mask) == 0) {
|
||||||
|
setPixelColor(xyToSimplePos(x, y), Color(0, 100, 0)); //bit is 0 at pos i
|
||||||
|
} else {
|
||||||
|
uint8_t _r = (uint8_t)(Color1 >> 16);
|
||||||
|
uint8_t _g = (uint8_t)(Color1 >> 8);
|
||||||
|
uint8_t _b = (uint8_t)Color1;
|
||||||
|
setPixelColor(xyToSimplePos(x, y), Color(_r, _g, _b)); //bit is 1 at pos i
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
show();
|
||||||
|
|
||||||
charposition++;
|
charposition++;
|
||||||
if (charposition == 9)
|
if (charposition == 9)
|
||||||
{
|
{
|
||||||
charposition = 0;
|
charposition = 0;
|
||||||
textposition++;
|
textposition++;
|
||||||
}
|
}
|
||||||
uint8_t FontChar = Text1[textposition];
|
|
||||||
|
|
||||||
for (int i = 0; i < numPixels(); i++) {
|
|
||||||
uint64_t mask = 1LL << (uint64_t)i;
|
|
||||||
if ( (font[FontChar]&mask) == 0) {
|
|
||||||
setPixelColor(numToPos(i), Color(0, 0, 0)); //bit is 0 at pos i
|
|
||||||
} else {
|
|
||||||
uint8_t _r = (uint8_t)(Color1 >> 16);
|
|
||||||
uint8_t _g = (uint8_t)(Color1 >> 8);
|
|
||||||
uint8_t _b = (uint8_t)Color1;
|
|
||||||
setPixelColor(numToPos(i), Color(_r, _g, _b)); //bit is 1 at pos i
|
|
||||||
}
|
|
||||||
}
|
|
||||||
show();
|
|
||||||
Increment();
|
Increment();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -683,8 +790,8 @@ uint32_t NeoPatterns::Wheel(byte WheelPos)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Convert x y pixel position to matrix position
|
uint8_t NeoPatterns::xyToSimplePos(int x, int y) {
|
||||||
uint8_t NeoPatterns::xyToPos(int x, int y) {
|
// Alternating rows
|
||||||
if (y % 2 == 0) {
|
if (y % 2 == 0) {
|
||||||
return (y * 8 + x);
|
return (y * 8 + x);
|
||||||
} else {
|
} else {
|
||||||
|
@ -692,6 +799,19 @@ uint8_t NeoPatterns::xyToPos(int x, int y) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Convert x y pixel position to matrix position
|
||||||
|
uint8_t NeoPatterns::xyToPos(int x, int y) {
|
||||||
|
if (y % 2 == 0) {
|
||||||
|
return (x + (y * 8));
|
||||||
|
} else {
|
||||||
|
return ((7 - x) + (y * 8));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t NeoPatterns::charxyToPos(int x, int y) {
|
||||||
|
return (y * 8 + x);
|
||||||
|
}
|
||||||
|
|
||||||
//convert pixel number to actual 8x8 matrix position
|
//convert pixel number to actual 8x8 matrix position
|
||||||
uint8_t NeoPatterns::numToPos(int num) {
|
uint8_t NeoPatterns::numToPos(int num) {
|
||||||
int x = num % 8;
|
int x = num % 8;
|
||||||
|
|
|
@ -53,6 +53,8 @@ class NeoPatterns : public Adafruit_NeoPixel
|
||||||
uint32_t Wheel(byte WheelPos);
|
uint32_t Wheel(byte WheelPos);
|
||||||
uint8_t numToSpiralPos(int num);
|
uint8_t numToSpiralPos(int num);
|
||||||
uint8_t xyToPos(int x, int y);
|
uint8_t xyToPos(int x, int y);
|
||||||
|
uint8_t xyToSimplePos(int x, int y);
|
||||||
|
uint8_t charxyToPos(int x, int y);
|
||||||
uint8_t numToPos(int num);
|
uint8_t numToPos(int num);
|
||||||
uint8_t getAverage(uint8_t array[], uint8_t i, int x, int y);
|
uint8_t getAverage(uint8_t array[], uint8_t i, int x, int y);
|
||||||
uint32_t parseColor(String value);
|
uint32_t parseColor(String value);
|
||||||
|
|
|
@ -163,7 +163,7 @@ bool onSetIcon(const HomieRange& range, const String& value) {
|
||||||
|
|
||||||
bool onSetText(const HomieRange& range, const String& value) {
|
bool onSetText(const HomieRange& range, const String& value) {
|
||||||
stopAfterCompletion = true;
|
stopAfterCompletion = true;
|
||||||
strip.Text(value);
|
strip.Text(" " + value + " ", 500);
|
||||||
homieNode.setProperty("text").send(value);
|
homieNode.setProperty("text").send(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue