How to change array value in an if-else code

Hi,

I am trying to make a pinpad for a school project that will change the order of the numbers; unlike an iPhone where it is "1,2,3,4..." it can be "9,3,6,1..." so people cannot see the order you type your PIN #. Im using a normal 4x4 keypad and I was wondering if I can make an array so when someone types in there password it will go from

char keys[ROW_NUM][COLUMN_NUM] = {
{'9','1','7'},
{'8','2','6'},
{'5','0','3'},
{'*','4','#'}
};

to

char keys[ROW_NUM][COLUMN_NUM] = {
{'2','6','8'},
{'5','1','4'},
{'9','2','3'},
{'*','7','#'}
};

as an example. I do not now how to this or if this is even possible. I am very new to Arduino so please bare with me, any tips or help will be greatly appreciated. Thank you!

Anything is possible.

Take a look at some of the tutorials for keypads for how to decode and just add in the array.

After you enter your numbers into [0] ... [n] then you output them in any order you wish. Ex:
[4] [0] [2] [3] [1] for a 5-digit number

https://create.arduino.cc/projecthub/projects/tags/keypad

Is there anyway you can help us with this? I am really lost and new to this :frowning:

Thank you! I understand how to do this but what I am really wondering is if I can change my value so on the keypad it might show 1 but it will register as 6. Does it make sense? I just want the keypad to be buttons that will change the value each time so if I press the number 6 on the keypad it will show up as 4 on the serial monitor, and next time it can show up as 8.

So, NP...
The keypad work is already done for you, so many examples. But you need to select the closest project to the hardware the school is providing.

Then the approach is very similar to that of an electronic lock.
https://www.google.com/search?q=arduino+keypad+electronic+lock

Except, you have to code for a known cipher ... that is, for simplicity. Random length ciphers are possible, but much harder to do.

Let's say the cipher is 456789 then that would (possibly mean) that you would type in 9 digits and the Arduino would output 6 digits ... the 456789 would be the array elements.

You type                Array
5                              [0]
5                              [1]
1                              [2]
8                              [3]
9                              [4]
2                              [5]
3                              [6]
7                              [7]
6                              [8]

The cipher is 456789, therefore the output (when you press maybe # or * would be:
a[4] == 9
a[5] == 2
a[6] == 3
a[7] == 7
a[8] == 6
a[9] == null because it does not exist. So your 456789 gets decoded as 92376.

Of course, you could come up with any silly scheme you wanted to decode the array.... maybe backward, etc.

We dont need it to be random, I should have clarified that, we can just have it with 2 possible like array changes so if I press 1,2,3,4 on the keypad the serial monitor will show 9,2,3,6. Next time it will show if I press 1,2,3,4 on the keypad, the serial monitor will show 5,1,4,7. The next time it will revert back to 9,2,3,6... so on and so forth

Then you are wanting a translation algorithm: one-to-one correspondence. Just pre-populate the array in the code:

int iArray[] = {9, 8, 7, 6, 5, 4, 3, 2, 1, 0};

You get a number (int) and output iArray[number]

Will this make it so once lets say once the password is entered, the array value will change and then once the passcode is entered once more it will change back and so on and so forth?

Of course not.
If you wish to enter a password via keyboard, you will need an input routine to initially set the iArray values ... element by element.
Once the input routine is in memory, you will need to write it to EEPROM
Then you could enter the messed-up numbers and have them processed by the array into the real passcode.

Draw it on paper. If you enter "1" for the first digit of the real passcode, it goes into iArray[0] and you enter "2" and it goes into iArray[1] ... you will have to decide ahead of time on the maximum length of the passcode and the scrambled inputs will be the same number to decode.

When you have the passcode stored in EERPOM, you must "know" that on power-up and check that in the setup(). You can google for how to make this determination.

I am super new to this and dont really understand the terms like EEPROM and iArray. Is there anyway you can show me a sample code or if you can make one that would be so helpful and you would be a life saver

No. You have specific assignment and are having difficulty explaining each piece. I cannot be a tutor or a ghostwriter as it is not fair... I have a large audience to assist and but a small time each night for the activity.

Look online for Arduino programmable electronic projects - one where the passcode is input and stored.

I do not mean it like that. I am very new to Arduino and do not understand what you are saying. I just want to know if I can change the values and if I can what would I use, is there a such thing as a change code? I am sorry that you think this, I was not trying to come of in that way.

What you are trying to articulate is you wish to write an algorithm which will decode a string of digits into another string of digits by an algorithm. A simple algorithm would be to add 1 to everything I input ... I type 1 and the display would say 2. I type 5 and the display would say 6.

In the above example, you could simply use an long series of if statements. More sophisticated would be to use math. More sophisticated would be arrays.

In one-to-one transposition, every digit typed in has a decoded digit shown on the display. You could count the digits and do them all at once or you could do them one by one.

Keyless lock code is 80% of your project. Do some analysis, that is about the most help I can provide.

@robsepton

Other topic on the same subject deleted.

Please do not duplicate your questions as doing so wastes the time and effort of the volunteers trying to help you as they are then answering the same thing in different places.

Repeated duplicate posting could result in a temporary or permanent ban from the forum.

Could you also take a few moments to [url=https://forum.arduino.cc/index.php?topic=710766.0]Learn How To Use The Forum[/url].

Other general help and troubleshooting advice can be found here.
It will help you get the best out of the forum in the future.

Thank you.

@robsepton
No sooner I delete one duplicate of your topic and you create 2 more and then flag my warning above to the moderators. In case you missed it I am a moderator.

I have stopped you posting anything for 2 days. If you continue to flout the forum rules your next ban will be for longer. Take the time I've given you to read the forum instructions linked to above.

Thank you.

Multiple accounts created, which then post the same topic, this one locked.