Digital code lock w/o using libraries

Hi one and all this is my first post and fairly new to the world of arduino and look forward to any guidance and help offered in aquiring knolledge on this exiting platform , and any help is welcome. ill start with a brief outline of what im trying to achieve and highlight the problem im encountering

I have managed to interface an 3x4 keypad to arduino , by taking inspiration in some respects and lots of reading and youtubing so far so apoligies if comments and code is not layed out in an easiy digestableway.

My problem is trying to encorporate a password into this program and , i have tried numerous things , and the only sucess that i have has is using 2 arrays one for userinput and one for password along with a keystate variable 'keypress' and a index counting variable for both . i have tried comparing these and have managed to get the unlock stage done but the lock stage is not. i also want the hash to be used to verify the correct code and star to reset the lock. I understand my code may be inefficeint and welcome any constructive critsism in aid to bring this project closer to its finish ,i also need the welcome message "enter password " to reconvine after it has been locked , reseting to orginal state ready for input.i think that is about it for the moment , thanks in advance

////////////////////////////////////////////////////  
///////////Global variable declaration/////////////
//////////////////////////////////////////////////

int rw1 = 7;      //row1
int rw2 = 2;     //row2
int rw3 = 3;    //row3
int rw4 = 5;   //row4

int cl1 = 6;     //collumn1
int cl2 = 8;    //collumn2
int cl3 = 4;   //colluumn3

int col_var_1;
int col_var_2;  //column variables 
int col_var_3;

int global_db_delay=200;  ///global delay variable 

int keyid=0;                                   //key identifier 
int keypress=0;                                //key state 
int userinput[4];                             //user keystrokes 
int password[4]= {1,2,3,4};    //password array 
int usr_in_count=0;                         //index variable for password array 


//////////////////////////////////////////////////  
///////////Setup and initialization//////////////
////////////////////////////////////////////////
///////////////////////////////////////////////
void setup(){
  String wm="Enter password";
  
  Serial.begin(9600); //baud rate for serial monitor 
  pinMode(rw1, OUTPUT);              
  pinMode(rw2, OUTPUT);    
  pinMode(rw3, OUTPUT);    
  pinMode(rw4, OUTPUT);    ///////set pinmode parameters for rows and cols 
  pinMode(cl1, INPUT);     
  pinMode(cl2, INPUT);     
  pinMode(cl3, INPUT);     

  digitalWrite(cl1, HIGH);
  digitalWrite(cl2, HIGH);  //input pins pulled high -will read high unless buttons are pressed 
  digitalWrite(cl3, HIGH);
  
  Serial.println(wm);
}

