Skip to content

Commit 897d1e5

Browse files
Merge pull request #2 from SupremeSports/feature-01
Upgraded to variable pixels per segment/decimal
2 parents c07b953 + 51a179b commit 897d1e5

File tree

6 files changed

+693
-208
lines changed

6 files changed

+693
-208
lines changed

README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,16 @@ You can then initialise the display with the following line that includes the nu
1414

1515
Neo7Segment disp( 5, 4 );
1616

17+
You can also initialise the display with custom pixels per segment and pixel per decimal point
18+
19+
#define PIXELS_DIGITS 5 // Number of digits
20+
#define PIXELS_PER_SEGMENT 4 // Pixels per segment - If you want more than 10 pixels per segment, modify the Neo7Segment.cpp
21+
#define PIXELS_PER_POINT 1 // Pixels per decimal point - CANNOT be higher than PIXELS_PER_SEGMENT
22+
#define PIXELS_PIN 4 // Pin number
23+
24+
// Initalise the display with 5 Neo7Segment boards, 4 LEDs per segment, 1 decimal point LED, connected to GPIO 4
25+
Neo7Segment disp(PIXELS_DIGITS, PIXELS_PER_SEGMENT, PIXELS_PER_POINT, PIXELS_PIN);
26+
1727
You then start the display with the bebin method, passing the brightness:
1828

