While loop & Reset

Thank you very much. I think what you suggested is almost working the only problem is I want to turn on and off IOXpin exactly the amount of time I had on my while loop. Because I am trying to control a pump. This pump has a pin when you apply 5v to it, it stops and when you apply 0V it turns on. Basically, you stop it with turning the IOXpin high.
Here is the changes I did to my code. And thanks again for the help.

#include <Keypad.h>
#include <Password.h>
int blinkLED =0; //Global variable to see if we need to turn the


const unsigned long interval = 250; // Global Scope     
//pin IOX high or not
unsigned long lastEdgeTime = 0; // time since last switch
int blinkingLEDState = LOW; // Start with low 


int IOXpin =2;
Password Disp1 = Password( "20" );
Password Disp2 = Password( "200" );

const byte ROWS = 4; //four rows
const byte COLS = 3; //three columns
char keys[ROWS][COLS] = {
  {
    '1','2','3'                          }
  ,
  {
    '4','5','6'                          }
  ,
  {
    '7','8','9'                          }
  ,
  {
    '*','0','#'                          }
};

byte rowPins[ROWS] = {
  5, 4, 3, 12}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {
  8, 7, 6}; //connect to the column pinouts of the keypad

Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
void setup(){
  pinMode(IOXpin, OUTPUT);
  Serial.begin(9600);
  keypad.addEventListener(keypadEvent); //add an event listener for this keypad
}

void loop(){
  //digitalWrite(IOXpin, HIGH);
  keypad.getKey();
}

//take care of some special events
void keypadEvent(KeypadEvent eKey){
  switch (keypad.getState()){
  case PRESSED:
    Serial.print("Pressed: ");
    Serial.println(eKey);
    switch (eKey){
    case '*': 
      checkDisp1(); 
      break;
    case '#':
      checkDisp2(); 
    case '1': 
      Disp1.reset();
      Disp2.reset();
      break;
    default: 
      Disp1.append(eKey);
      Disp2.append(eKey);
      Serial.flush();
    }
  }
}

void checkDisp1(){
  if (Disp1.evaluate()){
    Serial.println("Dispensing 20 uL");

    //    while(1)
    //    {
    //      digitalWrite(IOXpin, LOW);
    //      delay(100);
    //      digitalWrite(IOXpin, HIGH);
    //      delay(5000);
    //    }


    if((blinkLED==1)&&(millis() -  lastEdgeTime  > interval) ) { // check if it's been at least interval time since last switch and we should be blinking it
      lastEdgeTime  = millis(); // reset our interval timer
      blinkingLEDState = blinkingLEDState==HIGH?LOW:HIGH; // switch from HIGH to LOW or LOW to HIGH
      digitalWrite(IOXpin, blinkingLEDState); // write to the pin
    }


  }

  else{
    Serial.println("Not Available, Reset!!");

    digitalWrite(IOXpin, HIGH);
  }
}
void checkDisp2(){
  if (Disp2.evaluate()){
    Serial.println("Dispensing 200 uL");

    //    while(1)
    //    {
    //      digitalWrite(IOXpin, LOW);
    //      delay(1000);
    //      digitalWrite(IOXpin, HIGH);
    //      delay(5000);
    //    }


    if((blinkLED==1)&&(millis() -  lastEdgeTime  > interval) ) { // check if it's been at least interval time since last switch and we should be blinking it
      lastEdgeTime  = millis(); // reset our interval timer
      blinkingLEDState = blinkingLEDState==HIGH;//?LOW:HIGH; // switch from HIGH to LOW or LOW to HIGH
      digitalWrite(IOXpin, blinkingLEDState); // write to the pin
    }




  }
  else{
    Serial.println("Not Available, Reset!!");

    digitalWrite(IOXpin, HIGH);
  }
}

Could you, please, provide some feedback on what I am doing wrong.
Thanks

No answer?

Could you, please, provide some feedback on what I am doing wrong.

Could you please describe what that code is doing, and how what it does differs from what you want. With your vague handwaving, it's really hard to tell you how to fix the code.

Hi, thank you very much,
Forget about the modification I did in the last post. Here is the one I have now:

#include <Keypad.h>
#include <Password.h>
int IOXpin =2;
Password Disp1 = Password( "20" );
Password Disp2 = Password( "200" );

const byte ROWS = 4; //four rows
const byte COLS = 3; //three columns
char keys[ROWS][COLS] = {
  {
    '1','2','3'                      }
  ,
  {
    '4','5','6'                      }
  ,
  {
    '7','8','9'                      }
  ,
  {
    '*','0','#'                      }
};

byte rowPins[ROWS] = {
  5, 4, 3, 12}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {
  8, 7, 6}; //connect to the column pinouts of the keypad

Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
void setup(){
  pinMode(IOXpin, OUTPUT);
  Serial.begin(9600); // change this to 115200
  keypad.addEventListener(keypadEvent); //add an event listener for this keypad
}

void loop(){
  digitalWrite(IOXpin, HIGH);
  keypad.getKey();
}

//take care of some special events
void keypadEvent(KeypadEvent eKey){
  switch (keypad.getState()){
  case PRESSED:
    Serial.print("Pressed: ");
    Serial.println(eKey);
    switch (eKey){
    case '*': 
      checkDisp1(); 
      break;
    case '#':
      checkDisp2(); 
    case '1': 
      Disp1.reset();
      Disp2.reset();
      break;
    default: 
      Disp1.append(eKey);
      Disp2.append(eKey);
    }
  }
}

void checkDisp1(){
  if (Disp1.evaluate()){
    Serial.println("Dispensing 20 uL");
    //Add code to run if it works
    while(Disp2.evaluate() != '200')
    {
      digitalWrite(IOXpin, LOW);
      delay(100);
      digitalWrite(IOXpin, HIGH);
      delay(5000);
    }
  }
  else{
    Serial.println("Not Available, Reset!");
    //add code to run if it did not work
    digitalWrite(IOXpin, HIGH);
  }
}
void checkDisp2(){
  if (Disp2.evaluate()){
    Serial.println("Dispensing 200 uL");
    //Add code to run if it works
    while(1)
    {
      digitalWrite(IOXpin, LOW);
      delay(1000);
      digitalWrite(IOXpin, HIGH);
      delay(5000);
    }
  }
  else{
    Serial.println("Not Available, Reset!");
    //add code to run if it did not work
    digitalWrite(IOXpin, HIGH);
  }
}

The code work like how the password code works:

/*
||  Simple Password Entry Using Matrix Keypad
||  4/5/2012 Updates Nathan Sobieck: Nathan@Sobisource.com
||
*/


//* is to validate password   
//# is to reset password attempt

/////////////////////////////////////////////////////////////////

#include <Password.h> //http://www.arduino.cc/playground/uploads/Code/Password.zip
#include <Keypad.h> //http://www.arduino.cc/playground/uploads/Code/Keypad.zip

Password password = Password( "1234" );

const byte ROWS = 4; // Four rows
const byte COLS = 4; //  columns
// Define the Keymap
char keys[ROWS][COLS] = {
  {'1','2','3','A'},
  {'4','5','6','B'},
  {'7','8','9','C'},
  {'*','0','#','D'}
};

byte rowPins[ROWS] = { 9,8,7,6 };// Connect keypad ROW0, ROW1, ROW2 and ROW3 to these Arduino pins.
byte colPins[COLS] = { 5,4,3,2, };// Connect keypad COL0, COL1 and COL2 to these Arduino pins.


// Create the Keypad
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );

void setup(){

  Serial.begin(9600);
  keypad.addEventListener(keypadEvent); //add an event listener for this keypad
}

void loop(){
  keypad.getKey();
}

//take care of some special events
void keypadEvent(KeypadEvent eKey){
  switch (keypad.getState()){
    case PRESSED:
	Serial.print("Pressed: ");
	Serial.println(eKey);
	switch (eKey){
	  case '*': checkPassword(); break;
	  case '#': password.reset(); break;
	  default: password.append(eKey);
     }
  }
}

void checkPassword(){
  if (password.evaluate()){
    Serial.println("Success");
    //Add code to run if it works
  }else{
    Serial.println("Wrong");
    //add code to run if it did not work
  }
}

