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.
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.
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.
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.
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?
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
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.
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'
...
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.
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).