//////////////////////////////////////////////
//////////////////Main Program///////////////
////////////////////////////////////////////
void loop(){


//////////////////////////////////  
///////////ROW1 SCAN//////////////
//////////////////////////////////
  
  digitalWrite(rw1, LOW);
  digitalWrite(rw2, HIGH);               //row is selected by making the output of that row low - with the input pulled high -when the button is pressed it will pull that input low 
  digitalWrite(rw3, HIGH);              //all other rows pulled high are ignored 
  digitalWrite(rw4, HIGH);
  col_var_1 = digitalRead(cl1);
  col_var_2 = digitalRead(cl2);
  col_var_3= digitalRead(cl3);

  if (col_var_1 == LOW){
    keypress=1;
    keyid=1;
    Serial.println("1");
    delay(global_db_delay);
  
    }
    
  else{
   if (col_var_2 == LOW){ 
    keypress=1;
    keyid=2;                                    
    Serial.println("2");
    delay(200);
    }
    
   else{
    if (col_var_3== LOW){ 
     keypress=1;
     keyid=3;   
     Serial.println("3");
     delay(global_db_delay);
     }
    }
   }

//////////////////////////////////  
///////////ROW2 SCAN//////////////
//////////////////////////////////


  digitalWrite(rw1, HIGH);
  digitalWrite(rw2, LOW);
  digitalWrite(rw3, HIGH);
  digitalWrite(rw4, HIGH);
  col_var_1 = digitalRead(cl1);
  col_var_2 = digitalRead(cl2);
  col_var_3= digitalRead(cl3);

  if (col_var_1== LOW){ 
    keypress=1;
    keyid=4; 
    Serial.println("4");
    delay(global_db_delay);
    }
  
  else{
   if (col_var_2== LOW){
    keypress=1;
    keyid=5;
    Serial.println("5");
    delay(global_db_delay);
    }
    
  else{
   if (col_var_3== LOW){ 
     keypress=1;
     keyid=6;
     Serial.println("6");
     delay(global_db_delay);
      }
     }
    }

//////////////////////////////////  
///////////ROW3 SCAN//////////////
//////////////////////////////////

  digitalWrite(rw1, HIGH);
  digitalWrite(rw2, HIGH);
  digitalWrite(rw3, LOW);
  digitalWrite(rw4, HIGH);
  col_var_1 = digitalRead(cl1);
  col_var_2= digitalRead(cl2);
  col_var_3= digitalRead(cl3);

  if (col_var_1== LOW){ 
   keypress=1;
   keyid=7;
   Serial.println("7");
   delay(global_db_delay);
  }
  
  else{
   if (col_var_2 == LOW){ 
    keypress=1;
    keyid=8; 
    Serial.println("8");
    delay(global_db_delay);
   }
    
 else{
   if (col_var_3== LOW){ 
    keypress=1;
    keyid=9;
    Serial.println("9");
    delay(global_db_delay);
      
      }
     }
    }
///////////////////////////////////
//////////////////////////////////

digitalWrite(rw1, HIGH);
  digitalWrite(rw2, HIGH);
  digitalWrite(rw3, HIGH);
  digitalWrite(rw4, LOW);
  col_var_1 = digitalRead(cl1);
  col_var_2= digitalRead(cl2);
  col_var_3= digitalRead(cl3);

  if (col_var_1== LOW){ 
   keypress=1;
   keyid=10;
   Serial.println("*");
   delay(global_db_delay);
  }
  
  else{
   if (col_var_2 == LOW){ 
    keypress=1;
    keyid=0; 
    Serial.println("0");
    delay(global_db_delay);
   }
    
 else{
   if (col_var_3== LOW){ 
    keypress=1;
    keyid=12;
    Serial.println("#");
    delay(global_db_delay);
      
      }
     }
    }




    

if(userinput[0]==password[0] && userinput[1]==password[1] && 
   userinput[2]==password[2] && userinput[3]==password[3]){
     
      Serial.println("UNLOCKED");
      
      
      userinput[0]=0;
      userinput[1]=0;
      userinput[2]=0;          //reset user input,index variable and ,keypress'keystate'  
      userinput[3]=0;
      usr_in_count=0;
      keypress=0;
  }

if(keyid==10){
   usr_in_count=0;
      userinput[0]=0;
      userinput[1]=0;
      userinput[2]=0;
      userinput[3]=0;
      usr_in_count=0;
      keypress=0;

     Serial.println("locked");
  
  }


if(keypress==1){
    userinput[usr_in_count]=keyid;
    usr_in_count=usr_in_count+1;
    keypress=0;
    }
    }
   




  
///////////////////////////////////////
///////////End of key scan/////////////   
//////////////////////////////////////

You should really be using arrays for the rows and columns. It would reduce the size of the program by about a factor of 10.

Hi

first of all your button scanner can be Made realy easy, by useing a FOR loop.
it will make your code 4 times smaller!

and second i see when you entered the correct code/password you lock i back again.
so:

  1. enter correct code.
  2. system unlocked.
  3. Reset userinput.
  4. back locked again.

dont reset userinput when your inside the unlock code.
only do it when you lock it. by pressing keyid= 10

i think thats the reason why you THINK! you locked code doesnt work.

spirit:
first of all your button scanner can be Made realy easy, by useing a FOR loop.
it will make your code 4 times smaller!

But you will need arrays to utilize the for loop. More than 4 times smaller, if you also design functions to encapsulate the digital reads and writes.

You really need to separate different operations into individual functions. That's the way to get around your "Enter Password" problem, too. You could create a function called 'getPassword()' or similar, as well as one called 'readKeypad()' or similar to read your keypad.
It would make your life much easier.

Even if you don't want to use libraries, it's not a bad idea to study the "Keypad" library to get an idea of the best way to do things. It's a good way to learn. (You don't need to copy it, just study the concepts.)

During setup, you can enable input pullups far more easily, too.
Instead of this:-

