Avinash Repaka / Mbed 2 deprecated Lab4_519

Dependencies:   mbed

Revision:
2:2cc70773996b
Parent:
1:4ec28912c9e7
Child:
4:95fe80130442
--- a/Keypad.h	Thu Mar 26 02:25:46 2015 +0000
+++ b/Keypad.h	Thu Mar 26 06:10:56 2015 +0000
@@ -1,9 +1,11 @@
 #include "mbed.h"
-//#include "RequestQueue.h"
+#include "GlobalObjects.h"
+
+#ifndef KEYPAD_H
+#define KEYPAD_H
 
 //selection pin
 volatile int index = 1;
-Serial pc(USBTX, USBRX);
 
 //Row pins
 InterruptIn inputOne(p8);
@@ -23,16 +25,32 @@
 
 void changeConfiguration();
 
+void keyPressed (char ch){
+    pc.printf(": %c is pressed :",ch);
+    switch(ch){
+        case '1': floorChosen(1); break;
+        case '2': floorChosen(2); break;
+        case '3': floorChosen(3); break;
+        case '4': floorChosen(4); break;
+        case '5': floorChosen(5); break;
+        default: break;
+    }
+}
+
 void keyOnePressed (){
     keypadTicker .detach();
-    if (index == 1)
-        pc.printf(":   1 is pressed   :");
-    if (index == 2)
-        pc.printf(":   4 is pressed   :");
-    if (index ==3)
-        pc.printf(":   7 is pressed   :");
-    if (index ==4)
-        pc.printf(":   * is pressed   :");       
+     if (index == 1)
+        keyPressed('1');
+        //pc.printf(":   1 is pressed   :");
+    else if (index == 2)
+        keyPressed('4');
+        //pc.printf(":   4 is pressed   :");
+    else if (index ==3)
+        keyPressed('7');
+        //pc.printf(":   7 is pressed   :");
+    else if (index ==4)
+        keyPressed('*');
+        //pc.printf(":   * is pressed   :");      
 }
 
 void keyOneReleased (){
@@ -41,14 +59,18 @@
     
 void keyTwoPressed (){
    keypadTicker .detach();
-   if (index == 1)
-        pc.printf(":   2 is pressed   :");
-    if (index == 2)
-        pc.printf(":   5 is pressed   :");
-    if (index ==3)
-        pc.printf(":   8 is pressed   :");
-    if (index ==4)
-        pc.printf(":   0 is pressed   :");       
+    if (index == 1)
+        keyPressed('2');
+        //pc.printf(":   2 is pressed   : );
+    else if (index == 2)
+        keyPressed('5');
+        //pc.printf(":   5 is pressed   :");
+    else if (index ==3)
+        keyPressed('8');
+        //pc.printf(":   8 is pressed   :");
+    else if (index ==4)
+        keyPressed('0');
+        //pc.printf(":   0 is pressed   :");      
 }
 
 void keyTwoReleased (){
@@ -58,13 +80,17 @@
 void keyThreePressed (){
    keypadTicker .detach();
    if (index == 1)
-        pc.printf(":   3 is pressed   :");
-    if (index == 2)
-        pc.printf(":   6 is pressed   :");
-    if (index ==3)
-        pc.printf(":   9 is pressed   :");
-    if (index ==4)
-        pc.printf(":   # is pressed   :");       
+        keyPressed('3');
+        //pc.printf(":   3 is pressed   :");
+    else if (index == 2)
+        keyPressed('6');
+        //pc.printf(":   6 is pressed   :");
+    else if (index ==3)
+        keyPressed('9');
+        //pc.printf(":   9 is pressed   :");
+    else if (index ==4)
+        keyPressed('#');
+        //pc.printf(":   # is pressed   :");       
 }
 
 void keyThreeReleased (){
@@ -73,14 +99,18 @@
 
 void keyFourPressed (){
    keypadTicker .detach();
-   if (index == 1)
-        pc.printf(":   A is pressed   :");
-    if (index == 2)
-        pc.printf(":   B is pressed   :");
-    if (index ==3)
-        pc.printf(":   c is pressed   :");
-    if (index ==4)
-        pc.printf(":   D is pressed   :");              
+    if (index == 1)
+        keyPressed('A');
+        //pc.printf(":   A is pressed   :");
+    else if (index == 2)
+        keyPressed('B');
+        //pc.printf(":   B is pressed   :");
+    else if (index ==3)
+        keyPressed('C');
+        //pc.printf(":   c is pressed   :");
+    else if (index ==4)
+        keyPressed('D');
+        //pc.printf(":   D is pressed   :");              
 }
 
 void keyFourReleased (){
@@ -135,4 +165,6 @@
     inputFour.fall(&keyFourPressed);
     inputFour.rise(&keyFourReleased);
     keypadTicker.attach(&changeConfiguration, scanInterval);
-}
\ No newline at end of file
+}
+
+#endif
\ No newline at end of file