I need help to modify my code

Hi guys,

I have arduino project code and it works good. But i need to make some changings. I found an example of what i want.
In my code;
When i press the # button on keypad password change screen is opening and it works fine. But i want my code to verify new password 2 times. it should ask like;
New password, New password again, and then save it.

And if it is possible as in example i want to show saving % on lcd display it looks more proffesional.

My code and simu link; mychargestationproj - Wokwi ESP32, STM32, Arduino Simulator
Example code and simu link ((to go pass change screen you should hold pressing #)); Circuit design Password Based Circuit Breaker using Arduino | Tinkercad

Back at you!

Thanks for the wokwi. Do us all a favor, please.

Use the IDE Autoformat tool on your code. That will render it in a standard format most people will find easier to read.

If you still have it in the IDE, format it there ans copy paste it over the wokwi simulation code.

Or copy it from the wokwi into the IDE, format it there then paste back in the wokwi.

While you have it on your clipboard, come here and use the <CODE/> tool in the message composition window and do what it sez:

type or paste code here

So we can all read your code and it will live long on this forum.

Lastly, what's the initial password? I spent all the time I have just now reading your code and I may be blind from ocean glare fantastic day here but I just don't see it. I tried 0000.

edit: N'mind, I see it now.

TIA

a7

So in more clear language:
you found a code online that has the functionality that you want but you don't know how to modify it
and now
you want somebody else to do all the modifcations for you

well IMHO this is not how this forum is meant to be.
This forum is to support learning.

Make an own attempt to modify the code
or
at least ask a assuming questions where inside the code the modification must be done

best regards Stefan

i have rework little, i hope it is more clearly and easier to understand.
and if you understand then you modify it how you new wish is, like double check of new password or adding supervisor password to reset user password, or whatever.
i had pleasure to dig in this sketch. i thank you for this opportunity. i hope you have similar fun with it.

#include <Keypad.h>
#include <EEPROM.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>

LiquidCrystal_I2C lcd(0x27, 16, 2);

char password[4];
char initial_password[4], new_password[4];
int i = 0;
const int relay_pin = 11;
char key_pressed = 0;
const byte rows = 4;
const byte columns = 4;

char hexaKeys[rows][columns] = {
  {'1', '2', '3', 'A'},
  {'4', '5', '6', 'B'},
  {'7', '8', '9', 'C'},
  {'*', '0', '#', 'D'}
};
const byte row_pins[rows] = {7, 8, 9, 10};
const byte column_pins[columns] = {3, 4, 5, 6};
Keypad keypad_key = Keypad( makeKeymap(hexaKeys), row_pins, column_pins, rows, columns);
#define isPassOK (!strncmp(password, initial_password, 4))


void setup() {

  lcd.init();
  lcd.backlight();
  pinMode(relay_pin, OUTPUT);
  digitalWrite(relay_pin, HIGH);

  lcd.setCursor(5, 0);
  lcd.print("B & F");
  lcd.setCursor(2, 1);
  lcd.print("ELECTRONICS");
  delay(1000);
  lcd.clear();

  lcd.setCursor(4, 0);
  lcd.print("WELCOME");
  delay(1000);
  lcd.clear();

  lcd.setCursor(0, 0);
  lcd.print("ELECTRIC VEHICLE");
  lcd.setCursor(0, 1);
  lcd.print("CHARGING STATION");
  delay(1000);
  lcd.clear();

  lcd.setCursor(1, 0);
  lcd.print("PLEASE CONNECT");
  lcd.setCursor(1, 1);
  lcd.print("CHARGING CABLE");
  delay(1000);
  lcd.clear();

  lcd.setCursor(4, 0);
  lcd.print("TO YOUR");
  lcd.setCursor(0, 1);
  lcd.print("ELECTRIC VEHICLE");
  delay(1000);
  lcd.clear();

  lcd.setCursor(0, 0);
  lcd.print("AFTER CONNECTION");
  lcd.setCursor(0, 1);
  lcd.print("ENTER YOUR PIN");
  delay(1000);
  LCD_EntePass();
  initialpassword();
}


void loop() {
  key_pressed = keypad_key.getKey();
  if (key_pressed == '#')  change();
  if (key_pressed)
  {
    password[i++] = key_pressed;
    lcd.print('*');
    delay(200);
  }
  if (i == 4) {
    i = 0;

    if (isPassOK) { // ŞIFRE DOGRU DURUMLARI
      digitalWrite(relay_pin, LOW);  // Röle çalışır durumda
      LCD_PassOK();
    }
    else  {     // ŞIFRE YANLIŞ DURUMLARI
      digitalWrite(relay_pin, HIGH); // Röle çalışır halde kalsın
      LCD_WroPass();
    }
    LCD_EntePass();

  } // if=4 döngüsü kapanış

}  // voidloop kapanış

void LCD_PassOK() {
  lcd.clear();
  lcd.print("  PASSWORD IS");
  lcd.setCursor(4, 1);
  lcd.print("CORRECT");
  delay(3000);
}
void LCD_EntePass() {

  lcd.clear();
  lcd.print(" Enter Password");
  lcd.setCursor(6, 1);
}
void LCD_WroPass() {
  lcd.clear();
  lcd.setCursor(1, 0);
  lcd.print("Wrong Password");
  lcd.setCursor(3, 1);
  lcd.print("Try Again");
  delay(2000);
}

void change() {
  int j = 0;
  lcd.clear();
  lcd.print("Current Password");
  lcd.setCursor(6, 1);
  while (j < 4) {
    char key = keypad_key.getKey();
    if (key)
    {
      password[j++] = key;
      lcd.print(key);
    }
    key = 0;
  }
  delay(500);

  if (isPassOK == false) LCD_WroPass();
  else {
    j = 0;
    lcd.clear();
    lcd.setCursor(2, 0);
    lcd.print("New Password");
    lcd.setCursor(6, 1);

    while (j < 4) {
      char key = keypad_key.getKey();
      if (key)
      {
        initial_password[j] = key;
        lcd.print(key);
        EEPROM.write(j, key);
        j++;
      }
      key = 0;
    }
    lcd.clear();
    lcd.print("PIN is Changed");
    delay(2000);
  }

  LCD_EntePass();
  key_pressed = 0;
}

void initialpassword() {
  int j;
  if (EEPROM.read(0) == 0xFF)for (j = 0; j < 4; j++)EEPROM.write(j, j + 49);//if eeprom is empty then password is "1234"
  for (j = 0; j < 4; j++)initial_password[j] = EEPROM.read(j);
}


Did you abandon this a fortnight ago?

Hi,
Can I suggest you have an Emergency Stop button, rather than have to use a password if you need to switch off and isolate in a hurry.

I'm not familiar with the EV charging plugs, but are they locked in when charging, or can you pull them out during a charge.

If they aren't locked why the security to turn the charger off?
Anyone can come along and "pull the plug".

Tom.. :grinning: :+1: :coffee: :australia:

Dear Stefan, if u have time to have a look to my code, you will see it is already modified by me. I need one or two thing to complete all what i want thats why i asked for help.

This is simple project, of course it can improvable, i am not professional at software so that is what i can do clearly :slight_smile: For your suggestion, i can say that it is not that much easy to pull the plug the electricity source is coming from the junction box.

I did the neccesary modifications about this topic. I asked new things now.

thank you very much. At least there is a person who understood what i want :smiley: I am here to get help. Not to be criticized. I'll try your modifications on my code. Thanks again...

No. You did not. I understand.

i solved the problem of ''when i enter pass, stay opened, if i enter again the pass, close after i enter the password again and stay closed''.

Now i am asking when i press # to change password screen, i see old password one time, new password one time, i want to make double time check when i set new password. like;

old password ....
new password ...
write new password again ....

i hope i explained it.

You did explain it. But where is your attempt trying to code it yourself?
or at least

where is a specific question like:

"at the top of void loop the passwod gets entered.
If I copy & paste the lines that enter the password
would that realise that I have to enter the password twice?"

What you yourself has posted so far is not a single specific question similar to the example I wrote above.

Posting such a specific question would demonstrate that you yourself at least started thinking / analysing the code yourself

As long as you just repeat descriptions of the functionality this is almost the same as asking

"can somebody modify my code so it works like ..."

in turkey just in case your english is limited

[quote="batuhansa, gönderi:13, konu:1130307"]
eski Şifre ....
Yeni Şifre ...
yeni şifreyi tekrar yaz ....

umarım anlatabilmişimdir
[/alıntı]

Açıklamışsın. Ama **kendinizi** kodlamaya çalıştığınız **girişiminiz** nerede?
ya da en azından

gibi belirli bir soru nerede:

"void döngüsünün en üstünde parola girilir.
Şifreyi giren satırları kopyalayıp yapıştırırsam
Bu, parolayı iki kez girmem gerektiğini fark eder mi?"

Şu ana kadar**kendinizin** yayınladığı şey, yukarıda yazdığım örneğe benzer **tek bir **belirli** soru **değil**.

Böyle bir **spesifik** soru yayınlamak,**kendinizin** en azından **kodu kendi**kendiniz** üzerinde düşünmeye/analiz etmeye başladığınızı** gösterir.

İşlevselliğin açıklamalarını tekrarladığınız sürece, bu neredeyse soru sormakla aynıdır.

"biri kodumu şöyle çalışacak şekilde değiştirebilir mi ..."

best regards Stefan

Where is your actual code that shows that?

How should somebody else add a new functionality if you do not provide your actual code posted as a code-section here in this thread??!

If you re-read your whole thread can you see that the kind and way you are posting demonstrates more and more that you are unwilling to engage yourself ??

Stefan, do you have problem to understand what you read?

I am asking because you should have problem if u say still “ where is your actual code? “ .

Look top of the page. I gave a link to see my code and simulate it. What can i do more?

Do not worry, i totally understood, my english is good enough in turkey.

Anyway, You and people like you are not here to help each other, i can see.

I will not continue to lose my time here.

Good days.

Post it in a new post, some forum members are using platforms that may not let them go to simulation CADs.
PLEASE READ this link and post in a NEW post your code.
To add code please click this link;

Thanks.. Tom.. :grinning: :+1: :coffee: :australia:

even how you say it prove that is not "your" code. that`s why i not wanted to done your request, just simple rearrange in hope that i mistaken about you and you read the code and understand how it works.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.