7 segment displays

Pages: 12
My program is supposed to prompt the program user to enter text to be displayed on our 7-segment display. The text string should accommodate up to 64 characters of text. The user input should then be displayed on the display and as user friendly output the program. Each letter, number, or space character (All Segments Off) should be displayed for a period of two seconds.

I managed to figure out how to correlate numbers to the 7 segment display and its output, along with how to receive input from the user, but I cant figure out how to make my program utilize strings and arrays to output the word as a whole. The program just outputs all of the characters in alphabetical order. What should I do?
You have 64 7-segment displays in a row? So you have 64*7 possible toggles in your code?

Let's get a baseline here. Can you, hardcoded/by hand, write out the logic to show, say, "77" on the display? If so, show the code that does that. If not, then just show how "7" is displayed.
Last edited on
you should post your code.
much depends on how you coded this... for example if you want to print 888 you either need to use a 3rd party library to move the cursor around (or maybe the weird command codes support that?) or you need to print all the top segments, eg _ _ _ and then go down a line, then print all the next row of | | | | | |
and go down a line... etc.
or you need some way to buffer that into one string, eg ___\n| | | | | | \n___\n ... etc.
how are you going to handle that part... ?

the cross association... you need a way to associate a container of your things such that container['8'] gives you all 7 segments as ON, or container['1'] gives only the upper and lower right segments on, ... etc. This also depends on what your 'things' look like how best to do that but a vector matching ascii (128 or 256 or something entries) with all the segments off by default and correct entries for 0-9 and any letters you support would do it easily.
Last edited on
We have just one 7 segment display that shows just 1 character. For example, it just shows 9-0 and A-Z. For 7 to be displayed the code would be:

// 7 will be displayed for 2 seconds
OutputData(88); // 88 correlates to 7 being displayed
Sleep(2000);; // 2000 correlates to 2 seconds
I was recommended to use parallel arrays to make the users word be outputted to the 7 segment display (letter by letter, with a 2 second delay)
The issue is, I don't have experience with parallel arrays and from the videos/forums ive visited, they dont exactly help with this modification.
Alright. So it can only print one letter at a time, you just want it to print it in order according to the user input. We don't know how 88 maps to '7' being displayed, but I'll trust that it does.

So, assuming you successfully have an array or string with data in it, you'd do some sort of for loop:

1
2
3
4
5
6
7
8
string str; // or char str[65] if strings aren't supported (extra space for null terminator)
// ...
for (int i = 0; i < length_of_string; i++)
{
    int code = char_to_seven_seg_disp(str[i]);
    OutputData(code);
    Sleep(2000);
}


Edit: I see your latest post now. That only confuses me more, as I don't see what this has to do with parallelism if you only have 1 seven-segment display. Of course, the way that seven-segment displays work is that every segment is going on and off at a very high frequency, but it sounds like you are already getting the correct digits to show up, so I don't think that's the issue here.
Last edited on
ah, ok.
88?
vector<bool> digit(7){};
enum segs {top,middle,bottom,upper_left, lower_left, upper_right, lower_right };
for 7:

digit[top] = digit[upper_right] = digit[lower_right] = true;
maybe something easier to understand like that?

however, if its too late to clean that up..
int relate[128] {};
relate['7'] = 88;
relate['8'] = 42; //whatever .. fill all these in for all digits etc
then..
OutputData(relate[somestring[letter++]]); //the nth letter of the string is shown.
Last edited on
The professor said he recommends parallel arrays, but I 100 percent agree with you that I have no idea how that correlates to my issue. Lets just assume moving forward that we will just use the best method as its just a recommendation.
maybe we missed each other just then, does the last line of my above do what you want?

the best method is probably advanced C++, like an unordered map of digits to segments.
lets just keep it simple unless you want to skip to commercial grade code?
Last edited on
Lets say a user inputs the word "world". How would I compile all of the individual characters to then output to the 7-segment display? For help, I have assembled all of the numbers that correlate to output, as I shared earlier, 88 outputs the number 7. Here is my list of the alphabet since we need to use letters now:

A = 8
b = 3
c = 39
d = 33
E = 6
F = 14
G = 66
H = 9
i = 79
j = 97
K = 10
L = 79
m = 42
n = 43
O = 64
p = 12
Q = 24
R = 4
S = 18
t = 7
U = 65
V = 81
W = 85
X = 54
y = 5
Z = 36

for example,

// A will be displayed for 2 seconds
OutputData(8); // 8 correlates to A being displayed
Sleep(2000);; // 2000 correlates to 2 seconds
Last edited on
so as above.
in a setup area, one time:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
int relate [128]{};
relate['A'] = 8  ;
relate['b'] = 3  ;
relate['c'] = 39 ;
relate['d'] = 33 ;
relate['E'] = 6  ;
relate['F'] = 14 ;
relate['G'] = 66 ;
relate['H'] = 9  ;
relate['i'] = 79 ;
relate['j'] = 97 ;
relate['K'] = 10 ;
relate['L'] = 79 ;
relate['m'] = 42 ;
relate['n'] = 43 ;
relate['O'] = 64 ;
relate['p'] = 12 ;
relate['Q'] = 24 ;
relate['R'] = 4  ;
relate['S'] = 18 ;
relate['t'] = 7  ;
relate['U'] = 65 ;
relate['V'] = 81 ;
relate['W'] = 85 ;
relate['X'] = 54 ;
relate['y'] = 5  ;
relate['Z'] = 36 ;
//and then
string w = "world"
for(auto a:w)
output(relate[a]);


now, if you have a letter that isnt supported, like '?' or whatever, it will give a 0 from the lookup table. you can code it to ignore/skip/handle that somehow as you see fit.

this sort of code is incredibly fast. I had to code a weird program to do statistics on string patterns for some data analysts .. stuff like abc123 would give like vccnnn (vowel, consonant, number X 3) using the same approach I am showing you here -- their tool to do that was running for days, mine did it in a few min (hundreds of millions of strings). So this is a practical, useful pieces of code to understand... Ive done many such string lookups /replacements/etc built off this idea.
Last edited on
"world" would be inputted by the user. Using something like this:

cout << "Please enter a word: "; // Asking the user to input a word
cin >> UserInputWord; // Getting user input from the keyboard

how would I assemble those "codes" into a word?
I don't understand what you want. Ignoring case for a moment (you said world but "WORLd" is what would really be needed).
the above code (if you used "WORLd") as the user input would
call your output function with
85, then 64, then 4, and so on. Is that not what you are wanting?

I mean its an example--- variable names and such need fixing...

cin >> UserInputWord; // Getting user input from the keyboard
for(auto a:UserInputWord)
{
OutputData(relate[a]); // 8 correlates to A being displayed
Sleep(2000); // 2000 correlates to 2 seconds
}


so the first iteration:
a = 'W'
relate['W'] = 85
call output(85)
sleep
then a becomes 'O'
...
Last edited on
I'm not explaining this correctly and its my fault.

I want to:
-Ask the user input a word (the user would type in all lowercase, as the users input doesnt directly correlate to the output)
-Program would then case by case output the compiled word using the outputData and the sleep timer

There aren't specific words inputted by the user, it could be any combination of letters that result in a word.
Last edited on
yea, the above DOES THAT. :)
except for converting the case from user junk to what is supported.

one easy fix for user inputting the wrong case is to double down in the initialization of the lookup table.
so
relate['w'] = relate['W'] = 85.
then if the user put in 'w' they get the result for 'W' without having to work too hard to get there.
this is a really simple way to do it assuming you only have 1 supported letter, regardless of its case, eg you don't actually have like an entry for 'z' and 'Z' (you didn't in what you said).
Last edited on
that fix to a user error is extremely helpful, thanks :)
are you good to go now?
I should be. Thank you so much for the help and sorry for the misunderstanding/bad explaining
you are welcome!
Pages: 12