So in my case when the user hits the right combination, I want to display the message "Dispensing whatever 20uL or 200uL" and it will start the loop (Turn a pin high for some time and low for some time in a loop) in my case I am using pin 2.
I hope I clarified what I am looking for.

 while(1)
    {
      digitalWrite(IOXpin, LOW);
      delay(1000);
      digitalWrite(IOXpin, HIGH);
      delay(5000);
    }

Describe in your own words what you think this will do.

That loop need some work. I know because I put that "1" inside the while (i.e while(1)) that's why when the user inputs the right combination it just stays in loop because it's always true.
But What I want is if the user touched any key from the keypad it will exit the loop, that's simply what I am trying to do.
I tried putting inside the () of the while loop something like "key" or ekey thinking that variable stores the current reading but it didn't work.
Let me know if you have any help to provide us with.
Thanks

So when they enter the right password you want it to dispense stuff for ever? I hope you have a lot of this stuff.

At first the OIX pin will be set high. You can see that in the beginning of my void loop setup. Because that pin stops my micro pump when it's high. So I want it high when you first power the system. Then when the user put the right combination it will go to my two loops, depending on the selection. If the user selected 20 then it will execute the first loop.
If the user didn't enter the right combination the pin IOX will stay high to keep the pump in the stop mode.
Now if the user entered the right combination, I will print a message (dispensing 20 ul) and the pin start turning high and low (see my time) until the user touches the keys again in which case the IOX pin will turn high to stop the pump again and wait for the next entry, if it's 200 then that's good it'll go to the second loop, if it's 20 it'll go back to the first loop if it's not one of these two the program should exit the loop and turn the pin IOX high again to stop the pump.
My problem is just how do you get out of the loop and reset the system, I need a condition (maybe getkey() function to tell me that the user touched the keys or something).
Please some sample code, just suggesting things doesn't help me
I hope this makes it clear
Thank you very much for your time.
Thank you.

... I will print a message (dispensing 20 ul) and the pin start turning high and low (see my time) until the user touches the keys again ...

I'm sorry but I'm not just going to sit here and write your code. You have explained what you want, but your code doesn't reflect that.

while(1)
    {
      digitalWrite(IOXpin, LOW);
      delay(1000);
      digitalWrite(IOXpin, HIGH);
      delay(5000);
    }

That says, turn the pump on, wait 1 second, turn it off, wait 5 seconds, and then keep doing that until you power off the Arduino.

If you just want to run for one second, get rid of the loop, eg.

   digitalWrite(IOXpin, LOW);
   delay(1000);
   digitalWrite(IOXpin, HIGH);
   delay(5000);

If you want to run until they press a key, well test for that:

while(1)
    {
      keypad.getKey ();
      if (keypad.getState() == PRESSED)
          break;  // leave the loop
      digitalWrite(IOXpin, LOW);
      delay(1000);
      digitalWrite(IOXpin, HIGH);
      delay(5000);
    }

You don't need to reset the system. Try to design so you don't have those loops that you never leave.

I should point out though that this code will only check the key every 6 seconds. You may want to eliminate the delay altogether and just check for elapsed time.

yop !

unsigned long time1=0,time2=0;
int xx=1;

while (1) 
{ 
      

      keypad.getKey (); 
      if (keypad.getState () == presse) 
          break; // quitter la boucle 

      switch (xx) 
      {
        
      case 1 :
      
            digitalWrite (IOXpin, LOW); 
            time2=millis();
            if (time2>time1+1000)//1000 = 1sec
            {
                xx=2; 
                time1=millis();
            }
            break;
            
      case 2 :      

            digitalWrite (IOXpin, HIGH);
            time2=millis();
            if (time2>time1+5000)//1000 = 1sec
            {
                xx=1; 
                time1=millis();
            }
            break;
    }
}

it's good for your problem?? =)

Skizo !

Thank you very much for your help.
I am working now on my void loop() function. In my code (see bellow) I have to press "#" to dispense the 200 and "*" to dispense the 20.
How can I use just one * or # to do the same thing because I am trying to increase the number of combination to 10 and it's gonna be a mess to have a case for each one.
So here is my code so far:

