Arduino library for vairous types of 7 segment LED modules. The library is capable of driving a seven segment display from 1 to 8 digits, or combinations of modules making up to 8 digits. The module can also be of common anode or common cathode type.
Current supported products sold in our store:
1-DIGIT 7-SEGMENT LED MODULE SKU: HCOPTO0012
4-DIGIT 7-SEGMENT LED MODULE SKU: HCOPTO0013
The library makes use of the hardware timer 2 to refresh the display in the background leaving your sketch completely free to run your own code. It is includes an alphanumeric character set and with built in print commands both text and decimal numbers can easily be output to the display.
You will need to download (please log in to download the library) and unzip this library to the Arduino development environments library area.
On Windows:
My Documents\Arduino\libraries\
On Mac:
Documents/Arduino/libraries/
Linux:
Usually found within the users home area under /Arduino/libraries/
Using the HC7Seg library
To use the library just include the HC7Seg.h header file. E.g:
Code: Select all
#include "HC7Seg.h"
You will then need to create an instance of the library with the correct configuration for your module:
Code: Select all
HC7Seg HC7Seg(Type, SEG_A, SEG_B, SEG_C, SEG_D, SEG_E, SEG_F, SEG_G, SEG_DP, DIG_1, [DIG_2], [DIG_3], [DIG_4], [DIG_5], [DIG_6], [DIG_7], [DIG_8])
Where the first parameter Type is the type of module you are using and may be one of the following options:
COM_ANODE_1DIG (1 digit common anode display)
COM_ANODE_2DIG (2 digit common anode display)
COM_ANODE_3DIG (3 digit common anode display)
COM_ANODE_4DIG (4 digit common anode display)
COM_ANODE_5DIG (5 digit common anode display)
COM_ANODE_6DIG (6 digit common anode display)
COM_ANODE_7DIG (7 digit common anode display)
COM_ANODE_8DIG (8 digit common anode display)
COM_CATHODE_1DIG (1 digit common cathode display)
COM_CATHODE_2DIG (2 digit common cathode display)
COM_CATHODE_3DIG (3 digit common cathode display)
COM_CATHODE_4DIG (4 digit common cathode display)
COM_CATHODE_5DIG (5 digit common cathode display)
COM_CATHODE_6DIG (6 digit common cathode display)
COM_CATHODE_7DIG (7 digit common cathode display)
COM_CATHODE_8DIG (8 digit common cathode display)
SEG_A is the digital pin number that controls the segment A on your module
SEG_B is the digital pin number that controls the segment B on your module
SEG_C is the digital pin number that controls the segment C on your module
SEG_D is the digital pin number that controls the segment D on your module
SEG_E is the digital pin number that controls the segment E on your module
SEG_F is the digital pin number that controls the segment F on your module
SEG_G is the digital pin number that controls the segment G on your module
SEG_DP is the digital pin number that controls the decimal point on your module.
DIG_1 is the digital pin that controls the first digit (right most) on your module.
DIG_2 is optional digital pin that controls the second digit on your module.
DIG_3 is optional digital pin that controls the third digit on your module.
DIG_4 is optional digital pin that controls the forth digit on your module.
DIG_5 is optional digital pin that controls the fifth digit on your module.
DIG_6 is optional digital pin that controls the sixth digit on your module.
DIG_7 is optional digital pin that controls the seventh digit on your module.
DIG_8 is optional digital pin that controls the eighth digit on your module.
The following functions are available with this library:
Code: Select all
HC7Seg.print7Seg(Text, Offset, DP);
Text is the string or null terminated character array containing the text to print.
Offset is the digit position from where the text will start.
1 = the right most digit, 2 = second right most digit, etc. Characters can also be positioned off display.
DP is an optional parameter (default = false) which specifies if to use the seven segments DP led to represent full stops and decimal points. Valid values for DP are
false = full stops and decimal points will take up a whole digit on the display.
true = full stops and decimal points will use the DP segment on the preceding character/number.
Code: Select all
HC7Seg.print7Seg(value, Offset, DecimalPlaces, DP);
Prints a signed decimal number to the display where:
Value is the signed floating point number to display
Offset is the digit position from where the text will start.
1 = the right most digit, 2 = second right most digit, etc. Characters can also be positioned off display.
DecimalPlaces is optional and set number of decimal places to display the number to.
DP is an optional parameter (default = true) which specifies if to use the seven segments DP led to represent full stops and decimal points. Valid values for DP are
false = full stops and decimal points will take up a whole digit on the display.
true = full stops and decimal points will use the DP segment on the preceding character/number.
Code: Select all
HC7Seg.SetDigit(Digit, Data);
Digit is the digit number for the display to change.
Valid values are from 1 to 8
Data is an 8 bit byte which directly sets the state of each segment of the specified digit.
Code: Select all
HC7Seg.clear();
Clears the output buffer and display (turns off all LEDs)
Code: Select all
/* FILE: HC7Seg_Example
DATE: 12/10/16
VERSION: 0.1
AUTHOR: Andrew Davies
21/01/16 version 0.1: Original version
This sketch demonstrates how to use the HC7Seg Arduino library to control
a 7 segment LED display. The library is capable of driving a seven segment
display from 1 to 8 digits, or combinations of modules making up to 8 digits.
The module can also be of common anode or common cathode type. This sketch is
configured for a 4 digit common cathode display see item SKU HCOPTO0013 in our
store hobbycomponents.com.
The HC7Seg library can be downloaded from the software section of our support
forum here:
http://forum.hobbycomponents.com/viewforum.php?f=58
You may copy, alter and reuse this code in any way you like, but please leave
reference to HobbyComponents.com in your comments if you redistribute this code.
This software may not be used directly for the purpose of selling products that
directly compete with Hobby Components Ltd's own range of products.
THIS SOFTWARE IS PROVIDED "AS IS". HOBBY COMPONENTS MAKES NO WARRANTIES, WHETHER
EXPRESS, IMPLIED OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ACCURACY OR LACK OF NEGLIGENCE.
HOBBY COMPONENTS SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE FOR ANY DAMAGES,
INCLUDING, BUT NOT LIMITED TO, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES FOR ANY
REASON WHATSOEVER.
*/
#include "Arduino.h"
#include "HC7Seg.h"
/* Digital pins used to drive each digit and digit segment of your display. Please
change these to match the connections to your module */
#define SEG_A 2
#define SEG_B 4
#define SEG_C 8
#define SEG_D 6
#define SEG_E 7
#define SEG_F 3
#define SEG_G 9
#define SEG_DP 5
#define DIG_1 19
#define DIG_2 12
#define DIG_3 11
#define DIG_4 10
//HC7Seg HC7Seg(COM_CATHODE_1DIG, SEG_A, SEG_B, SEG_C, SEG_D, SEG_E, SEG_F, SEG_G, SEG_DP, DIG_1); //1 digit common cathode example (e.g. HCOPTO0012)
HC7Seg HC7Seg(COM_CATHODE_4DIG, SEG_A, SEG_B, SEG_C, SEG_D, SEG_E, SEG_F, SEG_G, SEG_DP, DIG_1, DIG_2, DIG_3, DIG_4); //4 digit common cathode example (e.g. HCOPTO0013)
//HC7Seg HC7Seg(COM_ANODE_8DIG, SEG_A, SEG_B, SEG_C, SEG_D, SEG_E, SEG_F, SEG_G, SEG_DP, DIG_1, DIG_2, DIG_3, DIG_4, DIG_5, DIG_6, DIG_7, DIG_8); //8 digit common anode example
void setup()
{
}
void loop()
{
/* Scroll some text */
for(int i = 0; i <= 18; i++)
{
HC7Seg.clear();
HC7Seg.print7Seg("HELLO WORLD !! ", i);
delay(150);
}
/* Scroll an integer number */
for(int i = 0; i <= 14; i++)
{
HC7Seg.clear();
HC7Seg.print7Seg(-123.45, i, 2);
delay(150);
}
}