Skip to content

Commit

Permalink
Fix #4 by enhancing fixed point displaying.
Browse files Browse the repository at this point in the history
  • Loading branch information
likema committed Oct 21, 2012
1 parent 33ac28a commit ee8030b
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 20 deletions.
49 changes: 36 additions & 13 deletions SevenSegmentDisplay.h
Expand Up @@ -2,17 +2,6 @@
* \file SevenSegmentDisplay.h
* \brief Arduino 7-Segment Display
* \author Like Ma <likemartinma@gmail.com>
*
* a
* _____
* | |
* f | g | b
* |_____|
* | |
* e | | c
* |_____| . dp
*
* d
*/

#ifndef SEVENSEGMENTDISPLAY_H
Expand Down Expand Up @@ -51,20 +40,54 @@ struct QuadriDigit {
template <boolean ANODE, typename DIGITS, unsigned DELAY = 20>
class SevenSegmentDisplay {
public:
/*!
* \brief Initialize 7-segment display.
*
* See the following ascii diagram for parameters:
*
* a
* _____
* | |
* f | g | b
* |_____|
* | |
* e | | c
* |_____| . dp
*
* d
*/
SevenSegmentDisplay(byte a, byte b, byte c, byte d, byte e, byte f, byte g, byte dp);
void print(unsigned n, unsigned long duration = 0);

/*!
* \brief Display fixed point number.
* \param n The number to display.
* \param pt The position of the point ranged from 0 to DIGITS::N - 1, while 0 denotes the lowest digit.
* \param duration The duration for displaying.
*/
void print(unsigned n, byte pt = -1, unsigned long duration = 0);

/*!
* \brief Display float point number.
* \param n The number to display.
* \param duration The duration for displaying.
*/
void print(float n, unsigned long duration = 0);

/*!
* \brief light off all segments.
*/
void clear ();
protected:
void pickDigit(byte i);
void printDigit(byte n, bool dp = false);
void printUnsigned(unsigned n, byte dp = -1);
void printUnsigned(unsigned n, byte dp);
void printFloat(float n);

enum {
MAX_SEGMENTS = 8,
DP_IDX = MAX_SEGMENTS - 1
};

byte pin_[MAX_SEGMENTS];
byte digit_[10];
};
Expand Down
6 changes: 3 additions & 3 deletions SevenSegmentDisplay.inl
Expand Up @@ -127,16 +127,16 @@ void SevenSegmentDisplay<ANODE, DIGITS, DELAY>::printFloat(float n)
}

template <boolean ANODE, typename DIGITS, unsigned DELAY>
void SevenSegmentDisplay<ANODE, DIGITS, DELAY>::print(unsigned n, unsigned long duration)
void SevenSegmentDisplay<ANODE, DIGITS, DELAY>::print(unsigned n, byte pt, unsigned long duration)
{
if (DIGITS::N > 1) {
if (duration) {
unsigned long endTime = millis() + duration;
while (millis () < endTime) {
printUnsigned(n);
printUnsigned(n, pt);
}
} else {
printUnsigned(n);
printUnsigned(n, pt);
}
} else {
printDigit(n % 10);
Expand Down
2 changes: 1 addition & 1 deletion examples/BiDigit/BiDigit.ino
Expand Up @@ -28,6 +28,6 @@ void setup() {
void loop() {
unsigned i = 99;
do {
ss.print(i, 2000);
ss.print(i, -1, 2000);
} while (i--);
}
2 changes: 1 addition & 1 deletion examples/QuadriDigit/QuardriDigit.ino
Expand Up @@ -30,6 +30,6 @@ void setup() {
void loop() {
unsigned i = 9999;
do {
ss.print(i, 2000);
ss.print(i, -1, 2000);
} while (i--);
}
2 changes: 1 addition & 1 deletion examples/TriDigit/TriDigit.ino
Expand Up @@ -29,6 +29,6 @@ void setup() {
void loop() {
unsigned i = 999;
do {
ss.print(i, 2000);
ss.print(i, -1, 2000);
} while (i--);
}
2 changes: 1 addition & 1 deletion examples/UniDigit/UniDigit.ino
Expand Up @@ -27,6 +27,6 @@ void setup() {
void loop() {
unsigned i = 9;
do {
ss.print(i, 2000);
ss.print(i, -1, 2000);
} while (i--);
}

0 comments on commit ee8030b

Please sign in to comment.