# SegmentDisplay

A collection of different seven-segment displays for showing numbers.

## Segments

Each digit of a SegmentDisplay has its segments enumerated as such:

**1**

**2**

**3**

**4**

**5**

**6**

**7**

**8**

Each digit of a multi-digit display has all these segments, except for the display with two dots in the middle. In the case of that display, the two dots are instead enumerated as their own "digit" in which each segment is each dot, making the total of "digits" for it 5. Additionally, the 8th segment (the dot) is absent.

**4 digits**

**5 "digits"**

## Properties

The displays are enumerated in tables of tables. The outer table is each display digit, the inner table is each segment in that digit. Therefore the tables must be accessed by `[digit][segment]`

.

A table that maps the lit/unlit state of each of the segments in the display.

A table that maps the color of each of the segments in the display.

## Methods

ShowDigit(groupIndex number, digit number)A helper function to show a numerical digit in a whole display.

`groupIndex`

is the digit that you want the number to show on,`digit`

is the number you want to show.

SetDigitColor(groupIndex number, color color)A helper function to set the color of a whole numerical digit at once.

`groupIndex`

is the digit that you want to change the color of,`color`

is the color you want to set it to.

## Examples

Here's how to display the CPU time (measured in seconds) on a 4-digit SegmentDisplay:

```
-- shorthand display module to "disp"
local disp = gdt.SegmentDisplay0
function update()
-- store the CPU time rounded down
local time = math.floor(gdt.CPU0.Time)
-- each digit gets remainder of division by 10
-- each next digit gets divided by 10 to get next decimal place
disp:ShowDigit(4, time % 10)
disp:ShowDigit(3, (time/10) % 10)
disp:ShowDigit(2, (time/100) % 10)
disp:ShowDigit(1, (time/1000) % 10)
end
```

The Collect the Dot cookbook example also makes use of a SegmentDisplay to show an increasing counter.