1929
disp.Begin(20);
Lines changed: 225 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,225 @@
1+
//Displays all digits with the same number counting from 0 to 9. Odd numbers have decimal point ON, others OFF.
2+
//Push button on pin 5 to control color changing
3+
#include <Neo7Segment.h>
4+
5+
#define PIXELS_DIGITS 5 // Number of digits
6+
#define PIXELS_PER_SEGMENT 4 // If you want more than 10 pixels per segment, modify the Neo7Segment_Var.cpp
7+
#define PIXELS_PER_POINT 1 // CANNOT be higher than PIXELS_PER_SEGMENT
8+
#define PIXELS_PIN 4 // Pin number
9+
10+
// Initalise the display with 5 Neo7Segment boards, 4 LEDs per segment, 1 decimal point LED, connected to GPIO 4
11+
Neo7Segment disp(PIXELS_DIGITS, PIXELS_PER_SEGMENT, PIXELS_PER_POINT, PIXELS_PIN);
12+
13+
int loopIndex = 0;
14+
byte rainbowIndex = 0;
15+
unsigned long nextRainbow = 0;
16+
int displayFeature = 0;
17+
long nextCount = millis();
18+
19+
//Button pin define
20+
#define buttonPin 5
21+
22+
bool changeColor = false;
23+
bool buttonActive = false;
24+
int digitDisplay = 0;
25+
26+
String text = "";
27+
28+
void setup()
29+
{
30+
Serial.begin(9600);
31+
delay(1000);
32+
33+
pinMode(buttonPin, INPUT);
34+
35+
// Start the display with a brightness value of 20
36+
disp.Begin(20);
37+
38+
// Set the initial display feature to show as 0
39+
displayFeature = 0;
40+
}
41+
42+
void loop()
43+
{
44+
// Wait until the display is initialised before we try to show anything
45+
if ( !disp.IsReady() )
46+
return;
47+
48+
readButtonPush();
49+
50+
if ( millis() > nextCount )
51+
{
52+
digitDisplay += 1;
53+
nextCount = millis() + 1000;
54+
}
55+
56+
if (digitDisplay > 9)
57+
digitDisplay = 0;
58+
59+
String dot = ( ( digitDisplay%2 ) == 0 ) ? "." : "";
60+
String digit = String( digitDisplay );
61+
62+
text = "";
63+
for ( int i = 0; i < PIXELS_DIGITS; i++ )
64+
text = text + digit + dot;
65+
66+
// Switch sequence when pressing on button
67+
if ( changeColor )
68+
displayFeature = (displayFeature + 1) % 13;
69+
70+
// Display stuff on the Neo7Segment displays
71+
if (nextRainbow < millis() || changeColor)
72+
colorChangingSequences();
73+
74+
changeColor = false;
75+
}
76+
77+
void colorChangingSequences()
78+
{
79+
switch(displayFeature)
80+
{
81+
case 0:
82+
disp.DisplayTextColorCycle( text, rainbowIndex );
83+
nextRainbow = millis() + 10;
84+
rainbowIndex++;
85+
break;
86+
87+
case 1:
88+
disp.DisplayTextVerticalRainbow( text, disp.Color(255,0,0), disp.Color(0,0,255) );
89+
nextRainbow = millis() + 10;
90+
break;
91+
92+
case 2:
93+
nextRainbow = millis() + 250;
94+
rainbowIndex+=5;
95+
loopIndex++;
96+
if (loopIndex > 1)
97+
loopIndex = 0;
98+
99+
disp.ForceUppercase( true );
100+
disp.DisplayTextMarquee( text, loopIndex, disp.Wheel( rainbowIndex & 255 ) );
101+
102+
break;
103+
104+
case 3:
105+
disp.ForceUppercase( false );
106+
disp.DisplayTextVerticalRainbow( text, disp.Wheel( rainbowIndex & 255 ) , disp.Wheel( ( rainbowIndex + 50 ) & 255 ) );
107+
nextRainbow = millis() + 10;
108+
rainbowIndex--;
109+
break;
110+
111+
case 4:
112+
nextRainbow = millis() + 50;
113+
rainbowIndex+=5;
114+
loopIndex++;
115+
if ( loopIndex > ( PIXELS_PER_SEGMENT-1 ) )
116+
loopIndex = 0;
117+
118+
disp.DisplayTextChaser( text, loopIndex, disp.Wheel( rainbowIndex & 255 ) );
119+
120+
break;
121+
122+
case 5:
123+
rainbowIndex++;
124+
125+
if (rainbowIndex % 5 == 0)
126+
{
127+
loopIndex++;
128+
if (loopIndex >= disp.GetSpinAllLength())
129+
loopIndex = 0;
130+
}
131+
132+
disp.SetDigitSegments(0, disp.GetSpinAllAtIndex(loopIndex), disp.Color(0, 0, 50));
133+
disp.SetDigitSegments(1, disp.GetSpinAllAtIndex(loopIndex), disp.Color(0, 0, 100));
134+
disp.SetDigitSegments(2, disp.GetSpinAllAtIndex(loopIndex), disp.Color(0, 0, 150));
135+
disp.SetDigitSegments(3, disp.GetSpinAllAtIndex(loopIndex), disp.Color(0, 0, 200));
136+
disp.SetDigitSegments(4, disp.GetSpinAllAtIndex(loopIndex), disp.Color(0, 0, 250));
137+
138+
for (int i = 5; i<PIXELS_DIGITS; i++)
139+
disp.SetDigit(i, "", disp.Color(0, 0, 0));
140+
141+
nextRainbow = millis() + 10;
142+
break;
143+
144+
case 6:
145+
if (rainbowIndex > (2*PIXELS_PER_SEGMENT*PIXELS_DIGITS))
146+
rainbowIndex = 0;
147+
148+
disp.DisplayKnightRider(rainbowIndex, disp.Color(255,0,255));
149+
nextRainbow = millis() + 10;
150+
rainbowIndex++;
151+
break;
152+
153+
case 7:
154+
disp.ForceUppercase(false);
155+
disp.DisplayTextHorizontalRainbow(text, disp.Wheel(rainbowIndex & 255) , disp.Wheel((rainbowIndex + 150) & 255));
156+
nextRainbow = millis() + 50;
157+
rainbowIndex--;
158+
break;
159+
160+
case 8://
161+
disp.DisplayBorderAnimation(rainbowIndex, disp.Color(0, 0, 250));
162+
nextRainbow = millis() + 100;
163+
rainbowIndex--;
164+
break;
165+
166+
case 9:
167+
disp.DisplayTime((digitDisplay*10+digitDisplay), (digitDisplay*10+digitDisplay), digitDisplay, disp.Color(255, 200, 0), disp.Color(0, 0, 255));
168+
nextRainbow = millis() + 500;
169+
break;
170+
171+
case 10:
172+
disp.DisplayTextColorCycle(text, rainbowIndex);
173+
nextRainbow = millis() + 10;
174+
rainbowIndex++;
175+
break;
176+
177+
case 11: // Same as case #5, but allows to send complete string and change each digit's color
178+
uint32_t digitColors[PIXELS_DIGITS];
179+
digitColors[0] = disp.Color(255, 0, 0);
180+
digitColors[1] = disp.Color(127, 127, 0);
181+
digitColors[2] = disp.Color(0, 255, 0);
182+
digitColors[3] = disp.Color(0, 127, 127);
183+
digitColors[4] = disp.Color(0, 0, 255);
184+
185+
for (int i = 5; i<PIXELS_DIGITS; i++)
186+
digitColors[i] = disp.Color(0, 0, 0);
187+
188+
disp.DisplayTextDigitColor(text, digitColors);
189+
nextRainbow = millis() + 50;
190+
rainbowIndex++;
191+
break;
192+
193+
case 12: // Same as case #5, but allows to send string character (only first will be used) and change only one digit at a time
194+
disp.SetDigit(0, text, disp.Color(0, 0, 255));
195+
disp.SetDigit(1, text, disp.Color(0, 127, 127));
196+
disp.SetDigit(2, text, disp.Color(0, 255, 0));
197+
disp.SetDigit(3, text, disp.Color(127, 127, 0));
198+
disp.SetDigit(4, text, disp.Color(255, 0, 0));
199+
200+
nextRainbow = millis() + 50;
201+
rainbowIndex++;
202+
break;
203+
204+
default:
205+
displayFeature = 0;
206+
break;
207+
}
208+
}
209+
210+
void readButtonPush()
211+
{
212+
bool buttonPressed = !digitalRead(buttonPin);
213+
if (buttonPressed)
214+
{
215+
if (!buttonActive)
216+
buttonActive = true;
217+
}
218+
else
219+
{
220+
if (buttonActive)
221+
changeColor = true;
222+
223+
buttonActive = false;
224+
}
225+
}