#include <Keypad.h>
#include <Password.h>
int IOXpin =2;
Password Disp1 = Password( "20" );
Password Disp2 = Password( "200" );

const byte ROWS = 4; //four rows
const byte COLS = 3; //three columns
char keys[ROWS][COLS] = {
  {
    '1','2','3'                              }
  ,
  {
    '4','5','6'                              }
  ,
  {
    '7','8','9'                              }
  ,
  {
    '*','0','#'                              }
};

byte rowPins[ROWS] = {
  5, 4, 3, 12}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {
  8, 7, 6}; //connect to the column pinouts of the keypad

Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
void setup(){
  pinMode(IOXpin, OUTPUT);
  Serial.begin(9600);
  keypad.addEventListener(keypadEvent); //add an event listener for this keypad
}

void loop(){
  digitalWrite(IOXpin, HIGH);
  keypad.getKey();
}

//take care of some special events
void keypadEvent(KeypadEvent eKey){
  switch (keypad.getState()){
  case PRESSED:
    Serial.print("Pressed: ");
    Serial.println(eKey);
    switch (eKey){
    case '*': 
      checkDisp1(); 
      break;
      case '#':
      checkDisp2(); 
      break;
    case '1': 
      Disp1.reset();
      Disp2.reset();
      break;
    default: 
      Disp1.append(eKey);
      Disp2.append(eKey);


    }
  }
}

void checkDisp1(){
  if (Disp1.evaluate()){
    Serial.println("Dispensing 20 uL");
    //Add code to run if it works
    while(1)
    {
      keypad.getKey ();
      if (keypad.getState() == PRESSED)
        break;  // leave the loop
      digitalWrite(IOXpin, LOW);
      delay(1000);
      digitalWrite(IOXpin, HIGH);
      delay(5000);
    }
  }
  else{
    Serial.println("Not Available, Reset!");
    //add code to run if it did not work
    digitalWrite(IOXpin, HIGH);
  }
}
void checkDisp2(){
  if (Disp2.evaluate()){
    Serial.println("Dispensing 200 uL");
    //Add code to run if it works
    while(1)
    {
      keypad.getKey ();
      if (keypad.getState() == PRESSED)
        break;  // leave the loop
      digitalWrite(IOXpin, LOW);
      delay(1000);
      digitalWrite(IOXpin, HIGH);
      delay(5000);
    }
  }
  else{
    Serial.println("Not Available, Reset!");
    //add code to run if it did not work
    digitalWrite(IOXpin, HIGH);
  }
}

and here is the print screen of what I get when I run it:

Pressed: 2
Pressed: 0
Pressed: *
Dispensing 20 uL
Pressed: 2
Pressed: 0
Pressed: #
Not Available, Reset!
Pressed: 2
Pressed: 0
Pressed: 0
Pressed: #
Not Available, Reset!
Pressed: 2
Pressed: 0
Pressed: 0
Pressed: #
Not Available, Reset!
Pressed: 1
Pressed: 2
Pressed: 0
Pressed: 0
Pressed: #
Dispensing 200 uL
Pressed: 2
Pressed: 0
Pressed: *
Not Available, Reset!
Pressed: 2
Pressed: 0
Pressed: 0
Pressed: #
Not Available, Reset!

now here is what I am trying to actually do:

#include <Keypad.h>
#include <Password.h>
int IOXpin =2;
Password Disp1 = Password( "20" );
Password Disp2 = Password( "40" );
Password Disp3 = Password( "60" );
Password Disp4 = Password( "80" );
Password Disp5 = Password( "100" );
Password Disp6 = Password( "120" );
Password Disp7 = Password( "140" );
Password Disp8 = Password( "160" );
Password Disp9 = Password( "180" );
Password Disp10 = Password( "200" );

const byte ROWS = 4; //four rows
const byte COLS = 3; //three columns
char keys[ROWS][COLS] = {
  {
    '1','2','3'                            }
  ,
  {
    '4','5','6'                            }
  ,
  {
    '7','8','9'                            }
  ,
  {
    '*','0','#'                            }
};

byte rowPins[ROWS] = {
  5, 4, 3, 12}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {
  8, 7, 6}; //connect to the column pinouts of the keypad

Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
void setup(){
  pinMode(IOXpin, OUTPUT);
  Serial.begin(9600);
  keypad.addEventListener(keypadEvent); //add an event listener for this keypad
}

