Arduino seven segment display

numberDisplayHere is the code of the library I am currently working on for the Arduino for interfacing with a 7 segment display with 0-2 dots.

Currently It only supports 1 dot but will be updated at some point.

Please feel free to use this code and comment on it so it can be improved!

Sources: http://www.hacktronics.com/Tutorials/arduino-and-7-segment-led.html

 

Code for numberDisplay.cpp:

/*
Library: numberDisplay
Purpose: controls a 7 segment LCD display with one dot on bottom right.
Author: Jeremy Cooper (jeremy@jeremycooper.info)
Constructer: Receives the pins associated to the display, in order A,B,C,D,E,F,G,DOT as discribed in http://www.hacktronics.com/Tutorials/arduino-and-7-segment-led.html
void setDigit(): Receives a digit from 0-9 to set on the display
void clear(): Clears the display
displayTest(): Tests all the led’s on the display.
Work to do:
Overloaded constructer to support displays with no dots.
*/

#include “Arduino.h”
#include “numberDisplay.h”
//These define array sizes so loops know the number of pins (so code can be used with displays with and without the DOT
#define diodePins_SIZE 8
int diodePins[diodePins_SIZE];
#define seven_seg_digits_SIZEW 7
#define seven_seg_digits_SIZEH 10
#define seven_seg_lines_SIZEW 8
#define seven_seg_lines_SIZEH 8

//Array of sequences for setting various numbers. #DO NOT MODIFY#
byte seven_seg_digits[seven_seg_digits_SIZEH][seven_seg_digits_SIZEW] = {
{ 0,0,0,0,0,0,1 }, // = 0
{ 1,0,0,1,1,1,1 }, // = 1
{ 0,0,1,0,0,1,0 }, // = 2
{ 0,0,0,0,1,1,0 }, // = 3
{ 1,0,0,1,1,0,0 }, // = 4
{ 0,1,0,0,1,0,0 }, // = 5
{ 0,1,0,0,0,0,0 }, // = 6
{ 0,0,0,1,1,1,1 }, // = 7
{ 0,0,0,0,0,0,0 }, // = 8
{ 0,0,0,0,1,0,0 } // = 9
};
//associates lines on display to lines on Arduino #DO NOT MODIFY#
byte seven_seg_lines[seven_seg_lines_SIZEH][seven_seg_lines_SIZEW] = {
{ 0,1,1,1,1,1,1,1 }, // = A
{ 1,0,1,1,1,1,1,1 }, // = B
{ 1,1,0,1,1,1,1,1 }, // = C
{ 1,1,1,0,1,1,1,1 }, // = D
{ 1,1,1,1,0,1,1,1 }, // = E
{ 1,1,1,1,1,0,1,1 }, // = F
{ 1,1,1,1,1,1,0,1 }, // = G
{ 1,1,1,1,1,1,1,0 }, // = Dot
};

//When this object is constructed it will get all the pins for making the display come on.
numberDisplay::numberDisplay(int LT,int LTR,int LBR,int LB,int LBL,int LTL,int LM,int RD)
{

pinMode(LT,OUTPUT);
pinMode(LTR,OUTPUT);
pinMode(LBR,OUTPUT);
pinMode(LB,OUTPUT);
pinMode(LBL,OUTPUT);
pinMode(LTL,OUTPUT);
pinMode(LM,OUTPUT);
pinMode(RD,OUTPUT);
diodePins[0]=LT;
diodePins[1]=LTR;
diodePins[2]=LBR;
diodePins[3]=LB;
diodePins[4]=LBL;
diodePins[5]=LTL;
diodePins[6]=LM;
diodePins[7]=RD;

}
//Function receives a number 0-9 then displays it
void numberDisplay::setDigit(byte digit) {
for (byte segCount = 0; segCount < 8; ++segCount) {
digitalWrite(diodePins[segCount], seven_seg_digits[digit][segCount]);
}
}
//tests the display by rotating in a clockwise direction
void numberDisplay::displayTest()
{
for(int linetest=0;linetest<seven_seg_lines_SIZEH;linetest++)
{
for (byte segCount = 0; segCount < 8; ++segCount) {
digitalWrite(diodePins[segCount], seven_seg_lines[linetest][segCount]);

}
delay(500);
}
//must clear display to remove dot.
displayClear();
}
//clears the display
void numberDisplay::displayClear(){
Serial.begin(9600);
for (byte segCount = 0; segCount < 8; ++segCount) {
digitalWrite(diodePins[segCount], 1);
Serial.println(diodePins[segCount]);

}

}

 

Code for  numberDisplay.h:

#ifndef numberDisplay_h
#define numberDisplay_h
#include “Arduino.h”
class numberDisplay
{
public:
numberDisplay(int LT,int LTR,int LBR,int LB,int LBL,int LTL,int LM,int RD);
void setDigit(byte digit);
void displayTest();
void displayClear();
private:
int _LTL;
int _LT;
int _LTR;
int _LBR;
int _LB;
int _LBL;
int _LM;
int _RD;
int _diodePins;

};

#endif