Skip to content

Arduino SevenSegmentDisplay class to automate the process of displaying information on a 7-Segment display device.

Notifications You must be signed in to change notification settings

tomiwa-adesanya/Arduino-Seven-Segment-Display

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

27 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

About Seven Segment Display Device

A Seven Segment display device is an electronic display device that consists of 7 LED segements labelled from a to g. The 7 LED Segments are arranged in a way to show specific decimal numerals or characters by lighting up difference combinations of the LED segments.

Diagram of a Seven Segement display Device

seven-segment-device

Based on the diagram of the Seven Segment display device above:

  • Pin 7 lights up the "a" LED segment.
  • Pin 6 lights up the "b" LED segment.
  • Pin 4 lights up the "c" LED segment.
  • Pin 2 lights up the "d" LED segment.
  • Pin 1 lights up the "e" LED segment.
  • Pin 9 lights up the "f" LED segment.
  • Pin 10 lights up the "g" LED segment.
  • Pin 5 lights up the "dp" LED segment.
  • Pins 3 and 8 are referred to as common(COM) pins. Either of them can be used.

The LED arrangement forms figure 8 which makes it possible to display all decimal numeric characters from 0 to 9. To display "1" on the display device for example, simply set the digital state of pins 7 and 6 to High.

About SevenSegmentDisplay library

SevenSegmentDisplay library is an arduino library that contains a SevenSegmentDisplay class with defined methods to automate the process of writing characters and values to a Seven Segment display device.

SevenSegmentDisplay comes with 28 predefined characters that can be displayed on a Seven Segment device without having to customise them yourself

The predefined characters that can be displayed include: 

    Decimal numerals: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9

    Alphabets(case-sensitive): A, b, C, d, E, F, H, I, J, L, n, O, P, q, r, S, t, U

SevenSegmentDisplay object methods include:

  • init(int a, int b, int c, int d, int e, int f, int g, int dpPin) initializes attributes of class and configures pin mode of each pin. To be called in the setup() function.

  • setState(int state=LOW) sets state all pins of the Seven Segment device to the same value. Value can either be LOW(0) or HIGH(1).

  • createCustomChar(byte customCharacters[]) creates user customised character that can be displayed on a Seven Segment Display device.

    Custom char is assigned a character(e.g 'v','+', e.t.c) or an int (e.g 1, 10, e.t.c) which is placed at index 0 of customCharacters[] passed as argument.

    The assigned character is used to refer to the customised character in the .writeCustomChar() method to display character on the device.

    byte array should be of length 8, with the remaining 7 values(index 1 to 7) as the state value (0 or 1) to be written to each of the seven segments (a to g) respectively.

  • writeCustomChar(byte value) displays customised character to device using the value assigned to the customised character.

  • writeChar(byte value) displays a single character on device. This method is implemented by the writeString method to display multiple characters.

  • writeString(String value, int delayPeriod) displays each character in string value one at a time with a delay period inbetween each charcter displayed.

    Note that there is a limit to the characters that can be displayed by a seven segment display device, for example it'd be impossible to display alphabet 'K'

Getting started

Connect Seven Segment pins to arduino board. The schematic below shows the pin connections for the ino sketch of this tutorial.

Seven Segment Display schematics

Download the library zip file, and install it in your Arduino IDE. Navigate to how to install arduino libraries to learn how to do so.

Within your Arduino sketch:

#include<SevenSegmentDisplay.h>

/*
  variables a - g, and dp should be replaced by their following pin values
*/

#define a 2 
#define b 3
#define c 4 
#define d 5
#define e 6
#define f 7
#define g 8
#define dp 9
 
SevenSegmentDisplay device;

/*
  To create customised character '-'
*/
byte custom1[] = {'-', 0, 0, 0, 0, 0, 0, 1}; 
 
void setup(){
  device.init(a, b, c, d, e, f, g, dp);
  device.createCustomChar(custom1)
}

void loop(){
  device.writeCustomChar('-'); // Displays custom1
  delay(2500);
  device.setState(LOW); // Turns off all LED after 2.5 seconds;
  device.writeString("HELLO", 2500); // Displays characters H E L L O to device with a 2.5 seconds interval
  delay(2500);
  device.setState(LOW);
  delay(2500);
} 

How to install an Arduino library in Arduino IDE

Step 1:

in your Arduino IDE toolbar click Sketch

Step 2:

select add "Include Library" the "add .zip Library"

Step 3:

navigate to library directory, select library and click "open"

About

Arduino SevenSegmentDisplay class to automate the process of displaying information on a 7-Segment display device.

Topics

Resources

Stars

Watchers

Forks

Languages