Remarks

SevenSegment
Status Working
Source code GitHub
NuGet package

A seven-segment display is a form of electronic display device used to show decimal numbers. These displays are widely used in digital clocks, electronic meters, basic calculators, and other electronic devices that display numerical information.

The SevenSegment driver is used to represent a 7-segment display controlled via GPIO.

The displays are simply a collection of single color leds in a pre-configured solutions. The segments are commonly referred to using letters, the top segment is A, and increase alphabetically as you move clockwise around the display. The center segment is G and the decimal or period is dp.

The pinouts vary from device to device, check the documentation to map the pinouts to a specific segment. The come in a wide selection of colors and may be common anode or common cathode.

Purchasing

You can get 7-segment displays from the following supplier(s):

Code Example

The following example shows how to initialize a SevenSegment display and iterates through all possible characters:

public class MeadowApp : App<F7Micro, MeadowApp>
{
    public MeadowApp ()
    {
        var sevenSegment = new SevenSegment
        (
            portA: Device.CreateDigitalOutputPort(Device.Pins.D14),
            portB: Device.CreateDigitalOutputPort(Device.Pins.D15),
            portC: Device.CreateDigitalOutputPort(Device.Pins.D06),
            portD: Device.CreateDigitalOutputPort(Device.Pins.D07),
            portE: Device.CreateDigitalOutputPort(Device.Pins.D08),
            portF: Device.CreateDigitalOutputPort(Device.Pins.D13),
            portG: Device.CreateDigitalOutputPort(Device.Pins.D12),
            portDecimal: Device.CreateDigitalOutputPort(Device.Pins.D05),
            isCommonCathode: true
        );

        bool showDecimal = false;

        while (true)
        {
            foreach (CharacterType character in Enum.GetValues(typeof(CharacterType)))
            {
                if (character != CharacterType.count)
                {
                    Console.WriteLine("Character: {0}", character.ToString());
                    sevenSegment.SetDisplay(character, showDecimal);
                }
                Thread.Sleep(1000);
            }

            showDecimal = !showDecimal;
        }            
    }
}

Sample projects available on GitHub

Wiring Example

To wire a Common Cathode Seven Segment Display (like the 5161AS) to your Meadow board, connect the following:

SevenSegment Meadow Pin
portA D14
portB D15
PortC D06
PortD D07
PortE D08
PortF D13
PortG D12
portDecimal D05
Common Cathode GND

It should look like the following diagram:

Characteristic Locus
Inheritance System.Object > SevenSegment
Inherited Members System.Object.ToString() System.Object.Equals(System.Object) System.Object.Equals(System.Object, System.Object) System.Object.ReferenceEquals(System.Object, System.Object) System.Object.GetHashCode() System.Object.GetType() System.Object.MemberwiseClone()
Namespace Meadow.Foundation.Displays.Led
Assembly SevenSegment.dll

Syntax

public class SevenSegment

Constructors

View Source

SevenSegment(IDigitalOutputPort, IDigitalOutputPort, IDigitalOutputPort, IDigitalOutputPort, IDigitalOutputPort, IDigitalOutputPort, IDigitalOutputPort, IDigitalOutputPort, Boolean)

Creates a SevenSegment connected to the especified IDigitalOutputPorts

Declaration
public SevenSegment(IDigitalOutputPort portA, IDigitalOutputPort portB, IDigitalOutputPort portC, IDigitalOutputPort portD, IDigitalOutputPort portE, IDigitalOutputPort portF, IDigitalOutputPort portG, IDigitalOutputPort portDecimal, bool isCommonCathode)

Parameters

Type Name Description
IDigitalOutputPort portA
IDigitalOutputPort portB
IDigitalOutputPort portC
IDigitalOutputPort portD
IDigitalOutputPort portE
IDigitalOutputPort portF
IDigitalOutputPort portG
IDigitalOutputPort portDecimal
System.Boolean isCommonCathode
View Source

SevenSegment(IIODevice, IPin, IPin, IPin, IPin, IPin, IPin, IPin, IPin, Boolean)

Creates a SevenSegment connected to the especified IPins to a IODevice

Declaration
public SevenSegment(IIODevice device, IPin pinA, IPin pinB, IPin pinC, IPin pinD, IPin pinE, IPin pinF, IPin pinG, IPin pinDecimal, bool isCommonCathode)

Parameters

Type Name Description
IIODevice device
IPin pinA
IPin pinB
IPin pinC
IPin pinD
IPin pinE
IPin pinF
IPin pinG
IPin pinDecimal
System.Boolean isCommonCathode

Methods

View Source

SetDisplay(SevenSegment.CharacterType, Boolean)

Displays the especified character

Declaration
public void SetDisplay(SevenSegment.CharacterType character, bool showDecimal = false)

Parameters

Type Name Description
SevenSegment.CharacterType character
System.Boolean showDecimal
View Source

SetDisplay(Char, Boolean)

Displays the especified valid character

Declaration
public void SetDisplay(char character, bool showDecimal = false)

Parameters

Type Name Description
System.Char character
System.Boolean showDecimal