Skip to content

Commit 8d89ed5

Browse files
Custom RC
Addition of the EFFECT_CUSTOM_RC return code option to identify when specific parts of a scrolling text message has been reached.
1 parent 106a178 commit 8d89ed5

File tree

3 files changed

+127
-13
lines changed

3 files changed

+127
-13
lines changed

LEDText.cpp

+14-7
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
LEDText V4 class by Aaron Liddiment (c) 2015
2+
LEDText V5 class by Aaron Liddiment (c) 2015
33
44
Uses my LEDMatrix class and especially the
55
@@ -133,7 +133,7 @@ void cLEDText::SetTextColrOptions(uint16_t Options, uint8_t ColA1, uint8_t ColA2
133133

134134
void cLEDText::SetFrameRate(uint8_t Rate)
135135
{
136-
m_FrameRate = Rate;
136+
m_FrameRate = Rate;
137137
}
138138

139139

@@ -167,16 +167,17 @@ void cLEDText::DecodeOptions(uint16_t *tp, uint16_t *opt, uint8_t *backDim, uint
167167
*tp += 1;
168168
break;
169169
case UC_FRAME_RATE:
170-
if ((m_XBitPos == 0) && (m_YBitPos == 0))
171-
m_FrameRate = (uint8_t)m_pText[*tp + 1];
170+
m_FrameRate = (uint8_t)m_pText[*tp + 1];
172171
*tp += 1;
173172
break;
174173
case UC_DELAY_FRAMES:
175-
if ( ((m_XBitPos == 0) && (m_YBitPos == 0)) && (m_LastDelayTP < *tp) )
174+
if (m_LastDelayTP < *tp)
176175
{
177176
m_LastDelayTP = *tp;
178177
m_DelayCounter = (m_pText[*tp + 1] << 8) + m_pText[*tp + 2];
179178
}
179+
else if ( (m_LastDelayTP == *tp) && (m_DelayCounter == 0) )
180+
m_LastDelayTP++;
180181
*tp += 2;
181182
break;
182183
case UC_CUSTOM_RC:
@@ -186,7 +187,7 @@ void cLEDText::DecodeOptions(uint16_t *tp, uint16_t *opt, uint8_t *backDim, uint
186187
*RC = m_pText[*tp + 1];
187188
}
188189
*tp += 1;
189-
break;
190+
break;
190191
case UC_CHAR_UP:
191192
case UC_CHAR_DOWN:
192193
case UC_CHAR_LEFT:
@@ -329,13 +330,19 @@ int cLEDText::UpdateText()
329330
uint16_t oldopt = opt;
330331
DecodeOptions(&tp, &opt, &bDim, c1, c2, &cDim, &RC);
331332
tp++;
332-
if ((m_Options & INSTANT_OPTIONS_MODE) == INSTANT_OPTIONS_MODE)
333+
if ( (tp == (m_LastDelayTP + 3)) && (m_DelayCounter > 0) )
334+
{ // Fix to stop processing codes until delay expired
335+
tp = m_pSize;
336+
x = m_XMax + 1;
337+
}
338+
else if ((m_Options & INSTANT_OPTIONS_MODE) == INSTANT_OPTIONS_MODE)
333339
opt = (opt & (~SCROLL_MASK)) | (oldopt & SCROLL_MASK);
334340
else if ((oldopt & SCROLL_MASK) != (opt & SCROLL_MASK))
335341
{
336342
if (m_EOLtp == 0)
337343
m_EOLtp = tp;
338344
tp = m_pSize;
345+
x = m_XMax + 1;
339346
opt = oldopt;
340347
}
341348
}

LEDText.h

+6-6
Original file line numberDiff line numberDiff line change
@@ -72,14 +72,14 @@
7272
/* Binary constant generator macro By Tom Torfs - donated to the public domain */
7373
/* All macro's evaluate to compile-time constants */
7474
#ifndef HEX__
75-
#define HEX__(n) 0x##n##LU
75+
#define HEX__(n) 0x##n##LU
7676
#endif
7777
#ifndef B8__
78-
#define B8__(x) ((x&0x0000000FLU)?1:0) +((x&0x000000F0LU)?2:0) +((x&0x00000F00LU)?4:0) +((x&0x0000F000LU)?8:0) \
79-
+((x&0x000F0000LU)?16:0) +((x&0x00F00000LU)?32:0) +((x&0x0F000000LU)?64:0) +((x&0xF0000000LU)?128:0)
80-
#define B8(d1) ((uint8_t)B8__(HEX__(d1)))
81-
#define B16(d1,d2) ((uint8_t)B8__(HEX__(d1))),((uint8_t)B8__(HEX__(d2)))
82-
#define B24(d1,d2,d3) ((uint8_t)B8__(HEX__(d1))),((uint8_t)B8__(HEX__(d2))),((uint8_t)B8__(HEX__(d3))))
78+
#define B8__(x) ((x&0x0000000FLU)?1:0) +((x&0x000000F0LU)?2:0) +((x&0x00000F00LU)?4:0) +((x&0x0000F000LU)?8:0) \
79+
+((x&0x000F0000LU)?16:0) +((x&0x00F00000LU)?32:0) +((x&0x0F000000LU)?64:0) +((x&0xF0000000LU)?128:0)
80+
#define B8(d1) ((uint8_t)B8__(HEX__(d1)))
81+
#define B16(d1,d2) ((uint8_t)B8__(HEX__(d1))),((uint8_t)B8__(HEX__(d2)))
82+
#define B24(d1,d2,d3) ((uint8_t)B8__(HEX__(d1))),((uint8_t)B8__(HEX__(d2))),((uint8_t)B8__(HEX__(d3))))
8383
#endif
8484

8585

+107
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
// This example shows the use of EFFECT_CUSTOM_RC
2+
// This allows you to monitor the return code of the UpdateText() call
3+
// for more than just 0 or -1. It allows you to set a return code of 1-255
4+
// when certain parts of the message reach the displayable area.
5+
6+
#include <FastLED.h>
7+
8+
#include <LEDMatrix.h>
9+
#include <LEDText.h>
10+
#include <FontRobotron.h>
11+
12+
// Change the next 6 defines to match your matrix type and size
13+
14+
#define LED_PIN 2
15+
#define COLOR_ORDER GRB
16+
#define CHIPSET WS2812B
17+
18+
#define MATRIX_WIDTH 16
19+
#define MATRIX_HEIGHT 16
20+
#define MATRIX_TYPE HORIZONTAL_MATRIX
21+
22+
cLEDMatrix<MATRIX_WIDTH, MATRIX_HEIGHT, MATRIX_TYPE> leds;
23+
24+
cLEDText DemoMsg;
25+
26+
const unsigned char TxtDemo[] = { EFFECT_SCROLL_LEFT
27+
EFFECT_FRAME_RATE "\x00"
28+
EFFECT_BACKGND_ERASE
29+
EFFECT_COLR_EMPTY
30+
EFFECT_CUSTOM_RC "\x01"
31+
" HORIZONTAL "
32+
EFFECT_CUSTOM_RC "\x02"
33+
"VERTICAL "
34+
EFFECT_CUSTOM_RC "\x03"
35+
"DIAGONAL " };
36+
37+
void setup()
38+
{
39+
FastLED.addLeds<CHIPSET, LED_PIN, COLOR_ORDER>(leds[0], leds.Size());
40+
FastLED.setBrightness(255);
41+
FastLED.clear(true);
42+
delay(500);
43+
FastLED.showColor(CRGB::Red);
44+
delay(1000);
45+
FastLED.showColor(CRGB::Lime);
46+
delay(1000);
47+
FastLED.showColor(CRGB::Blue);
48+
delay(1000);
49+
FastLED.showColor(CRGB::White);
50+
delay(1000);
51+
FastLED.show();
52+
53+
DemoMsg.SetFont(RobotronFontData);
54+
DemoMsg.Init(&leds, leds.Width(), DemoMsg.FontHeight() + 1, 0, 0);
55+
DemoMsg.SetText((unsigned char *)TxtDemo, sizeof(TxtDemo) - 1);
56+
}
57+
58+
59+
void loop()
60+
{
61+
static uint8_t hue;
62+
static int Mode = 1;
63+
int16_t x, y;
64+
uint8_t h;
65+
int rc;
66+
67+
h = hue;
68+
switch (Mode)
69+
{
70+
case 1:
71+
// ** Fill LED's with horizontal stripes
72+
for (y=0; y<leds.Height(); ++y)
73+
{
74+
leds.DrawLine(0, y, leds.Width() - 1, y, CHSV(h, 255, 255));
75+
h+=16;
76+
}
77+
break;
78+
case 2:
79+
// ** Fill LED's with vertical stripes
80+
for (x=0; x<leds.Width(); ++x)
81+
{
82+
leds.DrawLine(x, 0, x, leds.Height() - 1, CHSV(h, 255, 255));
83+
h+=16;
84+
}
85+
break;
86+
case 3:
87+
// ** Fill LED's with diagonal stripes
88+
for (x=0; x<(leds.Width()+leds.Height()); ++x)
89+
{
90+
leds.DrawLine(x - leds.Height(), leds.Height() - 1, x, 0, CHSV(h, 255, 255));
91+
h+=16;
92+
}
93+
break;
94+
}
95+
hue += 4;
96+
97+
rc = DemoMsg.UpdateText();
98+
if (rc == -1)
99+
{
100+
DemoMsg.SetText((unsigned char *)TxtDemo, sizeof(TxtDemo) - 1);
101+
rc = DemoMsg.UpdateText();
102+
}
103+
if (rc > 0)
104+
Mode = rc;
105+
FastLED.show();
106+
delay(20);
107+
}

0 commit comments

Comments
 (0)