void loop(){
  digitalWrite(IOXpin, HIGH);
  keypad.getKey();
}

//take care of some special events
void keypadEvent(KeypadEvent eKey){
  switch (keypad.getState()){
  case PRESSED:
    Serial.print("Pressed: ");
    Serial.println(eKey);
    switch (eKey){
    case '*': 
      checkDisp1(); 
      checkDisp2(); 
      checkDisp3(); 
      checkDisp4();
      checkDisp5(); 
      checkDisp6();
      checkDisp7();
      checkDisp8();
      checkDisp9(); 
      checkDisp10();
      break;
    case '1': 
      Disp1.reset();
      Disp2.reset();
      Disp3.reset();
      Disp4.reset();
      Disp5.reset();
      Disp6.reset();
      Disp7.reset();
      Disp8.reset();
      Disp9.reset();
      Disp10.reset();
      break;
    default: 
      Disp1.append(eKey);
      Disp2.append(eKey);
      Disp3.append(eKey);
      Disp4.append(eKey);
      Disp5.append(eKey);
      Disp6.append(eKey);
      Disp7.append(eKey);
      Disp8.append(eKey);
      Disp9.append(eKey);
      Disp10.append(eKey);
      
    }
  }
}

void checkDisp1(){
  if (Disp1.evaluate()){
    Serial.println("Dispensing 20 uL");
    //Add code to run if it works
    while(1)
    {
      keypad.getKey ();
      if (keypad.getState() == PRESSED)
        break;  // leave the loop
      digitalWrite(IOXpin, LOW);
      delay(1000);
      digitalWrite(IOXpin, HIGH);
      delay(5000);
    }
  }
  else{
    Serial.println("Not Available, Reset!");
    //add code to run if it did not work
    digitalWrite(IOXpin, HIGH);
  }
}
void checkDisp2(){
  if (Disp2.evaluate()){
    Serial.println("Dispensing 40 uL");
    //Add code to run if it works
    while(1)
    {
      keypad.getKey ();
      if (keypad.getState() == PRESSED)
        break;  // leave the loop
      digitalWrite(IOXpin, LOW);
      delay(1000);
      digitalWrite(IOXpin, HIGH);
      delay(5000);
    }
  }
  else{
    Serial.println("Not Available, Reset!");
    //add code to run if it did not work
    digitalWrite(IOXpin, HIGH);
  }
}
void checkDisp3(){
  if (Disp2.evaluate()){
    Serial.println("Dispensing 60 uL");
    //Add code to run if it works
    while(1)
    {
      keypad.getKey ();
      if (keypad.getState() == PRESSED)
        break;  // leave the loop
      digitalWrite(IOXpin, LOW);
      delay(1000);
      digitalWrite(IOXpin, HIGH);
      delay(5000);
    }
  }
  else{
    Serial.println("Not Available, Reset!");
    //add code to run if it did not work
    digitalWrite(IOXpin, HIGH);
  } 
}
void checkDisp4(){
  if (Disp2.evaluate()){
    Serial.println("Dispensing 80 uL");
    //Add code to run if it works
    while(1)
    {
      keypad.getKey ();
      if (keypad.getState() == PRESSED)
        break;  // leave the loop
      digitalWrite(IOXpin, LOW);
      delay(1000);
      digitalWrite(IOXpin, HIGH);
      delay(5000);
    }
  }
  else{
    Serial.println("Not Available, Reset!");
    //add code to run if it did not work
    digitalWrite(IOXpin, HIGH);
  }
}
void checkDisp5(){
  if (Disp2.evaluate()){
    Serial.println("Dispensing 100 uL");
    //Add code to run if it works
    while(1)
    {
      keypad.getKey ();
      if (keypad.getState() == PRESSED)
        break;  // leave the loop
      digitalWrite(IOXpin, LOW);
      delay(1000);
      digitalWrite(IOXpin, HIGH);
      delay(5000);
    }
  }
  else{
    Serial.println("Not Available, Reset!");
    //add code to run if it did not work
    digitalWrite(IOXpin, HIGH);
  } 
}
void checkDisp6(){
  if (Disp2.evaluate()){
    Serial.println("Dispensing 120 uL");
    //Add code to run if it works
    while(1)
    {
      keypad.getKey ();
      if (keypad.getState() == PRESSED)
        break;  // leave the loop
      digitalWrite(IOXpin, LOW);
      delay(1000);
      digitalWrite(IOXpin, HIGH);
      delay(5000);
    }
  }
  else{
    Serial.println("Not Available, Reset!");
    //add code to run if it did not work
    digitalWrite(IOXpin, HIGH);
  }
}
void checkDisp7(){
  if (Disp2.evaluate()){
    Serial.println("Dispensing 140 uL");
    //Add code to run if it works
    while(1)
    {
      keypad.getKey ();
      if (keypad.getState() == PRESSED)
        break;  // leave the loop
      digitalWrite(IOXpin, LOW);
      delay(1000);
      digitalWrite(IOXpin, HIGH);
      delay(5000);
    }
  }
  else{
    Serial.println("Not Available, Reset!");
    //add code to run if it did not work
    digitalWrite(IOXpin, HIGH);
  } 
}
void checkDisp8(){
  if (Disp2.evaluate()){
    Serial.println("Dispensing 160 uL");
    //Add code to run if it works
    while(1)
    {
      keypad.getKey ();
      if (keypad.getState() == PRESSED)
        break;  // leave the loop
      digitalWrite(IOXpin, LOW);
      delay(1000);
      digitalWrite(IOXpin, HIGH);
      delay(5000);
    }
  }
  else{
    Serial.println("Not Available, Reset!");
    //add code to run if it did not work
    digitalWrite(IOXpin, HIGH);
  }
}
void checkDisp9(){
  if (Disp2.evaluate()){
    Serial.println("Dispensing 180 uL");
    //Add code to run if it works
    while(1)
    {
      keypad.getKey ();
      if (keypad.getState() == PRESSED)
        break;  // leave the loop
      digitalWrite(IOXpin, LOW);
      delay(1000);
      digitalWrite(IOXpin, HIGH);
      delay(5000);
    }
  }
  else{
    Serial.println("Not Available, Reset!");
    //add code to run if it did not work
    digitalWrite(IOXpin, HIGH);
  } 
}
void checkDisp10(){
  if (Disp2.evaluate()){
    Serial.println("Dispensing 200 uL");
    //Add code to run if it works
    while(1)
    {
      keypad.getKey ();
      if (keypad.getState() == PRESSED)
        break;  // leave the loop
      digitalWrite(IOXpin, LOW);
      delay(1000);
      digitalWrite(IOXpin, HIGH);
      delay(5000);
    }
  }
  else{
    Serial.println("Not Available, Reset!");
    //add code to run if it did not work
    digitalWrite(IOXpin, HIGH);
  }   
}

