Skip to content

Commit 4216497

Browse files
author
Nathan Seidle
committed
Change initialize to call multi-display functions. Rename methods to be xyzSingle.
1 parent 7d5346b commit 4216497

File tree

2 files changed

+102
-55
lines changed

2 files changed

+102
-55
lines changed

src/SparkFun_Alphanumeric_Display.cpp

Lines changed: 90 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,6 @@ bool HT16K33::begin(uint8_t addressLeft, uint8_t addressLeftCenter, uint8_t addr
5656
Serial.println(i);
5757
return false;
5858
}
59-
if (initialize(i) == false)
60-
{
61-
Serial.print("Failed initialize() on displayNumber: ");
62-
Serial.println(i);
63-
return false;
64-
}
6559
// if (checkDeviceID(i) == false)
6660
// {
6761
// Serial.println(i);
@@ -70,51 +64,58 @@ bool HT16K33::begin(uint8_t addressLeft, uint8_t addressLeftCenter, uint8_t addr
7064
// }
7165
}
7266

67+
if (initialize() == false)
68+
{
69+
Serial.println("Failed initialize()");
70+
return false;
71+
}
72+
7373
// clearDisplay();
7474
return true;
7575
}
7676

77+
//The repeated start condition seems to help the display at address 0x71.
7778
bool HT16K33::isConnected(uint8_t displayNumber)
7879
{
80+
_i2cPort->beginTransmission(lookUpDisplayAddress(displayNumber));
81+
_i2cPort->endTransmission();
82+
7983
_i2cPort->beginTransmission(lookUpDisplayAddress(displayNumber));
8084
if (_i2cPort->endTransmission() == 0)
8185
return true;
8286
return false;
8387
}
8488

