From c14e2e7cce212d33955ec581fcdc9e07320f34d6 Mon Sep 17 00:00:00 2001 From: Blake Tourneur Date: Sun, 1 Dec 2019 13:20:32 +1030 Subject: [PATCH] 2.4.0 - Common anode support Support for common anode displays has been updated, by specifying a boolean in the declaration on whether it is common anode/cathode (true is default and it is common cathode). Examples have been updated for this support. --- README.md | 18 +++++------ examples/Letter_cycle/Letter_cycle.ino | 6 ++-- examples/Number_cycle/Number_cycle.ino | 6 ++-- examples/Serial_input/Serial_input.ino | 6 ++-- library.properties | 2 +- src/sevenSegment.cpp | 41 ++++++++++++++++++++++---- src/sevenSegment.h | 9 +++--- 7 files changed, 58 insertions(+), 30 deletions(-) diff --git a/README.md b/README.md index 031829c..89e1415 100644 --- a/README.md +++ b/README.md @@ -8,25 +8,25 @@ To install sevenSegment, install it using the Arduino library manager, or manual # Using the library / syntax ### Declare the library -You can either declare the library for use with straight wiring, straight wiring with a decimal point or with a shift register. +You can either declare the library for use with straight wiring, straight wiring with a decimal point or with a shift register. You also specify whether you have a common cathode (one ground pin on the display and a positive pin for all the segments) or a common anode display (one positive pin on the display and a ground pin for all the segments). True is common cathode and False is common anode. STRAIGHT WIRING: ``` #include // Include the sevenSegment library -sevenSegment sevseg(5, 6, 7, 8, 9, 10, 11); // Set the pins you want -// Segments: a, b, c, d, e, f, g +sevenSegment sevseg(5, 6, 7, 8, 9, 10, 11, true); // Set the pins you want and whether the display is common anode/cathode +// Segments: a, b, c, d, e, f, g, c a/c ``` STRAIGHT WIRING WITH DECIMAL POINT: ``` #include // Include the sevenSegment library -sevenSegment sevseg(5, 6, 7, 8, 9, 10, 11, 12); // Set the pins you want -// Segments: a, b, c, d, e, f, g, dp +sevenSegment sevseg(5, 6, 7, 8, 9, 10, 11, 12, true); // Set the pins you want and whether the display is common anode/cathode +// Segments: a, b, c, d, e, f, g, dp, c a/c ``` SHIFT REGISTER WIRING: ``` #include // Include the sevenSegment library -sevenSegment sevseg(5, 6, 7); // Set the pins you want -// Pins: D, C, L +sevenSegment sevseg(5, 6, 7, true); // Set the pins you want and whether the display is common anode/cathode +// Pins: D, C, L, c a/c ``` ### Commands @@ -68,9 +68,7 @@ The examples available for this library are: # Updates Updates can be done through the Arduino Library Manager, or by downloading the latest package from [releases page](https://github.com/Blake-Tourneur/sevenSegment/releases). -#### Future update list (current version 2.3.1): -2.4.0 - Add support for common anode displays (the library currently only supports common cathode displays) - +#### Future update list (current version 2.4.0): 2.5.0 - Add support for BCD (binary coded decimal) decoder wired displays 3.0.0 - Add support for 16-segment displays diff --git a/examples/Letter_cycle/Letter_cycle.ino b/examples/Letter_cycle/Letter_cycle.ino index 8eb2e21..eb1f11b 100644 --- a/examples/Letter_cycle/Letter_cycle.ino +++ b/examples/Letter_cycle/Letter_cycle.ino @@ -3,9 +3,9 @@ // The library can either be declared using pins straight (sega-segg), pins straight with decimal point (sega-segdp) or with a shift register (data, clock, latch) (dp or no dp) // Un-comment the one you are using below! -//sevenSegment sevseg(5, 6, 7, 8, 9, 10, 11); // Uncomment for straight wiring pins (segment a - segment g) -//sevenSegment sevseg(5, 6, 7, 8, 9, 10, 11, 12); // Uncomment for straight wiring pins with a decimal point (segment a - decimal point) -//sevenSegment sevseg(5, 6, 7); // Uncomment for shift register wiring pins (Data, Clock, Latch) (it doesn't matter if it has a decimal point or not) +//sevenSegment sevseg(5, 6, 7, 8, 9, 10, 11, true); // Uncomment for straight wiring pins (segment a - segment g) +//sevenSegment sevseg(5, 6, 7, 8, 9, 10, 11, 12, true); // Uncomment for straight wiring pins with a decimal point (segment a - decimal point) +//sevenSegment sevseg(5, 6, 7, true); // Uncomment for shift register wiring pins (Data, Clock, Latch) (it doesn't matter if it has a decimal point or not) int delayTime = 1000; // Milliseconds to delay after each number (default 1 second) int displays = 4; // Number of seven segment displays you have daisy-chained (default 1) diff --git a/examples/Number_cycle/Number_cycle.ino b/examples/Number_cycle/Number_cycle.ino index 99d4910..d033e24 100644 --- a/examples/Number_cycle/Number_cycle.ino +++ b/examples/Number_cycle/Number_cycle.ino @@ -3,9 +3,9 @@ // The library can either be declared using pins straight (sega-segg), pins straight with decimal point (sega-segdp) or with a shift register (data, clock, latch) (dp or no dp) // Un-comment the one you are using below! -//sevenSegment sevseg(5, 6, 7, 8, 9, 10, 11); // Uncomment for straight wiring pins (segment a - segment g) -//sevenSegment sevseg(5, 6, 7, 8, 9, 10, 11, 12); // Uncomment for straight wiring pins with a decimal point (segment a - decimal point) -//sevenSegment sevseg(5, 6, 7); // Uncomment for shift register wiring pins (Data, Clock, Latch) (it doesn't matter if it has a decimal point or not) +//sevenSegment sevseg(5, 6, 7, 8, 9, 10, 11, true); // Uncomment for straight wiring pins (segment a - segment g) +//sevenSegment sevseg(5, 6, 7, 8, 9, 10, 11, 12), true; // Uncomment for straight wiring pins with a decimal point (segment a - decimal point) +//sevenSegment sevseg(5, 6, 7, true); // Uncomment for shift register wiring pins (Data, Clock, Latch) (it doesn't matter if it has a decimal point or not) int delayTime = 1000; // Milliseconds to delay after each number (default 1 second) int displays = 4; // Number of seven segment displays you have daisy-chained (default 1) diff --git a/examples/Serial_input/Serial_input.ino b/examples/Serial_input/Serial_input.ino index b3a3305..54ba91c 100644 --- a/examples/Serial_input/Serial_input.ino +++ b/examples/Serial_input/Serial_input.ino @@ -3,9 +3,9 @@ // The library can either be declared using pins straight (sega-segg), pins straight with decimal point (sega-segdp) or with a shift register (data, clock, latch) (dp or no dp) // Un-comment the one you are using below! -//sevenSegment sevseg(5, 6, 7, 8, 9, 10, 11); // Uncomment for straight wiring pins (segment a - segment g) -//sevenSegment sevseg(5, 6, 7, 8, 9, 10, 11, 12); // Uncomment for straight wiring pins with a decimal point (segment a - decimal point) -//sevenSegment sevseg(5, 6, 7); // Uncomment for shift register wiring pins (Data, Clock, Latch) (it doesn't matter if it has a decimal point or not) +//sevenSegment sevseg(5, 6, 7, 8, 9, 10, 11, true); // Uncomment for straight wiring pins (segment a - segment g) +//sevenSegment sevseg(5, 6, 7, 8, 9, 10, 11, 12, true); // Uncomment for straight wiring pins with a decimal point (segment a - decimal point) +//sevenSegment sevseg(5, 6, 7, true); // Uncomment for shift register wiring pins (Data, Clock, Latch) (it doesn't matter if it has a decimal point or not) String incoming = ""; // This is where we will store what is recieved from the serial int displays = 4; // Change this to the numbers of 7seg-displays you are using (daisy chained) diff --git a/library.properties b/library.properties index 195e9a8..638aab3 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=sevenSegment -version=2.3.1 +version=2.4.0 author=Blake Tourneur maintainer=Blake Tourneur sentence=Control infinite seven segment displays with your arduino! diff --git a/src/sevenSegment.cpp b/src/sevenSegment.cpp index 61a3acf..0a26591 100644 --- a/src/sevenSegment.cpp +++ b/src/sevenSegment.cpp @@ -75,7 +75,7 @@ const int sevenSegment::_numMatrix[62][8] PROGMEM { {0,0,0,0,0,0,0,1} //CHARACTER . }; -sevenSegment::sevenSegment(int sega, int segb, int segc, int segd, int sege, int segf, int segg){ +sevenSegment::sevenSegment(int sega, int segb, int segc, int segd, int sege, int segf, int segg, bool cathode){ pinMode(sega, OUTPUT); pinMode(segb, OUTPUT); pinMode(segc, OUTPUT); @@ -91,9 +91,10 @@ sevenSegment::sevenSegment(int sega, int segb, int segc, int segd, int sege, int _segf = segf; _segg = segg; _segMode = 1; + _cathode = cathode; } -sevenSegment::sevenSegment(int sega, int segb, int segc, int segd, int sege, int segf, int segg, int segdp){ +sevenSegment::sevenSegment(int sega, int segb, int segc, int segd, int sege, int segf, int segg, int segdp, bool cathode){ pinMode(sega, OUTPUT); pinMode(segb, OUTPUT); pinMode(segc, OUTPUT); @@ -111,9 +112,10 @@ sevenSegment::sevenSegment(int sega, int segb, int segc, int segd, int sege, int _segg = segg; _segdp = segdp; _segMode = 2; + _cathode = cathode; } -sevenSegment::sevenSegment(int Data, int Clock, int Latch){ +sevenSegment::sevenSegment(int Data, int Clock, int Latch, bool cathode){ pinMode(Data, OUTPUT); pinMode(Clock, OUTPUT); pinMode(Latch, OUTPUT); @@ -121,6 +123,7 @@ sevenSegment::sevenSegment(int Data, int Clock, int Latch){ _Clock = Clock; _Latch = Latch; _segMode = 3; + _cathode = cathode; } void sevenSegment::_Clocking(){ @@ -136,14 +139,21 @@ void sevenSegment::_Latching(){ } void sevenSegment::_Write(int _Numeral){ - if (_segMode == 3) { + if (_segMode == 3 && _cathode) { for (_bitNum = 0;_bitNum < 8;_bitNum++){ digitalWrite(_Data,pgm_read_word_near(_numMatrix[_Numeral] + _bitNum)); _Clocking(); } _Latching(); } - else if (_segMode == 1) { + else if (_segMode == 3 && !_cathode) { + for (_bitNum = 0;_bitNum < 8;_bitNum++){ + digitalWrite(_Data,!pgm_read_word_near(_numMatrix[_Numeral] + _bitNum)); + _Clocking(); + } + _Latching(); + } + else if (_segMode == 1 && _cathode) { digitalWrite(_segg,pgm_read_word_near(_numMatrix[_Numeral] + 0)); digitalWrite(_segf,pgm_read_word_near(_numMatrix[_Numeral] + 1)); digitalWrite(_sege,pgm_read_word_near(_numMatrix[_Numeral] + 2)); @@ -152,7 +162,16 @@ void sevenSegment::_Write(int _Numeral){ digitalWrite(_segb,pgm_read_word_near(_numMatrix[_Numeral] + 5)); digitalWrite(_sega,pgm_read_word_near(_numMatrix[_Numeral] + 6)); } - else if (_segMode == 2) { + else if (_segMode == 1 && !_cathode) { + digitalWrite(_segg,!pgm_read_word_near(_numMatrix[_Numeral] + 0)); + digitalWrite(_segf,!pgm_read_word_near(_numMatrix[_Numeral] + 1)); + digitalWrite(_sege,!pgm_read_word_near(_numMatrix[_Numeral] + 2)); + digitalWrite(_segd,!pgm_read_word_near(_numMatrix[_Numeral] + 3)); + digitalWrite(_segc,!pgm_read_word_near(_numMatrix[_Numeral] + 4)); + digitalWrite(_segb,!pgm_read_word_near(_numMatrix[_Numeral] + 5)); + digitalWrite(_sega,!pgm_read_word_near(_numMatrix[_Numeral] + 6)); + } + else if (_segMode == 2 && _cathode) { digitalWrite(_segg,pgm_read_word_near(_numMatrix[_Numeral] + 0)); digitalWrite(_segf,pgm_read_word_near(_numMatrix[_Numeral] + 1)); digitalWrite(_sege,pgm_read_word_near(_numMatrix[_Numeral] + 2)); @@ -162,6 +181,16 @@ void sevenSegment::_Write(int _Numeral){ digitalWrite(_sega,pgm_read_word_near(_numMatrix[_Numeral] + 6)); digitalWrite(_segdp,pgm_read_word_near(_numMatrix[_Numeral] + 7)); } + else if (_segMode == 2 && !_cathode) { + digitalWrite(_segg,!pgm_read_word_near(_numMatrix[_Numeral] + 0)); + digitalWrite(_segf,!pgm_read_word_near(_numMatrix[_Numeral] + 1)); + digitalWrite(_sege,!pgm_read_word_near(_numMatrix[_Numeral] + 2)); + digitalWrite(_segd,!pgm_read_word_near(_numMatrix[_Numeral] + 3)); + digitalWrite(_segc,!pgm_read_word_near(_numMatrix[_Numeral] + 4)); + digitalWrite(_segb,!pgm_read_word_near(_numMatrix[_Numeral] + 5)); + digitalWrite(_sega,!pgm_read_word_near(_numMatrix[_Numeral] + 6)); + digitalWrite(_segdp,!pgm_read_word_near(_numMatrix[_Numeral] + 7)); + } } void sevenSegment::display(char charac){ diff --git a/src/sevenSegment.h b/src/sevenSegment.h index 1d46318..40a2f1d 100644 --- a/src/sevenSegment.h +++ b/src/sevenSegment.h @@ -13,9 +13,9 @@ class sevenSegment { public: - sevenSegment(int sega, int segb, int segc, int segd, int sege, int segf, int segg); - sevenSegment(int sega, int segb, int segc, int segd, int sege, int segf, int segg, int segdp); - sevenSegment(int Data, int Clock, int Latch); + sevenSegment(int sega, int segb, int segc, int segd, int sege, int segf, int segg, bool cathode); + sevenSegment(int sega, int segb, int segc, int segd, int sege, int segf, int segg, int segdp, bool cathode); + sevenSegment(int Data, int Clock, int Latch, bool cathode = true); void display(char charac); void clear(int displays = 1); void displayString(String word, int displays = 1, bool cleardisp = true); @@ -50,8 +50,9 @@ class sevenSegment // 6 - 14 segment shift register display (16-bit shift register so includes decimal point and one extra output which isn't used) // 7 - 16 segment straight wired display // 8 - 16 segment straight wired display, decimal point - // 9 - 16 segment shift register display (16-bit shift register so you can't use a decimal point) + // 9 - 16 segment shift register display (16-bit shift register so you can't use a decimal point unless it is wired up straight to the arduino board) // 10 - Dot matrix display + bool _cathode; static const int _numMatrix[62][8] PROGMEM; };