Textscroller - läuft noch falschrum, aber der Zwischenzustand ist wert, eingecheckt zu werden. :)

This commit is contained in:
starcalc 2018-11-29 22:52:49 +01:00
parent fab3b693aa
commit a1e273a248
3 changed files with 147 additions and 25 deletions

View File

@ -305,7 +305,7 @@ void NeoPatterns::RandomBuffer()
void NeoPatterns::Random()
{
None(); // Stop all other effects
ActivePattern = RANDOM;
ActivePattern = RANDOM;
for (int i = 0; i < numPixels(); i++) {
setPixelColor(i, Wheel(random(0, 256)));
}
@ -471,7 +471,7 @@ void NeoPatterns::IconComplete()
Direction = SavedDirection;
PlasmaPhase = SavedPlasmaPhase;
PlasmaPhaseIncrement = SavedPlasmaPhaseIncrement;
PlasmaColorStretch = SavedPlasmaColorStretch;
PlasmaColorStretch = SavedPlasmaColorStretch;
}
/****************** Text ******************/
@ -491,39 +491,146 @@ void NeoPatterns::Text(String text, uint8_t interval)
ActivePattern = TEXT;
Interval = interval;
// textlength*8
TotalSteps = text.length()*8;
TotalSteps = (text.length()-1 ) * 9;
Index = TotalSteps;
// Index = 0;
Text1 = text;
// FontChar = fontchar;
Direction = REVERSE;
Color1 = 255*255*255;
textposition=0;
charposition=0;
Color1 = 16711680;
textposition = 0;
// charposition = 0;
charposition = 0;
}
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++;
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++;
if (charposition == 9)
{
charposition = 0;
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();
}
@ -538,7 +645,7 @@ void NeoPatterns::TextComplete()
Direction = SavedDirection;
PlasmaPhase = SavedPlasmaPhase;
PlasmaPhaseIncrement = SavedPlasmaPhaseIncrement;
PlasmaColorStretch = SavedPlasmaColorStretch;
PlasmaColorStretch = SavedPlasmaColorStretch;
}
@ -602,7 +709,7 @@ void NeoPatterns::PlasmaUpdate()
// Scale the color up to 0..7 . Max brightness is 7.
//strip.setPixelColor(col + (edge * row), strip.Color(color_4, 0, 0) );
setPixelColor(xyToPos(row, col), Color(color_1, color_2, color_3));
}
}
@ -683,8 +790,8 @@ uint32_t NeoPatterns::Wheel(byte WheelPos)
}
}
// Convert x y pixel position to matrix position
uint8_t NeoPatterns::xyToPos(int x, int y) {
uint8_t NeoPatterns::xyToSimplePos(int x, int y) {
// Alternating rows
if (y % 2 == 0) {
return (y * 8 + x);
} 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
uint8_t NeoPatterns::numToPos(int num) {
int x = num % 8;

View File

@ -53,6 +53,8 @@ class NeoPatterns : public Adafruit_NeoPixel
uint32_t Wheel(byte WheelPos);
uint8_t numToSpiralPos(int num);
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 getAverage(uint8_t array[], uint8_t i, int x, int y);
uint32_t parseColor(String value);

View File

@ -163,7 +163,7 @@ bool onSetIcon(const HomieRange& range, const String& value) {
bool onSetText(const HomieRange& range, const String& value) {
stopAfterCompletion = true;
strip.Text(value);
strip.Text(" " + value + " ", 500);
homieNode.setProperty("text").send(value);
}