Skip to content

Commit 929c14c

Browse files
committed
update sketch 8x7segment_display.ino
1 parent f3ca096 commit 929c14c

File tree

1 file changed

+28
-25
lines changed

1 file changed

+28
-25
lines changed

sketches/8x7segment_display/8x7segment_display.ino

Lines changed: 28 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// AUTHOR: Rob Tillaart
44
// VERSION: 0.5.2
55
// PURPOSE: demo 8x7segment display with 74HC595 controllers
6+
// URL: https://github.com/RobTillaart/Arduino/sketches
67
// LICENSE: MIT
78
// HISTORY: based upon demo code @ Tinytronics
89
// 0.5.1 added PROGMEM
@@ -11,9 +12,9 @@
1112
// TODO: put all in a class?
1213

1314

14-
const int datapin = 5; //DIO
15-
const int clockpin = 6; //SCK
16-
const int latchpin = 7; //RCK
15+
const int datapin = 5; // DIO
16+
const int clockpin = 6; // SCK
17+
const int latchpin = 7; // RCK
1718

1819
/* Segment bit location(7=MSB, 0=LSB):
1920
@@ -24,7 +25,7 @@ const int latchpin = 7; //RCK
2425
|--3--| **7
2526
*/
2627

27-
// Array with possible values(0 = segment ON, 1 = segment off)
28+
// Array with possible values (0 = segment ON, 1 = segment off)
2829
const byte value[] PROGMEM = {
2930
B11000000, // 0
3031
B11111001, // 1
@@ -55,15 +56,16 @@ const byte value[] PROGMEM = {
5556
};
5657

5758
const byte digit[] PROGMEM = {
58-
B00010000, // left segment
59+
B00010000, // left segment
5960
B00100000,
6061
B01000000,
6162
B10000000,
6263
B00000001,
6364
B00000010,
6465
B00000100,
6566
B00001000
66-
}; // right segment
67+
}; // right segment
68+
6769

6870
////////////////////////////////////////////////////////////////////////
6971

@@ -74,7 +76,7 @@ void showVUvertical(uint8_t val)
7476
if (val == 0) return;
7577
if (val >= 2)
7678
{
77-
showDigit(i, 18, false); // digit 8 also works very well...
79+
showDigit(i, 18, false); // digit 8 also works very well...
7880
val -= 2;
7981
continue;
8082
}
@@ -86,8 +88,8 @@ void showVUvertical(uint8_t val)
8688
}
8789
}
8890

89-
// TODO same values at once would be faster
90-
void showEqualizer(uint8_t ar[8]) // values 0..3
91+
// TODO same values at once would be faster
92+
void showEqualizer(uint8_t ar[8]) // values 0..3
9193
{
9294
for (int i = 0; i < 8; i++)
9395
{
@@ -122,17 +124,17 @@ void showHex(uint32_t value)
122124
for (int i = 7; i > -1; i--)
123125
{
124126
uint32_t t = v / 16;
125-
int d = v - 16 * t; // faster than %
127+
int d = v - 16 * t; // faster than %
126128
v = t;
127129
showDigit(i, d, false);
128130
}
129131
}
130132

131133

132-
// implementation of showing a float number in one go.
133-
// range positive from 0.0000001 - 99999999 + 0 (8 digits)
134-
// range negative from -0.000001 - -9999999 (7 digits + sign)
135-
// needs to be called also as much as possible, once every millisecond.
134+
// implementation of showing a float number in one go.
135+
// range positive from 0.0000001 - 99999999 + 0 (8 digits)
136+
// range negative from -0.000001 - -9999999 (7 digits + sign)
137+
// needs to be called also as much as possible, once every millisecond.
136138
void showFloat(float value)
137139
{
138140
float v = value;
@@ -163,9 +165,9 @@ void showFloat(float value)
163165
}
164166

165167

166-
// implementation of showing a long number in one go.
167-
// range from -9999999 (7 digits + sign) - 99999999 (8 digits)
168-
// needs to be called also as much as possible, once every millisecond.
168+
// implementation of showing a long number in one go.
169+
// range from -9999999 (7 digits + sign) - 99999999 (8 digits)
170+
// needs to be called also as much as possible, once every millisecond.
169171
void showLong(long value)
170172
{
171173
long v = value;
@@ -187,19 +189,19 @@ void showLong(long value)
187189
}
188190
}
189191

190-
// clear does write a space to all segments in one step
192+
// clear does write a space to all segments in one step
191193
//
192194
void clear()
193195
{
194196
showDigit(0xFF, 16, false);
195197
}
196198

197199

198-
// displaying single digit
199-
// shiftOut could be replaced by faster implementation
200-
// as the datapin and clockpin are always same and
201-
// the order is always MSBFIRST
202-
// see also my FastShiftOut library
200+
// displaying single digit
201+
// shiftOut could be replaced by faster implementation
202+
// as the data pin and clock pin are always same and
203+
// the order is always MSBFIRST
204+
// see also my FastShiftOut library
203205
void showDigit(int segmentnum, int number, bool showdecimalpoint)
204206
{
205207
byte value_temp = pgm_read_byte_near(value + number);
@@ -211,9 +213,10 @@ void showDigit(int segmentnum, int number, bool showdecimalpoint)
211213
digitalWrite(latchpin, HIGH);
212214
}
213215

216+
214217
///////////////////////////////////////////////////////////////////////////////////
215218
//
216-
// demo sketch
219+
// demo sketch
217220
//
218221
uint32_t counter = 0;
219222
uint32_t start = 0;
@@ -340,4 +343,4 @@ void loop()
340343
delay(1000);
341344
}
342345

343-
// -- END OF FILE --
346+
// -- END OF FILE --

0 commit comments

Comments
 (0)