pinMode(cl1, INPUT);     
  pinMode(cl2, INPUT);     
  pinMode(cl3, INPUT);     

  digitalWrite(cl1, HIGH);
  digitalWrite(cl2, HIGH);  //input pins pulled high -will read high unless buttons are pressed
  digitalWrite(cl3, HIGH);

you can do this:-

pinMode(cl1, INPUT_PULLUP);     
  pinMode(cl2, INPUT_PULLUP);     
  pinMode(cl3, INPUT_PULLUP);

And I have to ask, why don't you want to use libraries?

Hi steve , i think ive been long overdue this talk of organization in terms of my code haha , thanks for pointing it out , makes alot of sense to do this ,so would i treat these extra fucntions as subroutines , in a bid to get my code into a more logical format ??And would there be a way to condense the code down , as the keypad scanning works but is clunky and alot of it and is asthetically displeasing !!haha

And my reason for not using librarys is just my learning style i suppose i appreciate the time they save in providing fucntionality, but they do take some of the challenege away , being one of my first higher level languages i feel its the best way to learn for me, as its how got past the barriers in learning lower level assembler languages primarily Microchips Pics midrange family. My motivation for this i suppose is theres always a variety of ways something can be achieved , and an outside perspective can prove invaluable in the learning process.

Also thanks for the hint with the pull ups !!

OldSteve:
You really need to separate different operations into individual functions. That’s the way to get around your “Enter Password” problem, too. You could create a function called ‘getPassword()’ or similar, as well as one called ‘readKeypad()’ or similar to read your keypad.
It would make your life much easier.

Even if you don’t want to use libraries, it’s not a bad idea to study the “Keypad” library to get an idea of the best way to do things. It’s a good way to learn. (You don’t need to copy it, just study the concepts.)

During setup, you can enable input pullups far more easily, too.
Instead of this:-

pinMode(cl1, INPUT);     

pinMode(cl2, INPUT);   
  pinMode(cl3, INPUT);

digitalWrite(cl1, HIGH);
  digitalWrite(cl2, HIGH);  //input pins pulled high -will read high unless buttons are pressed
  digitalWrite(cl3, HIGH);



you can do this:-


pinMode(cl1, INPUT_PULLUP);   
  pinMode(cl2, INPUT_PULLUP);   
  pinMode(cl3, INPUT_PULLUP);




And I have to ask, why don't you want to use libraries?

Hi aarg

Thanks for the advice it just dawned on me that would make a big difference in the initialization stage,but have difficulty in implimenting it in my keypad read loop could you shed some light prehaps??
,i have however taken your advice on in the set up stage and makes a huge difference ill paste what ive done so far , still far from pretty but definatly tidier

////////////////////////////////////////////////////  
///////////Global variable declaration/////////////
//////////////////////////////////////////////////

int row_array[4]= {7,2,3,5};      //ROWS 

int r_index;                     //index variable 

int collumn_array[3]={6,8,4};   //COLS

int c_index;                   //index variable 

int col_Var1;
int colVar_2;  //column variables 
int colVar_3;
////////////////////////////////////////////////////
///////////////////////////////////////////////////
int global_db_delay=200;  ///global delay variable 

int keyid=0;                                   //key identifier 
int keypress=0;                                //key state 
int userinput[4];                             //user keystrokes 
int password[4]= {1,2,3,4};    //password array 
int usr_in_count=0;                         //index variable for password array 


//////////////////////////////////////////////////  
///////////Setup and initialization//////////////
////////////////////////////////////////////////
///////////////////////////////////////////////
void setup(){

String wm="Enter password";
  
Serial.begin(9600); //baud rate for serial monitor 
 
for(r_index=0;r_index<4;r_index++){
   pinMode(row_array[r_index], OUTPUT)}       //initialize pinmode rows  

for(c_index=0;c_index<3;c_index++){
   pinMode(collumn_array[c_index], OUTPUT)}  //initialize pinmode cols   

  pinMode(collumn_array[0], INPUT_PULLUP);    
  pinMode(collumn_array[1], INPUT_PULLUP);   //internal pullups for rows        
  pinMode(collumn_array[2], INPUT_PULLUP);

  Serial.println(wm);
}


void loop(){}


void readKeypad(){}


void getPassword{}


}

Hi spirit

