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


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

segment 1 1

segment 2 2

segment 3 3

segment 4 4

segment 5 5

segment 6 6

segment 7 7

segment 8 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 4 digits

5 digits 5 "digits"


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].

States {{boolean}}

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

Colors {{color}}

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


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.


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)

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