4180 Final Project

Dependencies:   4DGL-uLCD-SE mbed Servo

Revision:
12:22444d5f5920
Parent:
11:1ca1f07896b0
Child:
13:88d8408f6e60
--- a/main.cpp	Thu Apr 21 14:09:35 2016 +0000
+++ b/main.cpp	Thu Apr 21 21:42:24 2016 +0000
@@ -40,8 +40,10 @@
 int maxLength = 18; //random length chosen
 int minLength = 5;  //random length chosen
 
+
 //function for debugging
-void printPW() {
+void printPW()
+{
     for (int i=0; i<password.size(); i++) {
         pc.printf("%d", int(password[i]));
     }
@@ -57,7 +59,7 @@
 
     //checks every key for press
     for (i=0; i<=11; i++) {
-        
+
         //if key 10 (clr) is pressed, clear the last value on the vector will be popped off
         if ((((value>>i)&0x01)==1)&&(i==10)) {
             if (!password.empty()) {
@@ -66,22 +68,22 @@
                 pc.printf("container size: %d\r\n", password.size());//for debugging
             }
         }
-        
+
         //if key 11 (ENTER) is pressed, the password will be submitted IF it is long enough
         else if ((((value>>i)&0x01)==1)&&(i==11)) {
-            
+
             //if the password is long enough, check passwords, and clear vector.
             if (password.size() > minLength) { // --------- password.size() == 6 -------------- PAYMAN
-                password = ans; // ------checkResult() , passing password to ans (vector used in checkResult() ------ PAYMAN
+                ans = password; // ------checkResult() , passing password to ans (vector used in checkResult() ------ PAYMAN
                 //CALL checkResult() FUNCTION, OR SET A FLAG INDICATING THAT PASSWORD IS COMPLETE AND AVAILABLE TO BE CHECKED!
                 password.clear(); //only use this if the checkResult is called above. If a flag is set, do not call this here - it should be called from within the checkResult function!
             }
-            
+
             else {
                 pc.printf("The password must be at least %d characters long\r\n", minLength);
             }
-        } 
-        
+        }
+
         //if keys 0 through 9 are pressed
         else if (((value>>i)&0x01)==1) {
 
@@ -90,11 +92,11 @@
                 key_code=i;
                 password.push_back((char)key_code);
                 printPW(); //for debugging
-            } 
-            
+            }
+
             //if max password length has been reached
             else {
-                pc.printf("Maximum password length reached.\r\n");   
+                pc.printf("Maximum password length reached.\r\n");
             }
         }
     }
@@ -131,8 +133,8 @@
 
     // vector<char> ans(password.size()); //This vector should be the values coming from keypad
     //ans = password; // password from fallInterrupt function
-    
-    
+
+
     if (pass.size()==6) {
         i++; //use "i" to find which person logged in.
         if (ans == pass) {
@@ -176,16 +178,10 @@
 }
 
 
-
-int main()
+//Interrupt
+void Rx_interrupt()
 {
-    interrupt.fall(&fallInterrupt);
-    interrupt.mode(PullUp);
-    //load_from_file();
-
-    //interupt driven read from serial port
-    // calls save_to_file();
-    while(1) {
+    while (pc.readable()) {
         char c = pc.getc();
         if (c!='#') {
             im.push_back(c); //writing all the characters into vector
@@ -196,8 +192,21 @@
                 //lcd.printf("%c",im[cnt]);
             }
         }
+
     }
-
+    return;
 }
 
 
+int main()
+{
+    interrupt.fall(&fallInterrupt);
+    interrupt.mode(PullUp);
+    //load_from_file();
+
+    //interupt driven read from serial port
+    // calls save_to_file();
+    pc.attach(&Rx_interrupt, Serial::RxIrq);
+}
+
+