Thanks for your insight , do you mean for loops nested within an if loop , as my only concern really is the timing , its not something ive tried in this project yet , but i want the keypresses to be as instananeous as possible , 1 because of functionality and 2 its nicking all ports space haha ,but on a serious not thanks for bringing that too light and any other suggestions are very welcome !!!

hi just for the fun i tried it my self.
but i understood the theorie and had a 4x4 keypad laying around.

const uint8_t colom[4] = {13, 12, 11, 10};
const uint8_t row[4] = {7, 6, 5, 4};

const char sign[4][4] = {
  {'1', '2', '3', 'A'},
  {'4', '5', '6', 'B'},
  {'7', '8', '9', 'C'},
  {'*', '0', '#', 'D'}
};

void setup() {

  Serial.begin(9600);

  for (uint8_t x = 0; x < 4; x++) {
    pinMode(colom[x], OUTPUT);
  }
  for (uint8_t x = 0; x < 4; x++) {
    pinMode(row[x], INPUT_PULLUP);
  }
}



void loop() {
  char a = readKeypad();
  //Serial.println(a);
}

char readKeypad() {
  for (uint8_t x = 0; x < 4; x++) { // for loop 1. to scan thru the digitalWrite pins
    digitalWrite(colom[x], LOW); // set pin[x] LOW
    for (uint8_t y = 0; y < 4; y++) { // for loop 2. to scan thru the digitalRead pins
      if (digitalRead(row[y]) == LOW) {
        //return sign[x][y]; // somehow i cant get this to work :-(
        Serial.println(sign[x][y]); // this works OK!
      }
    }
    digitalWrite(colom[x], HIGH); // set pin[x] HIGH again. only 1 pin must be LOW!
  }
}

this is a example. there are somethings i cant get to work, but i get the correct output.
its just to give you a idea how to use the For loops.

and i dont use delay, and i use less digitalWrite. so my code should run faster.

AlexENG:
And my reason for not using librarys is just my learning style i suppose i appreciate the time they save in providing fucntionality, but they do take some of the challenege away , being one of my first higher level languages i feel its the best way to learn for me, as its how got past the barriers in learning lower level assembler languages primarily Microchips Pics midrange family. My motivation for this i suppose is theres always a variety of ways something can be achieved , and an outside perspective can prove invaluable in the learning process.

I come from a mid-range PIC background too - I've used them for over 20 years. C, PICBasic Pro and some assembly. I don't think it's worth the effort of using assembly for everything any more. Short inline assembly routines have their place, but where possible I'd always use a high-level language.

I actually switched to Arduino because of the libraries. It's OK to do it the hard way while learning the basics, but why re-invent the wheel? You can get stuck spending long periods writing complex code to do the simplest things. (Like right now.) And generally a well-written library will do things much more efficently than you or I might.
With a library you can often be up-and-running reading keypads, (or whatever), in under 10 minutes, leaving you free to concentrate on the more important aspects of the program.

I got sick of constantly having to connect all of those wires and waste so many pins to read a 4x4 keypad, so made an I2C keypad a few weeks ago. An ATtiny84 does all of the keypad reading stuff, and communicates with the host, (usually a UNO), with an I2C interface.
No more messing around for me when prototyping - just two wires plus power connections. :slight_smile:

Hi spirt

Thanks for giving it a go to demonstrate the use of for loops ,found it usefull ,i was aware of how to use for loops though although it gave a basis for reduction of my original code though only marginally in the grand scheme of things , i feel like maybe going back to the drawing board on this one may seem like a good idea , but have spent a good amount of time getting to this position , so im inclined to get it to work.I understand the theory behind the keypad just lack the knollegde in translating it into an efficeint piece of code . For example the keymap had me a tad confused i know the need it but the implimentation and use confuse me , aside from that i think i get the jist of it, again thanks for you input to this discusion


Hi steve

Thats wicked , alot of people tend to start of with the PIC platform within microprocessor development,it quite interesting.20 years!! welll i feel quite young in the game coming up to my third year focusing mainly on assembler language using MPlab and more recently trying to teach myself C/C++, so naturally i saw the Arduino as a good middle ground in getting familair ,as there is some crossover with C a bit of a gentle intoduction if you will .

I have to say i have to agree with you , using assembler for everything is not really nessesary anymore , although there are times where you can achieve the same result with less line of code , and the compiling time is virtually non-existant.But for the most part the higher level languages have been more fun in my opinion and a bit more diverse in some respects, assembler can be tiresom at times .

