how can shange an float value with keypad !!

hello friends

finally I build my first project with Arduino
just one thing to finish it

How can I change the float p1 AND float p2 value with keypad and save it after power rescores go off

   #include <LiquidCrystal.h>
   #include <Wire.h>
   LiquidCrystal lcd(7, 8, 9, 10, 11, 12);
//---------- Price 1 + Price 2 ---------------------------------------

   float p1= (0.30);  //Minimum price C1
   float p2=(0.20);  // MAX price C2
   
   float price1 = (p1 * 10); 
   float price2 = (p2 *10);
   
//---------- Relay AND IO Pulse IN -------------------------------

   const int relay = A0;         //Relay Out pin
   const int CopyPulse1 = A5;   // IO PRICE1 Pulse IN
   const int CopyPulse2 = A6;  // IO PRICE2 Pulse IN
   int buttonState = 0;
   int buttonState2 = 0;
   
//---------- COINS Validator Pulse IN---------------------------------

   int puls = 3;                  // Coins Pin Pulse
   volatile byte CoinPulseCount = 0;
   byte NewCoinInserted;
   byte Command = 0;
   volatile unsigned long PulseTime;
   float CurrentCredit = 0;
   float NewCurrentCredit = 0;

//---------- ++ Strings ---------------------------------------------

   String OnePulse = "00.10 AG";
   String TwoPulses = "00.50 AG";
   String ThreePulses = "01.00 SH";
   String FourPulses = "02.00 SH";
   String FivePulses = "05.00 SH";
   String SixPulses = "10.00 SH";

//---------- Credits ---------------------------------------------

void showCredit() {
//   NewCurrentCredit = (CurrentCredit/100) + NewCurrentCredit;
   NewCurrentCredit = (CurrentCredit) + NewCurrentCredit;
   Serial.print("Coins IN: ");
   Serial.println(CurrentCredit /10);
   Serial.print("NewCurrentCredit:");
   Serial.println(NewCurrentCredit /10);
   lcd.begin(16, 2);
   lcd.clear();
   lcd.setCursor(0, 0);
   lcd.print("Credit:");
   lcd.setCursor(8, 0);
   lcd.print(NewCurrentCredit /10);
   lcd.setCursor(0, 1);
   CopyTotal();
}

void Price1Credit() {
   NewCurrentCredit = (NewCurrentCredit - price1);
   Serial.print("Credit2 is:");
   Serial.println(NewCurrentCredit /10);
   lcd.begin(16, 2);
   lcd.clear();
   lcd.setCursor(0, 0);
   lcd.print("Credit:");
   lcd.setCursor(8, 0);
   lcd.print(NewCurrentCredit /10);
      CopyTotal();
   if (NewCurrentCredit == 0.00){
   setup();
   }
}

void Price2Credit() {
   NewCurrentCredit = (NewCurrentCredit - price2);
   Serial.print("Credit3 is:");
   Serial.println(NewCurrentCredit /10);
   lcd.begin(16, 2);
   lcd.clear();
   lcd.setCursor(0, 0);
   lcd.print("Credit:");
   lcd.setCursor(8, 0);
   lcd.print(NewCurrentCredit /10);
      CopyTotal();
   if (NewCurrentCredit == 0.00){
   setup();
   }
}

//---------- IO Total Screen --------------------------------------

void CopyTotal(){
  lcd.setCursor(0, 1);
  lcd.print("T:");
  lcd.setCursor(3, 1);
  lcd.print("C1=");
  lcd.setCursor(6, 1);
  lcd.print((int)(NewCurrentCredit /price1));
  lcd.setCursor(10, 1);
  lcd.print("C2=");
  lcd.setCursor(13, 1);
  lcd.print((int)(NewCurrentCredit /price2));
}

//---------- Setup  -------------------------------------------------

void setup() {    
Serial.begin(9600);
pinMode(CopyPulse1, INPUT); // PRICE1 Machine Pulse IN
pinMode(CopyPulse2, INPUT); // PRICE2 Copy Machine Pulse IN
pinMode(relay, OUTPUT); // Relay IO Release   
pinMode(puls, OUTPUT); // Coins Validator Pulse
digitalWrite(puls, HIGH);// Coins Validator Pulse ON/OFF
SetupS ();
attachInterrupt(1, CoinPulse, RISING);
}