85-
bool HT16K33::initialize(uint8_t displayNumber)
89+
bool HT16K33::initialize()
8690
{
87-
uint8_t address = lookUpDisplayAddress(displayNumber);
88-
89-
Serial.print("Initialize: 0x");
90-
Serial.println(address, HEX);
91-
92-
//internal system clock enable
93-
if (writeOne(address, 0x21) == false)
91+
//Turn on system clock of all displays
92+
if (enableSystemClock() == false)
93+
{
94+
Serial.println("I've failed enableSystemClock()");
9495
return false;
96+
}
9597

9698
//ROW/INT output pin set, INT pin output level set
97-
uint8_t temp = 0;
98-
if (writeRAM(address, 0xA0, (uint8_t *)&temp, 0) == false)
99-
return false;
99+
// uint8_t temp = 0;
100+
// if (writeRAM(address, 0xA0, (uint8_t *)&temp, 0) == false)
101+
// return false;
100102

101-
//Set brightness of display by duty cycle
102-
if (setBrightnessDisplay(displayNumber, 16) == false)
103+
//Set brightness of all displays to full brightness
104+
if (setBrightness(16) == false)
103105
{
104106
Serial.println("I've failed setBrightness()");
105107
return false;
106108
}
107109

108-
//Blinking set - blinking off, display on
109-
if (setBlinkRateDisplay(displayNumber, 0) == false)
110+
//Blinking set - blinking off
111+
if (setBlinkRate(ALPHA_BLINK_RATE_NOBLINK) == false)
110112
{
111113
Serial.println("I've failed setBlinkRate()");
112-
blinkRate = ALPHA_BLINK_RATE_NOBLINK;
113-
displayOnOff = 1;
114114
return false;
115115
}
116116

117-
if (singleDisplayOn(displayNumber) == false)
117+
//Turn on all displays
118+
if (displayOn() == false)
118119
{
119120
Serial.println("Failed display on");
120121
return false;
@@ -145,6 +146,44 @@ bool HT16K33::initialize(uint8_t displayNumber)
145146
// return true;
146147
// }
147148

149+
bool HT16K33::enableSystemClock()
150+
{
151+
bool status = true;
152+
for (uint8_t i = 0; i < sizeOfDisplay / 4; i++)
153+
{
154+
if (enableSystemClockSingle(i) == false)
155+
status = false;
156+
}
157+
return status;
158+
}
159+
160+
bool HT16K33::disableSystemClock()
161+
{
162+
bool status = true;
163+
for (uint8_t i = 0; i < sizeOfDisplay / 4; i++)
164+
{
165+
if (enableSystemClockSingle(i) == false)
166+
status = false;
167+
}
168+
return status;
169+
}
170+
171+
bool HT16K33::enableSystemClockSingle(uint8_t displayNumber)
172+
{
173+
uint8_t dataToWrite = ALPHA_CMD_SYSTEM_SETUP | 1; //Enable system clock
174+
175+
uint8_t temp = 0;
176+
return (writeRAM(lookUpDisplayAddress(displayNumber), dataToWrite, (uint8_t *)&temp, 0));
177+
}
178+
179+
bool HT16K33::disableSystemClockSingle(uint8_t displayNumber)
180+
{
181+
uint8_t dataToWrite = ALPHA_CMD_SYSTEM_SETUP | 0; //Standby mode
182+
183+
uint8_t temp = 0;
184+
return (writeRAM(lookUpDisplayAddress(displayNumber), dataToWrite, (uint8_t *)&temp, 0));
185+
}
186+
148187
uint8_t HT16K33::lookUpDisplayAddress(uint8_t displayNumber)
149188
{
150189
switch (displayNumber)
@@ -184,28 +223,21 @@ bool HT16K33::setBrightness(uint8_t duty)
184223
bool status = true;
185224
for (uint8_t i = 0; i < sizeOfDisplay / 4; i++)
186225
{
187-
if (setBrightnessDisplay(i, duty) == false)
226+
if (setBrightnessSingle(i, duty) == false)
188227
status = false;
189228
}
190229
return status;
191230
}
192231

193-
bool HT16K33::setBrightnessDisplay(uint8_t displayNumber, uint8_t duty)
232+
bool HT16K33::setBrightnessSingle(uint8_t displayNumber, uint8_t duty)
194233
{
195-
int temp = 0;
196-
//Duty value is acceptable
197-
if (1 <= duty <= 16)
198-
{
199-
//Based on datasheet
200-
duty = duty + 223;
201-
}
202-
//else if duty value doesn't make sense, default to full brightness
203-
else
204-
{
205-
duty = 239;
206-
}
234+
if (duty > 15)
235+
duty = 15; //Error check
207236

208-
return (writeRAM(lookUpDisplayAddress(displayNumber), duty, (uint8_t *)&temp, 0));
237+
uint8_t dataToWrite = ALPHA_CMD_DIMMING_SETUP | duty;
238+
239+
uint8_t temp = 0;
240+
return (writeRAM(lookUpDisplayAddress(displayNumber), dataToWrite, (uint8_t *)&temp, 0));
209241
}
210242

211243
//Parameter "rate" in Hz
@@ -216,13 +248,13 @@ bool HT16K33::setBlinkRate(float rate)
216248
bool status = true;
217249
for (uint8_t i = 0; i < sizeOfDisplay / 4; i++)
218250
{
219-
if (setBlinkRateDisplay(i, rate) == false)
251+
if (setBlinkRateSingle(i, rate) == false)
220252
status = false;
221253
}
222254
return status;
223255
}
224256

225-
bool HT16K33::setBlinkRateDisplay(uint8_t displayNumber, float rate)
257+
bool HT16K33::setBlinkRateSingle(uint8_t displayNumber, float rate)
226258
{
227259
int temp = 0;
228260

@@ -249,17 +281,17 @@ bool HT16K33::setBlinkRateDisplay(uint8_t displayNumber, float rate)
249281
return (writeRAM(lookUpDisplayAddress(displayNumber), dataToWrite, (uint8_t *)&temp, 0));
250282
}
251283

252-
bool HT16K33::singleDisplayOn(uint8_t displayNumber)
284+
bool HT16K33::displayOnSingle(uint8_t displayNumber)
253285
{
254-
return setSingleDisplayOn(displayNumber, true);
286+
return setDisplayOnOff(displayNumber, true);
255287
}
256-
bool HT16K33::singleDisplayOff(uint8_t displayNumber)
288+
bool HT16K33::displayOffSingle(uint8_t displayNumber)
257289
{
258-
return setSingleDisplayOn(displayNumber, false);
290+
return setDisplayOnOff(displayNumber, false);
259291
}
260292

261293
//Set or clear the display on/off bit of a given display number
262-
bool HT16K33::setSingleDisplayOn(uint8_t displayNumber, bool turnOnDisplay)
294+
bool HT16K33::setDisplayOnOff(uint8_t displayNumber, bool turnOnDisplay)
263295
{
264296
if (turnOnDisplay == true)
265297
displayOnOff = ALPHA_DISPLAY_ON;
@@ -281,7 +313,7 @@ bool HT16K33::displayOn()
281313

282314
for (uint8_t i = 0; i < sizeOfDisplay / 4; i++)
283315
{
284-
if (singleDisplayOn(i) == false)
316+
if (displayOnSingle(i) == false)
285317
status = false;
286318
}
287319

@@ -296,7 +328,7 @@ bool HT16K33::displayOff()
296328

297329
for (uint8_t i = 0; i < sizeOfDisplay / 4; i++)
298330
{
299-
if (singleDisplayOff(i) == false)
331+
if (displayOffSingle(i) == false)
300332
status = false;
301333
}
302334

@@ -575,7 +607,7 @@ bool HT16K33::updateDisplay()
575607
{
576608
if (writeRAM(lookUpDisplayAddress(i), 0, (uint8_t *)displayRAM + (i * 16), 16) == false)
577609
{
578-
Serial.print("Hello, I'm failing updateDisplay at display 0x");
610+
Serial.print("updateDisplay fail at display 0x");
579611
Serial.println(lookUpDisplayAddress(i), HEX);
580612
status = false;
581613
}
@@ -588,6 +620,9 @@ bool HT16K33::updateDisplay()
588620

589621
bool HT16K33::readRAM(uint8_t address, uint8_t reg, uint8_t *buff, uint8_t buffSize)
590622
{
623+
_i2cPort->beginTransmission(address);
624+
_i2cPort->endTransmission();
625+
591626
_i2cPort->beginTransmission(address);
592627
_i2cPort->write(reg);
593628
_i2cPort->endTransmission();
@@ -613,6 +648,9 @@ bool HT16K33::readRAM(uint8_t address, uint8_t reg, uint8_t *buff, uint8_t buffS
613648

614649
bool HT16K33::writeRAM(uint8_t address, uint8_t reg, uint8_t *buff, uint8_t buffSize)
615650
{
651+
_i2cPort->beginTransmission(address);
652+
_i2cPort->endTransmission(false);
653+
616654
_i2cPort->beginTransmission(address);
617655
_i2cPort->write(reg);
618656

@@ -631,6 +669,9 @@ bool HT16K33::writeRAM(uint8_t address, uint8_t reg, uint8_t *buff, uint8_t buff
631669

632670
bool HT16K33::writeOne(uint8_t address, uint8_t reg)
633671
{
672+
_i2cPort->beginTransmission(address);
673+
_i2cPort->endTransmission(false);
674+
634675
_i2cPort->beginTransmission(address);
635676
_i2cPort->write(reg);
636677

src/SparkFun_Alphanumeric_Display.h

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ typedef enum
4646
{
4747
ALPHA_CMD_SYSTEM_SETUP = 0b00100000,
4848
ALPHA_CMD_DISPLAY_SETUP = 0b10000000,
49+
ALPHA_CMD_DIMMING_SETUP = 0b11100000,
4950
};
5051

5152
// class HT16K33
@@ -73,23 +74,28 @@ class HT16K33 : public Print
7374
uint8_t addressRight = DEFAULT_NOTHING_ATTACHED,
7475
TwoWire &wirePort = Wire); // Sets the address of the device and opens the Wire port for communication
7576
bool isConnected(uint8_t displayNumber);
76-
bool initialize(uint8_t displayNumber);
77+
bool initialize();
7778
bool checkDeviceID(uint8_t displayNumber);
7879
uint8_t lookUpDisplayAddress(uint8_t displayNumber);
7980

8081
//Display configuration functions
8182
bool clearDisplay();
8283
bool setBrightness(uint8_t duty);
83-
bool setBrightnessDisplay(uint8_t displayNumber, uint8_t duty);
84+
bool setBrightnessSingle(uint8_t displayNumber, uint8_t duty);
8485
// uint8_t getBrightness();
8586
bool setBlinkRate(float rate);
86-
bool setBlinkRateDisplay(uint8_t displayNumber, float rate);
87+
bool setBlinkRateSingle(uint8_t displayNumber, float rate);
8788
// uint8_t getBlinkRate();
8889
bool displayOn();
89-
bool singleDisplayOn(uint8_t displayNumber);
9090
bool displayOff();
91-
bool singleDisplayOff(uint8_t displayNumber);
92-
bool setSingleDisplayOn(uint8_t displayNumber, bool turnOnDisplay);
91+
bool displayOnSingle(uint8_t displayNumber);
92+
bool displayOffSingle(uint8_t displayNumber);
93+
bool setDisplayOnOff(uint8_t displayNumber, bool turnOnDisplay);
94+
95+
bool enableSystemClock();
96+
bool disableSystemClock();
97+
bool enableSystemClockSingle(uint8_t displayNumber);
98+
bool disableSystemClockSingle(uint8_t displayNumber);
9399

94100
//Light up functions
95101
void illuminateSegment(uint8_t segment, uint8_t digit);

0 commit comments

Comments
 (0)