And here is the problems when I use one case for a bunch of functions.

Pressed: 2
Pressed: 0
Pressed: *
Dispensing 20 uL
Not Available, Reset!
Not Available, Reset!
Not Available, Reset!
Not Available, Reset!
Not Available, Reset!
Not Available, Reset!
Not Available, Reset!
Not Available, Reset!
Not Available, Reset!
Pressed: 2
Pressed: 0
Pressed: 0
Pressed: *
Not Available, Reset!
Not Available, Reset!
Not Available, Reset!
Not Available, Reset!
Not Available, Reset!
Not Available, Reset!
Not Available, Reset!
Not Available, Reset!
Not Available, Reset!
Not Available, Reset!
Pressed: 1
Pressed: 2
Pressed: 0
Pressed: 0
Pressed: *
Not Available, Reset!
Not Available, Reset!
Not Available, Reset!
Not Available, Reset!
Not Available, Reset!
Not Available, Reset!
Not Available, Reset!
Not Available, Reset!
Not Available, Reset!
Not Available, Reset!
Pressed: 1
Pressed: 1
Pressed: 2
Pressed: 0
Pressed: 0
Pressed: *
Not Available, Reset!
Not Available, Reset!
Not Available, Reset!
Not Available, Reset!
Not Available, Reset!
Not Available, Reset!
Not Available, Reset!
Not Available, Reset!
Not Available, Reset!
Not Available, Reset!
Pressed: 4
Pressed: 0
Pressed: *
Not Available, Reset!
Not Available, Reset!
Not Available, Reset!
Not Available, Reset!
Not Available, Reset!
Not Available, Reset!
Not Available, Reset!
Not Available, Reset!
Not Available, Reset!
Not Available, Reset!
Pressed: 1
Pressed: 4
Pressed: 0
Pressed: *
Not Available, Reset!
Dispensing 40 uL
Dispensing 60 uL
Dispensing 80 uL
Dispensing 100 uL
Dispensing 120 uL
Dispensing 140 uL

