From ee8030b20e0dc712871d6caf9728b50386b1873a Mon Sep 17 00:00:00 2001 From: Like Ma Date: Sun, 21 Oct 2012 23:53:05 +0800 Subject: [PATCH] Fix #4 by enhancing fixed point displaying. --- SevenSegmentDisplay.h | 49 ++++++++++++++++++++------- SevenSegmentDisplay.inl | 6 ++-- examples/BiDigit/BiDigit.ino | 2 +- examples/QuadriDigit/QuardriDigit.ino | 2 +- examples/TriDigit/TriDigit.ino | 2 +- examples/UniDigit/UniDigit.ino | 2 +- 6 files changed, 43 insertions(+), 20 deletions(-) diff --git a/SevenSegmentDisplay.h b/SevenSegmentDisplay.h index 9a464ea..3ea3640 100644 --- a/SevenSegmentDisplay.h +++ b/SevenSegmentDisplay.h @@ -2,17 +2,6 @@ * \file SevenSegmentDisplay.h * \brief Arduino 7-Segment Display * \author Like Ma - * - * a - * _____ - * | | - * f | g | b - * |_____| - * | | - * e | | c - * |_____| . dp - * - * d */ #ifndef SEVENSEGMENTDISPLAY_H @@ -51,20 +40,54 @@ struct QuadriDigit { template 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]; }; diff --git a/SevenSegmentDisplay.inl b/SevenSegmentDisplay.inl index 557e1d6..177437b 100644 --- a/SevenSegmentDisplay.inl +++ b/SevenSegmentDisplay.inl @@ -127,16 +127,16 @@ void SevenSegmentDisplay::printFloat(float n) } template -void SevenSegmentDisplay::print(unsigned n, unsigned long duration) +void SevenSegmentDisplay::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); diff --git a/examples/BiDigit/BiDigit.ino b/examples/BiDigit/BiDigit.ino index 68be508..ef5cb6a 100644 --- a/examples/BiDigit/BiDigit.ino +++ b/examples/BiDigit/BiDigit.ino @@ -28,6 +28,6 @@ void setup() { void loop() { unsigned i = 99; do { - ss.print(i, 2000); + ss.print(i, -1, 2000); } while (i--); } diff --git a/examples/QuadriDigit/QuardriDigit.ino b/examples/QuadriDigit/QuardriDigit.ino index 70c1276..372cc29 100644 --- a/examples/QuadriDigit/QuardriDigit.ino +++ b/examples/QuadriDigit/QuardriDigit.ino @@ -30,6 +30,6 @@ void setup() { void loop() { unsigned i = 9999; do { - ss.print(i, 2000); + ss.print(i, -1, 2000); } while (i--); } diff --git a/examples/TriDigit/TriDigit.ino b/examples/TriDigit/TriDigit.ino index 747d4c2..4b13657 100644 --- a/examples/TriDigit/TriDigit.ino +++ b/examples/TriDigit/TriDigit.ino @@ -29,6 +29,6 @@ void setup() { void loop() { unsigned i = 999; do { - ss.print(i, 2000); + ss.print(i, -1, 2000); } while (i--); } diff --git a/examples/UniDigit/UniDigit.ino b/examples/UniDigit/UniDigit.ino index 7600c60..2583c1e 100644 --- a/examples/UniDigit/UniDigit.ino +++ b/examples/UniDigit/UniDigit.ino @@ -27,6 +27,6 @@ void setup() { void loop() { unsigned i = 9; do { - ss.print(i, 2000); + ss.print(i, -1, 2000); } while (i--); }