//---------- Setup Screen -------------------------------------------

void SetupS (){
Serial.println("#Insert Coins#");
Serial.print("NewCurrentCredit:");
Serial.print(NewCurrentCredit / 10);
lcd.begin(16, 2);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("#Insert Coins:#");
lcd.setCursor(0, 1);
lcd.print("C1=");
lcd.setCursor(3, 1);
lcd.print(price1 / 10);
lcd.setCursor(7, 1);
lcd.print(" C2=");
lcd.setCursor(11, 1);
lcd.print(price2 / 10);
}

//---------- LOOP COINS Insert & Relay releas & Buttons --------------

void loop() { 
if (CoinPulseCount > 0 && millis() - PulseTime > 200) {
NewCoinInserted = CoinPulseCount;
CoinPulseCount = 0;
}
switch (NewCoinInserted) {
case 1:
      Serial.println(OnePulse + " inserted");
      CurrentCredit = 1.0; // 0.10 AG
      showCredit();
      NewCoinInserted = 0;
break;
case 2:
      Serial.println(TwoPulses + " inserted");
      CurrentCredit = 5.0; // 0.50 AG
      showCredit();
      NewCoinInserted = 0;
break;
case 3:
      Serial.println(ThreePulses + " inserted");
      CurrentCredit = 10.0; // 1 Shikle
      showCredit();
      NewCoinInserted = 0;
break;
case 4:
      Serial.println(FourPulses + " inserted");
      CurrentCredit = 20.0; // 2 Shikle
      showCredit();
      NewCoinInserted = 0;
break;
case 5:
      Serial.println(FivePulses + " inserted");
      CurrentCredit = 50.0; // 5 Shikle
      showCredit();
      NewCoinInserted = 0;
break;
case 6:
      Serial.println(SixPulses + " inserted");
      CurrentCredit = 100.0; // 10 Shikle
      showCredit();
      NewCoinInserted = 0;
break;
} 

//--------------------- Relay PIN -----------------------------

if (NewCurrentCredit < price1 and price2 <= price1){
  digitalWrite(relay, LOW);
}
else if (price2 >= price1 and NewCurrentCredit < price2 ){
 digitalWrite(relay, LOW);
}
else {
digitalWrite(relay, HIGH);
}

//if (NewCurrentCredit >= price2 and price1 <= price2){
//  digitalWrite(relay, HIGH);
//}
//else {
//digitalWrite(relay, LOW);
//}
//--------------------- Button C1 -----------------------------

buttonState = digitalRead(CopyPulse1);
/*if ((NewCurrentCredit < price1)or(NewCurrentCredit == 0)){
digitalWrite(CopyPulse1, LOW);  
}*/
if ((NewCurrentCredit >= price1)and(buttonState == HIGH)){
Price1Credit();
delay(500);
}
//--------------------- Button C2 -----------------------------
buttonState = digitalRead(CopyPulse2);
/*if ((NewCurrentCredit < price2)or(NewCurrentCredit == 0)){
digitalWrite(CopyPulse2, LOW);  
}*/
if ((NewCurrentCredit >= price2)and(buttonState == HIGH)){
Price2Credit();
delay(500);
}
}

//---------- CoinPulse ---------------------------------------------

void CoinPulse() {
  CoinPulseCount ++;
  PulseTime = millis();
}

thanx alot

Read the keypad, change p1 & p2 accordingly, save these to EEPROM.

On power up read EEPROM locations to restore p1 & p2.

Edit:
Only update EEPROM when changes are accepted from the keypad.
100,000 write cycles available only.
.

LarryD:
Read the keypad, change p1 & p2 accordingly, save these to EEPROM.

On power up read EEPROM locations to restore p1 & p2.

Edit:
Only update EEPROM when changes are accepted from the keypad.
100,000 write cycles available only.
.

thanks for that LarryD
could you write a simple code for that and can I use the internal Arduino eeprom for that ??

Yes you can use the EEPROM in the Arduino.

No time now.
There should be lots of keypad and EEPROM examples on the web.

Search 'Arduino keypad' and 'Arduino EEPROM'.

.