editable pin numbers

Hi Guys, i am pretty new to arduino and am working on a project at the moment wich requires a pin code to start the process, i also have a menu function to change various settings in the process, however within this menu i want to be able to change the pin number. At the moment i set the pins at the begining with

char PinCode[] = "123456"; // main operating pin code
char AdminCode[] = "654321"; //code to access settings menu

i wonder if you could help me with the code to edit these numbers.

much appreciated.

The title of the thread is a bit misleading. If I understand correctly, the "pin" means a passcode, not arduino analog or digital I/O pins, right?

If you want to change this pin, how are you relaying the new code to arduino? Serial.read? A keypad or a few buttons? A twist knob with something to turn?

My apologies, yes i do mean passcode, i will be inputting the code via keypad, i've already created an editable clock wher i can edit hours,mins,secs in the project, but cant seem to get the idea of inputting strings of numbers like my 6 digit passcode.

I doubt it’s much different to what you are already doing for the clock.

Assuming you have a function to get a numeric value from a key press and you want to store the values as ASCII characters then

memset (PinCode, 6, 0);  // clear the array
for (int i = 0; i < 6; i++)
  PinCode[i] = getKey() + '0';

Is about what you would do. Of course you need to handle the method getting to the password entry code, exiting if someone wants to start again etc.


Rob

I suspect if you use the keypad library on arduino playground, it already translates the keys into ASCII characters from '0' to '9', and then '*' and '#'. Can you show us how you did it in your clock project?

Yes i used the keypad tutorial.

#include <Keypad.h>
#include <LiquidCrystal.h>
#include <LedControl.h>
#include <MsTimer2.h>

LedControl lc=LedControl(4,3,2,1);

const byte ROWS = 4; //four rows
const byte COLS = 4; //four columns
char keys[ROWS][COLS] = {
{'1','2','3','A'},
{'4','5','6','B'},
{'7','8','9','C'},
{'*','0','#','D'}
};
byte rowPins[ROWS] = {7, 8, 9, 10}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {13, 12, 11, 6}; //connect to the column pinouts of the keypad

my A,B,C,D keys are used for menu, yes, no and cancel. the clock edit is done like this:

void clockSet(){
lcd.clear();
char timeInt;
lcd.setCursor(0, 0);
lcd.print("Enter Admin Pin");
if (getAdminPin() == true){
lcd.clear();
lcd.print("Enter Hours");
do{
timeInt = keypad.getKey();
}
while(timeInt == '\0' || timeInt < '0' || timeInt > '6');

hour = (timeInt - '0') * 10;
do{
timeInt = keypad.getKey();
}
while(timeInt == '\0');
hour = (timeInt - '0') + hour;
lcd.clear();
timeInt = 'L';

lcd.print("Enter Minutes");
do{
timeInt = keypad.getKey();
}
while(timeInt == '\0' || timeInt < '0' || timeInt > '6');
while (timeInt < '0' || timeInt > '6'){
timeInt = keypad.getKey();
}
minute = (timeInt - '0') * 10;/
do{
timeInt = keypad.getKey();
}
while(timeInt == '\0');
minute = (timeInt - '0') + minute;
lcd.clear();
timeInt = 'L';

lcd.print("Enter Seconds");
do{
timeInt = keypad.getKey();
}
while(timeInt == '\0' || timeInt < '0' || timeInt > '6');
while (timeInt < '0' || timeInt > '6'){
timeInt = keypad.getKey();
}
second = (timeInt - '0') * 10;
do{
timeInt = keypad.getKey();
}
while(timeInt == '\0');
second = (timeInt - '0') + second;
delay(500);

timeInt = 'L';

repeatTimerEdit = 1;
}//end of getAdminPin == true

if(getAdminPin == false){
lcd.print("Incorrect");
}
lcd.clear();
lcd.print("Enter Pin");
}//end of timer edit function

Please modify your post with the code button "#". See the button in red square.

Yes please modify the post and put the code inside code tags.

Meanwhile

if (getAdminPin() == true){
  // a lot of stuff
  }//end of getAdminPin == true
  
  if(getAdminPin == false){
   lcd.print("Incorrect");
  }

should be

if (getAdminPin() == true){
  // a lot of stuff
  } else {
   lcd.print("Incorrect");
  }

I'm not even sure the first version would have compiled.

But aren't we supposed to be looking at the PIN entry, where's the source for getAdminPin() ?


Rob