Skip to content

Commit d00b433

Browse files
author
Gregory Schmidt
committed
Add scrolling message to seven seg um
1 parent 3ac772b commit d00b433

File tree

1 file changed

+31
-18
lines changed

1 file changed

+31
-18
lines changed

usermods/seven_segment_display/usermod_v2_seven_segment_display.h

Lines changed: 31 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,13 @@
77
class SevenSegmentDisplay : public Usermod {
88

99
#define WLED_SS_BUFFLEN 6
10+
#define REFRESHTIME 497
1011
private:
1112
//Private class members. You can declare variables and functions only accessible to your usermod here
1213
unsigned long lastRefresh = 0;
14+
unsigned long lastCharacterStep = 0;
1315
char ssDisplayBuffer[WLED_SS_BUFFLEN+1]; //Runtime buffer of what should be displayed.
14-
char ssCharacterMask[36] = {0x77,0x11,0x6B,0x3B,0x1D,0x3E,0x7E,0x13,0x7F,0x1F,0x5F,0x7B,0x66,0x79,0x6E,0x4E,0x76,0x5D,0x44,0x71,0x5E,0x64,0x27,0x58,0x77,0x4F,0x1F,0x48,0x3E,0x6C,0x75,0x25,0x7D,0x2A,0x3D,0x6B};
16+
char ssCharacterMask[36] = {0x77,0x11,0x6B,0x3B,0x1D,0x3E,0x7E,0x13,0x7F,0x1F,0x5F,0x7C,0x66,0x79,0x6E,0x4E,0x76,0x5D,0x44,0x71,0x5E,0x64,0x27,0x58,0x77,0x4F,0x1F,0x48,0x3E,0x6C,0x75,0x25,0x7D,0x2A,0x3D,0x6B};
1517
int ssDisplayMessageIdx = 0; //Position of the start of the message to be physically displayed.
1618

1719

@@ -20,13 +22,14 @@ class SevenSegmentDisplay : public Usermod {
2022
byte ssLEDPerSegment = 1; //The number of LEDs in each segment of the 7 seg (total per digit is 7 * ssLedPerSegment)
2123
byte ssLEDPerPeriod = 1; //A Period will have 1x and a Colon will have 2x
2224
int ssStartLED = 0; //The pixel that the display starts at.
23-
// HH - 0-23. hh - 1-12, kk - 1-24 hours
25+
/* HH - 0-23. hh - 1-12, kk - 1-24 hours
2426
// MM or mm - 0-59 minutes
2527
// SS or ss = 0-59 seconds
2628
// : for a colon
2729
// All others for alpha numeric, (will be blank when displaying time)
30+
*/
2831
char ssDisplayMask[WLED_SS_BUFFLEN+1] = "HHMMSS"; //Physical Display Mask, this should reflect physical equipment.
29-
// ssDisplayConfig
32+
/* ssDisplayConfig
3033
// -------
3134
// / A / 0 - EDCGFAB
3235
// / F / B 1 - EDCBAFG
@@ -37,15 +40,15 @@ class SevenSegmentDisplay : public Usermod {
3740
// / /
3841
// -------
3942
// D
43+
*/
4044
byte ssDisplayConfig = 5; //Physical configuration of the Seven segment display
41-
char ssDisplayMessage[50] = "ABCDEF";//Message that can scroll across the display
42-
bool ssDoDisplayMessage = 1; //If not, display time.
43-
int ssDisplayMessageTime = 10; //Length of time to display message before returning to time, in seconds. <0 would be indefinite. High Select of ssDisplayMessageTime and time to finish current scroll
44-
int ssScrollSpeed = 500; //Time between advancement of extended message scrolling, in milliseconds.
45+
char ssDisplayMessage[50] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";//Message that can scroll across the display
46+
bool ssDoDisplayMessage = false; //If not, display time.
47+
unsigned long ssScrollSpeed = 1000; //Time between advancement of extended message scrolling, in milliseconds.
4548

4649

4750

48-
void _overlaySevenSegmentProcess()
51+
unsigned long _overlaySevenSegmentProcess()
4952
{
5053
//Do time for now.
5154
if(!ssDoDisplayMessage)
@@ -94,16 +97,33 @@ class SevenSegmentDisplay : public Usermod {
9497
ssDisplayBuffer[index] = (ssDisplayMask[index] == ':' ? ':' : ' ');
9598
}
9699
}
100+
return REFRESHTIME;
97101
}
98102
else
99103
{
100104
/* This will handle displaying a message and the scrolling of the message if its longer than the buffer length */
101105
//TODO: Progress message starting point depending on display length, message length, display time, etc...
102106

107+
//Increase the displayed message index to progress it one character.
108+
ssDisplayMessageIdx++;
109+
110+
//Check to see if the message has scrolled completely
111+
size_t len = strlen(ssDisplayMessage); //really should grab this when the message is set. TODO
112+
if(ssDisplayMessageIdx > len)
113+
{
114+
//If it has displayed the whole message and the display time has exceeded, go back to clock.
115+
ssDisplayMessageIdx = 0;
116+
ssDoDisplayMessage = false;
117+
return REFRESHTIME;
118+
}
103119
//Display message
104120
for(int index = 0; index < WLED_SS_BUFFLEN; index++){
105-
ssDisplayBuffer[index] = ssDisplayMessage[ssDisplayMessageIdx+index];
121+
if(ssDisplayMessageIdx + index < len)
122+
ssDisplayBuffer[index] = ssDisplayMessage[ssDisplayMessageIdx+index];
123+
else
124+
ssDisplayBuffer[index] = ' ';
106125
}
126+
return ssScrollSpeed;
107127
}
108128
}
109129

@@ -163,7 +183,7 @@ class SevenSegmentDisplay : public Usermod {
163183
//ssCharacterMask
164184
if(var > 0x60) //Essentially a "toLower" call.
165185
var -= 0x20;
166-
if(var > 0x9) //Meaning it is a non-numeric
186+
if(var > 0x39) //Meaning it is a non-numeric
167187
var -= 0x07;
168188
var -= 0x30; //Shift ascii down to start numeric 0 at index 0.
169189

@@ -237,17 +257,10 @@ class SevenSegmentDisplay : public Usermod {
237257

238258
/*
239259
* loop() is called continuously. Here you can check for events, read sensors, etc.
240-
*
241-
* Tips:
242-
* 1. You can use "if (WLED_CONNECTED)" to check for a successful network connection.
243-
* Additionally, "if (WLED_MQTT_CONNECTED)" is available to check for a connection to an MQTT broker.
244-
*
245-
* 2. Try to avoid using the delay() function. NEVER use delays longer than 10 milliseconds.
246-
* Instead, use a timer check as shown here.
247260
*/
248261
void loop() {
249262
if (millis() - lastRefresh > resfreshTime) {
250-
_overlaySevenSegmentProcess();
263+
resfreshTime = _overlaySevenSegmentProcess();
251264
lastRefresh = millis();
252265
}
253266
}

0 commit comments

Comments
 (0)