Skip to content

Commit

Permalink
2.4.0 - Common anode support
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
BlaT2512 committed Dec 1, 2019
1 parent 3e370fa commit c14e2e7
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 30 deletions.
18 changes: 8 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 <sevenSegment.h> // 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 <sevenSegment.h> // 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 <sevenSegment.h> // 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
Expand Down Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions examples/Letter_cycle/Letter_cycle.ino
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions examples/Number_cycle/Number_cycle.ino
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions examples/Serial_input/Serial_input.ino
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name=sevenSegment
version=2.3.1
version=2.4.0
author=Blake Tourneur <[email protected]>
maintainer=Blake Tourneur <[email protected]>
sentence=Control infinite seven segment displays with your arduino!
Expand Down
41 changes: 35 additions & 6 deletions src/sevenSegment.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -111,16 +112,18 @@ 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);
_Data = Data;
_Clock = Clock;
_Latch = Latch;
_segMode = 3;
_cathode = cathode;
}

void sevenSegment::_Clocking(){
Expand All @@ -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));
Expand All @@ -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));
Expand All @@ -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){
Expand Down
9 changes: 5 additions & 4 deletions src/sevenSegment.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
};

Expand Down

0 comments on commit c14e2e7

Please sign in to comment.