try1 with keypad

Dependencies:   keypad mbed

Revision:
3:74062f7daedd
Parent:
2:05f7cf34c118
Child:
4:4c7fb6a870bf
--- a/keyo.cpp	Tue Nov 07 01:12:28 2017 +0000
+++ b/keyo.cpp	Tue Nov 07 01:52:20 2017 +0000
@@ -7,14 +7,29 @@
                      '7', '8', '9', 'C',   // r2
                      '*', '0', '#', 'D',   // r3
                    };
-                  // c0   c1   c2 
+                  // c0   c1   c2   c3
  
  uint32_t Index;
- uint32_t
+ uint32_t pass = 1234,check=1,modc=1000; //password is 1234, modc is current val of mod. the value will be 10^(n-1). n is no of digits of pass
+ DigitalOut led1(LED_BLUE);
+ DigitalOut led2(LED_GREEN);
+ DigitalOut led3(LED_RED);
+   
  uint32_t cbAfterInput(uint32_t index) {
      Index = index;
-     PwmOut r(LED_RED);
-     return 0;
+     led1=!led1;
+     if(check == 1)
+      if(pass/modc == Index)
+       { check = 1;
+         modc=modc/10;
+       } 
+     else check =0;
+     
+     if(modc==0)
+      if(check == 1) led2=!led2;  
+      else led3=!led3;
+     else;  
+      return 0;
  }
  
  int main() {
@@ -22,7 +37,7 @@
      Keypad keypad(PTE5, PTE4, PTE3, PTE2, PTB11, PTB10, PTB9, NC);
      keypad.attach(&cbAfterInput);
      keypad.start();  // energize the keypad via c0-c3
-     PwmOut r(LED_BLUE);
+     //PwmOut r(LED_RED); //for checking
 
      while (1) {
          __wfi();