I do understand what your trying to say and am inclined to agree , but for this specific project the keypad and password are the main bits of code i will impliment , as for the lcd ill be using an i2c connection using the <wire.h> and the <liquidcrystal.h> as i have a module for connecting lcd’s via an i2c connection ive had laying about for a while.So as you can see im trying to focus on the keypad and password code,although my method seems to be of a brute force style approach haha .

Though at the moment it works much to my suprise , aside one minor detail which i was going to enquire about , as i cant think of a way to solve it without entering an eternal loop, ive got to the point where correct entering of the password unlocks , and pressing star resets the lock and locks ,but password failure is what im stuck on , i want after 4 presses of the incorrect key to display password failed and reset index positions and keypress’s so that an attempt can be made again without having to press * to reset.Any help on this would essentially see this project a sucess .

That i2c keypad sounds pretty sweet aswell id be interested in hearing more about that, the notion of i2c for both lcd and keypad leaves a whole lotta port space espcially if your working on an uno.Ive seen a way you can essentially use 1 wire meaning one pin in your portspace , but then i forgot you have to connect 5v to the rows so it depends on how you you look at it really ,but it uses resistance values therfore using the analogue read port to ‘convert’ and assign to integer values ,interesting concept .

Also just had a look at that attiny84 looks pretty sweet , is there any support aside from datasheets , might have to get a couple ,apoligies for the long message ahaha

/////////////////////////////////////////////////////////////////////////////////  
///////////Global variable declaration//////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////

int row_array[4]= {7,2,3,5};  //ROWS 
int r_index;                 //index variable 
int col_array[3]={6,8,4};   //COLS                
int c_index;               //index variable 
int colVar[3];            //collumn variable[ high/low] 

//////////////////////////////////////////////////////////////////////////
//////////////////DEBOUNCER /////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////

int global_db_delay=200;  ///global delay variable

//////////////////////////////////////////////////////////////////////
///////////PASSWORD+USERINPUT/KEYSTATE///////////////////////////////
////////////////////////////////////////////////////////////////////

int keyid=0;                                   //key identifier 
int keypress=0;                               //key state 
int userinput[4];                            //user keystrokes 
int password[4]= {1,2,3,4};                 //password array 
int usr_in_count=0;                        //index variable for password array 

///////////////////////////////////////////////////////////////  
///////////Setup and initialization///////////////////////////
/////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////

void setup(){

String wm="Enter password";                         //welcome message string 
  
Serial.begin(9600);                               //baud rate for serial monitor 
 
for(r_index=0;r_index<4;r_index++){
   pinMode(row_array[r_index], OUTPUT);}        //initialize pinmode rows  

for(c_index=0;c_index<3;c_index++){
   pinMode(col_array[c_index], INPUT_PULLUP);} //initialize pinmode cols and activate pullups  

Serial.println(wm);                       //display welcome message 
}

//////////////////////////////////////////////////////
//////////////////Main Program///////////////////////
////////////////////////////////////////////////////