I am getting a lot of prints that I don't need. Another thing is when I pressed 4 and 0 and * to validate I got what I have in the print screen and the key don't print anything after this. Also the Disp2() function in my code does not work.
I know I asked a lot of questions but hopefully this will be my last question. I am working on a project and it's due soon. Thanks

This isn't really a password is it? I'd throw the password library out.

Yes you are right but that's how much brain I got. Do you have another way of using a keypad to actually get something useful and use it to do what I talked about. If not I hope that You can just help fix what I have right now and after the project I will work on it myself to improve it.

I was looking what's available online. How to use a keypad and I mostly found how to use for a password, so I used it to do two things but now they want in between in increment of 20 so I have to do 10 setting.
And I just can go back and look for other solutions. especially I am new to this things.
Thanks anyway for your feedbacks

Here's what I am talking about:

#include <Keypad.h>

const byte IOXpin = 2;

const byte ROWS = 4; //four rows
const byte COLS = 3; //three columns
char keys[ROWS][COLS] = 
  {
    { '1','2','3' },
    { '4','5','6' },
    { '7','8','9' },
    { '*','0','#' }
  };

byte rowPins [ROWS] = { 5, 4, 3, 12}; //connect to the row pinouts of the keypad
byte colPins [COLS] = { 8, 7, 6 }; //connect to the column pinouts of the keypad

// Create the Keypad
Keypad kpd = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );

void setup()
{
  pinMode(IOXpin, OUTPUT);
  Serial.begin (9600);
}  // end of setup

void processNumber (const unsigned long amount)
  {
  Serial.print ("Dispensing ");
  Serial.print (amount);
  Serial.println (" ml.");

  // Sanity Claus
  
  if (amount < 5 || amount > 500)
    {
    Serial.println ("Invalid amount ... aborting.");
    return;    
    }
   
  unsigned long startTime = millis ();
  unsigned long runTime = amount * 100;   // assume 0.1 secs per ml
  
  digitalWrite (IOXpin, LOW);
  while (millis () - startTime < runTime)
    {
    if (kpd.getKey() == '*')  // cancel button
       {
       Serial.println ("Cancelled.");
       break;  
       }  // end of if cancelled
    }  // end of waiting for time to be up
  digitalWrite (IOXpin, HIGH);

  Serial.println ("Done.");
  
  }  // end of processNumber

void handleKeypress (const char key)
  {
  Serial.print ("Got: ");
  Serial.println (key);

  static unsigned long receivedNumber = 0;
  
  switch (key)
    {
    case '#':  
      processNumber (receivedNumber);
      receivedNumber = 0; 
      break;
      
    case '0' ... '9': 
      receivedNumber *= 10;
      receivedNumber += key - '0';
      break;

    default: 
      Serial.println ("Unexpected input!");
      break;
      
    } // end of switch  
    
  }  // end of handleKeypress

void loop()
{
  byte key = kpd.getKey();
  if (key)
    handleKeypress (key);
}

Don't need passwords. Just a simple keypad handler. Send the keys off to a state machine. That handles numbers. Then the "#" "commits" the number and it starts dispensing. You use the "*" to abort.

Now this might not do everything you want, but it shows the general idea.

Merci beaucoup mon ami pour votre aid. I don't know how to thank you. I am new to this and you just saved me the headache. I am trying to learn but given the time I have left and what I still have to do. I realized it's not worth it to spend more time to think about what each function does in the code. But Arduino is definitley fascinating. I need to look into it.
Thank you very much.