try1 with keypad

Dependencies:   keypad mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers keyo.cpp Source File

keyo.cpp

00001 #include "mbed.h"
00002 #include "Keypad.h"
00003  
00004  // Define your own keypad values
00005  char Keytable[] = { '1', '2', '3', 'A',   // r0
00006                      '4', '5', '6', 'B',   // r1
00007                      '7', '8', '9', 'C',   // r2
00008                      '*', '0', '#', 'D',   // r3
00009                    };
00010                   // c0   c1   c2   c3
00011  
00012  uint32_t Index;
00013  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
00014  DigitalOut led1(LED_BLUE);
00015  DigitalOut led2(LED_GREEN);
00016  DigitalOut led3(LED_RED);
00017    
00018  uint32_t cbAfterInput(uint32_t index) {
00019      Index = index;
00020      led1=!led1;
00021      if(check == 1)
00022       if(pass/modc == Index)
00023        { check = 1;
00024          modc=modc/10;
00025        } 
00026       else check =0;
00027      else check =0; 
00028      
00029      if(modc==0)
00030       if(check == 1) led2=!led2;  
00031       else led3=!led3;
00032      else;  
00033      pass=pass%10;
00034       return 0;
00035  }
00036  
00037  int main() {
00038                  // r0    r1    r2    r3    c0     c1     c2   c3
00039      Keypad keypad(PTE5, PTE4, PTE3, PTE2, PTB11, PTB10, PTB9, NC);
00040      keypad.attach(&cbAfterInput);
00041      keypad.start();  // energize the keypad via c0-c3
00042      //PwmOut r(LED_RED); //for checking
00043 
00044      while (1) {
00045          __wfi();
00046          printf("Interrupted\r\n");
00047          printf("Index:%d => Key:%c\r\n", Index, Keytable[Index]);
00048      }
00049  }