I need to design two switch cases that will operate independently one for a key pad that detects what key is pressed and one for a segment display that will display the key.
they will both have a shared array to read and write to I've not done this in a while so I am kinda stuck on how to write it. So the array will have 12 values for the key pad can I say just create an array of say 1-12 by doing something along the lines of
int array[12] = {0,1,2,3,4,5,6,7,8,9,10,11}
switch(keypad)
case 0:
array[0]; //Does this set it as the current one that the other switch case can read from
break;
case n:
array[n];
break;
switch(segment)
case 0:
if(array[0]){display on segment}
else segment = 1;
break;
case 1:
if(array[1]){display on segment}
else segment = n;
break;
case n:
if(array[n]){display on segment}
else segment = n;
break;
I honestly can't remember the method of saving and sharing with arrays.
the only other thing I can think of is if everything is set to false and as they are pressed it sets to true then it can go something along the lines of.
int array[12] = {false,false,false,false,false,false,false,false,false,false,false,false,}
switch(keypad)
case 0:
array[0] = true;
break;
case n:
array[0] = true;
break;
switch(segment)
case 0:
if(array[0] == true){display on segment}
else segment = 1;
break;
case 1:
if(array[1] == true){display on segment}
else segment = n;
break;
case n:
if(array[n]== true){display on segment}
else segment = n;
break;
Obviously there will be some logic in there to set the value back to false when released but aside from that do either of them look the right way to go or is there another way. Am I using the arrays correctly?