void loop(){
  
////////////////////////////////////////////  
///////////ROW1 SCAN///////////////////////
//////////////////////////////////////////

 for(int x=0;x<4;x++){
    digitalWrite(row_array[x], HIGH);}     //sets row 2,3 and 4 high 
    digitalWrite(row_array[0], LOW);      //sets row one low -selecting row 1 negating rows pulled high 

 for(int i=0;i<3;i++){                              
     colVar[i] = digitalRead(col_array[i]);}  //cycles through collumns reading conditions , if button is pressed the coresponding column is pulled low indicating key press 

  if (colVar[0] == LOW){
     keypress=1;                      //key id assigns value for comparision with user input and password array //keypress is used as an indicator for keystrokes  
     keyid=1;                        //If conditionals assign key values to buttons pressed , again in line with the coresponding collumns and row selected 
     Serial.println("1");
     delay(global_db_delay);       //debouncing delay prevents continous stream of values being printed on the serial monitor 
     }
                                 //repeat for each row 
 else{
  if (colVar[1] == LOW){ 
     keypress=1;
     keyid=2;                                    
     Serial.println("2");
     delay(200);
     }
    
 else{
  if (colVar[2]== LOW){ 
     keypress=1;
     keyid=3;   
     Serial.println("3");
     delay(global_db_delay);
     }
    }
   }

////////////////////////////////////////////  
///////////ROW2 SCAN///////////////////////
//////////////////////////////////////////

 for(int x=0;x<4;x++){
    digitalWrite(row_array[x], HIGH);}
    digitalWrite(row_array[1], LOW);
    
 for(int i=0;i<3;i++){
     colVar[i] = digitalRead(col_array[i]);}

 if (colVar[0] == LOW){
    keypress=1;
    keyid=4;
    Serial.println("4");
    delay(global_db_delay);
    }
    
 else{
  if (colVar[1] == LOW){ 
     keypress=1;
     keyid=5;                                    
     Serial.println("5");
     delay(200);
     }
    
 else{
  if (colVar[2]== LOW){ 
     keypress=1;
     keyid=6;   
     Serial.println("6");
     delay(global_db_delay);
     }
    }
   }
   
////////////////////////////////////////////  
///////////ROW3 SCAN///////////////////////
//////////////////////////////////////////

for(int x=0;x<4;x++){
    digitalWrite(row_array[x], HIGH);}
    digitalWrite(row_array[2], LOW);
    
for(int i=0;i<3;i++){
    colVar[i] = digitalRead(col_array[i]);}

 if (colVar[0] == LOW){
    keypress=1;
    keyid=7;
    Serial.println("7");
    delay(global_db_delay);
     }
    
 else{
  if (colVar[1] == LOW){ 
     keypress=1;
     keyid=8;                                    
     Serial.println("8");
     delay(200);
     }
    
 else{
  if (colVar[2]== LOW){ 
     keypress=1;
     keyid=9;   
     Serial.println("9");
     delay(global_db_delay);
    }
   }
  }
   
////////////////////////////////////////////  
///////////ROW4 SCAN///////////////////////
//////////////////////////////////////////

 for(int x=0;x<4;x++){
    digitalWrite(row_array[x], HIGH);}
    digitalWrite(row_array[3], LOW);
    
 for(int i=0;i<3;i++){
    colVar[i] = digitalRead(col_array[i]);}

 if (colVar[0] == LOW){
    keypress=1;
    keyid=10;
    Serial.println("*");
    delay(global_db_delay);
    }
    
 else{
  if (colVar[1] == LOW){ 
    keypress=1;
    keyid=11;                                    
    Serial.println("0");
    delay(200);
    }
    
  else{
   if (colVar[2]== LOW){ 
     keypress=1;
     keyid=12;   
     Serial.println("#");
     delay(global_db_delay);
     }
    }
   }
  passwordRead();
 }
 
/////////////////////////////////////////////
/////////END OF KEYSCAN ////////////////////
///////////////////////////////////////////


void passwordRead(){

/////////////////////////////////////////////
/////////UNLOCK CONDITIONS//////////////////
/////////////////////////////////////////// 
  
if(userinput[0]==password[0] && userinput[1]==password[1] &&   //compares userinput and password at relevant index positions 
   userinput[2]==password[2] && userinput[3]==password[3]){    
   
   Serial.println("UNLOCKED");                             //greeting message on correct code 
 
for(int y=0;y<4;y++){
   userinput[y]=0;}                                 //reset user input array to zero ,index variable and ,keypress'keystate'
   usr_in_count=0;
   keypress=0;
   
   }
   
if(keypress==1){
   userinput[usr_in_count]=keyid;      //asigns keyid the value of the userinput/userinput count 
   usr_in_count=usr_in_count+1;       //each correct integer comparison increments userinput index 
   keypress=0;                       //resets key press to zero (nothing has been pressed)
   }
   
///////////////////////////////////////////
///////////LOCK CONDITIONS////////////////
/////////////////////////////////////////

if(keyid==10&&colVar[0]== LOW){   //if key * has been pressed and column 2 is pulled low (momentarily pulled low stopping endless loop ) 
   Serial.println("locked");
   digitalWrite(10,HIGH);

for(int y=0;y<4;y++){
   userinput[y]=0;}         //reset user input,index variable and ,keypress'keystate'
   usr_in_count=0;
   keypress=0;
   
   }
  }

                                               //////////////////////////////////////////////
 //////////////////////////////////////////////////////////////END OF PROGRAM/////////////////////////////////////////////////////////////////////////////////////////
                                              /////////////////////////////////////////////