examples/Neo7Segment_Demo/Neo7Segment_Demo.ino

Lines changed: 55 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,20 @@
1+
//Displays different designs
2+
//Changes feature every 5 seconds
13
#include <Neo7Segment.h>
24

3-
// Initalise the display with 5 Neo7Segment boards connected to GPIO 4
4-
Neo7Segment disp( 5, 4 );
5+
#define PIXELS_DIGITS 5 // Number of digits
6+
#define PIXELS_PER_SEGMENT 4 // Pixels per segment - If you want more than 10 pixels per segment, modify the Neo7Segment_Var.cpp
7+
#define PIXELS_PER_POINT 1 // Pixels per decimal point - CANNOT be higher than PIXELS_PER_SEGMENT
8+
#define PIXELS_PIN 4 // Pin number
9+
10+
// Initalise the display with 5 Neo7Segment boards, 4 LEDs per segment, 1 decimal point LED, connected to GPIO 4
11+
Neo7Segment disp(PIXELS_DIGITS, PIXELS_PER_SEGMENT, PIXELS_PER_POINT, PIXELS_PIN);
512

613
int loopIndex = 0;
714
byte rainbowIndex = 0;
815
unsigned long nextRainbow = 0;
916
int displayFeature = 0;
10-
int nextSwitch = 10000;
17+
long nextSwitch = millis();
1118

