Skip to content

Commit

Permalink
add method displayTime
Browse files Browse the repository at this point in the history
  • Loading branch information
nomad605dis committed Apr 26, 2017
1 parent eca0383 commit 988ab1d
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 15 deletions.
73 changes: 60 additions & 13 deletions QuadDisplay2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,44 +96,39 @@ void QuadDisplay::displayInt(int val, bool padZeros, uint8_t dots)
{
uint8_t digits[4] = {0xff, 0xff, 0xff, 0xff};

if (!padZeros && !val)
if (!padZeros && !val) {
digits[3] = numerals[0];
else {
} else {
bool negative = val < 0;
val = abs(val);


int8_t i;
for (i = 4; i--; ) {
uint8_t digit = val % 10;
digits[i] = (val || padZeros) ? numerals[digit] : 0xff;

val /= 10;

if (!val && !padZeros)
break;
}

if (negative)
digits[max(0, i-1)] = QD_MINUS;
digits[i - 1] = QD_MINUS;

digits[4 - dots] &= QD_DOT;

for (i = 4; i--; ) {
if (dots & (1 << i))
digits[4 - i] &= QD_DOT;
}
}

displayDigits(digits[0], digits[1], digits[2], digits[3]);
}

void QuadDisplay::displayFloat(float val, uint8_t precision, bool padZeros)
{
uint8_t dot = 0x1;
uint8_t dot = 0;
while (precision) {
val *= 10;
--precision;
dot <<= 1;
dot++;
}

displayInt((int)val, padZeros, dot);
}

Expand Down Expand Up @@ -190,3 +185,55 @@ void QuadDisplay::displayHumidity(int val, bool padZeros)
}
displayDigits(digits[0], digits[1], digits[2], digits[3]);
}

void QuadDisplay::displayTime(int hour, int minute)
{
uint8_t digits[4] = {0xff, 0xff, 0xff, 0xff};

if (!hour) {
igits[0] = numerals[0];
digits[1] = numerals[0];
} else {
if (hour < 10) {
digits[0] = numerals[0];
}
int8_t i;
for (i = 2; i--; ) {
uint8_t digit = hour % 10;
digits[i] = hour ? numerals[digit] : 0xff;

hour /= 10;
if (!hour)
break;
}
}

if (!minute) {
digits[2] = numerals[0];
digits[3] = numerals[0];
} else {
if (minute < 10) {
digits[2] = numerals[0];
}
int8_t i;
for (i = 4; i--; ) {
uint8_t digit = minute % 10;
digits[i] = minute ? numerals[digit] : 0xff;

minute /= 10;
if (!minute)
break;
}
}

if (millis() - _startMillis > 500) {
_state = !_state;
_startMillis = millis();
}
if (_state) {
digits[2] &= QD_DOT;
} else {
digits[2] |= ~QD_DOT;

displayDigits(digits[0], digits[1], digits[2], digits[3]);
}
5 changes: 4 additions & 1 deletion QuadDisplay2.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@
class QuadDisplay
{
private:
unsigned long _startMillis = millis();
bool _state;
uint8_t _pinSCK;
uint8_t _pinDI;
uint8_t _pinCS;
Expand All @@ -83,9 +85,10 @@ class QuadDisplay
void displayFloat(float val, uint8_t precision, bool padZeros = false);
void displayDigits(uint8_t digit1, uint8_t digit2, uint8_t digit3, uint8_t digit4);
void displaySegments(uint32_t digits);
void displayClear();
void displayTemperatureC(int val, bool padZeros = false);
void displayHumidity(int val, bool padZeros = false);
void displayTime(int hour, int minute);
void displayClear();
};

#endif
2 changes: 1 addition & 1 deletion examples/qdTest/qdTest.ino
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ void loop()

// можно показывать температуру в °C
qd.displayTemperatureC(-5);

delay(1000);
// можно показывать нехитрый текст (on/off, например) или
// произвольную графику
qd.displayDigits(QD_O, QD_f, QD_f, QD_NONE); // off
Expand Down

0 comments on commit 988ab1d

Please sign in to comment.