A collection of different seven-segment displays for showing numbers.
Each digit of a SegmentDisplay has its segments enumerated as such:
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.
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
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.
A helper function to show a numerical digit in a whole display.
groupIndexis the digit that you want the number to show on,
digitis the number you want to show.
A helper function to set the color of a whole numerical digit at once.
groupIndexis the digit that you want to change the color of,
coloris 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) end
The Collect the Dot cookbook example also makes use of a SegmentDisplay to show an increasing counter.