1219
void setup()
1320
{
@@ -34,12 +41,16 @@ void loop()
3441
if ( millis() > nextSwitch )
3542
{
3643
nextSwitch = millis() + 5000;
37-
displayFeature = ( displayFeature + 1 ) % 11;
44+
displayFeature = ( displayFeature + 1 ) % 13;
3845
}
3946

4047
// Display stuff on the Neo7Segment displays
4148
if ( nextRainbow < millis() )
42-
{
49+
colorChangingSequences();
50+
}
51+
52+
void colorChangingSequences()
53+
{
4354
switch( displayFeature )
4455
{
4556
case 0:
@@ -97,7 +108,7 @@ void loop()
97108
nextRainbow = millis() + 25;
98109
rainbowIndex+=5;
99110
loopIndex++;
100-
if ( loopIndex > 3 )
111+
if ( loopIndex > ( PIXELS_PER_SEGMENT-1 ) )
101112
loopIndex = 0;
102113

103114
disp.DisplayTextChaser("lolol", loopIndex, disp.Wheel( rainbowIndex & 255 ) );
@@ -106,11 +117,11 @@ void loop()
106117

107118
case 5:
108119
rainbowIndex++;
109-
120+
110121
if ( rainbowIndex % 5 == 0 )
111122
{
112123
loopIndex++;
113-
if ( loopIndex == disp.GetSpinAllLength() )
124+
if ( loopIndex >= disp.GetSpinAllLength() )
114125
loopIndex = 0;
115126
}
116127

@@ -119,9 +130,17 @@ void loop()
119130
disp.SetDigitSegments( 2, disp.GetSpinAllAtIndex( loopIndex ), disp.Color(0, 0, 150) );
120131
disp.SetDigitSegments( 3, disp.GetSpinAllAtIndex( loopIndex ), disp.Color(0, 0, 200) );
121132
disp.SetDigitSegments( 4, disp.GetSpinAllAtIndex( loopIndex ), disp.Color(0, 0, 250) );
133+
134+
for (int i = 5; i<PIXELS_DIGITS; i++)
135+
disp.SetDigit(i, "", disp.Color(0, 0, 0));
136+
137+
nextRainbow = millis() + 10;
122138
break;
123139

124140
case 6:
141+
if (rainbowIndex > (2*PIXELS_PER_SEGMENT*PIXELS_DIGITS))
142+
rainbowIndex = 0;
143+
125144
disp.DisplayKnightRider( rainbowIndex, disp.Color(255,0,255) );
126145
nextRainbow = millis() + 80;
127146
rainbowIndex++;
@@ -147,12 +166,37 @@ void loop()
147166
break;
148167

149168
case 10:
150-
disp.DisplayTextColorCycle( "0....0", rainbowIndex );
169+
disp.DisplayTextColorCycle( "0....0 ", rainbowIndex );
151170
nextRainbow = millis() + 10;
152171
rainbowIndex++;
153172
break;
154173

174+
case 11: // Same as case #5, but allows to send complete string and change each digit's color
175+
uint32_t digitColors[PIXELS_DIGITS];
176+
digitColors[0] = disp.Color(255, 0, 0);
177+
digitColors[1] = disp.Color(127, 127, 0);
178+
digitColors[2] = disp.Color(0, 255, 0);
179+
digitColors[3] = disp.Color(0, 127, 127);
180+
digitColors[4] = disp.Color(0, 0, 255);
181+
182+
disp.DisplayTextDigitColor("8.8.8.8.8.", digitColors);
183+
nextRainbow = millis() + 50;
184+
rainbowIndex++;
185+
break;
186+
187+
case 12: // Same as case #5, but allows to send string character (only first will be used) and change only one digit at a time
188+
disp.SetDigit(0, "5", disp.Color(0, 0, 255));
189+
disp.SetDigit(1, "4", disp.Color(0, 127, 127));
190+
disp.SetDigit(2, "3", disp.Color(0, 255, 0));
191+
disp.SetDigit(3, "2", disp.Color(127, 127, 0));
192+
disp.SetDigit(4, "1", disp.Color(255, 0, 0));
193+
194+
nextRainbow = millis() + 50;
195+
rainbowIndex++;
196+
break;
197+
198+
default:
199+
displayFeature = 0;
200+
break;
155201
}
156-
}
157202
}
158-

library.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name=Neo7Segment
2-
version=1.0.1
2+
version=2.0.3
33
author=UnexpectedMaker
44
maintainer=UnexpectedMaker
55
sentence=A library to display numbers and letters on Neo7Segment displays.

0 commit comments

Comments
 (0)