RuiViana

KeyPadRepeater

Nov 24th, 2019
241
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. #include <Keypad.h>
  3.  
  4. const byte ROWS = 4; //four rows
  5. const byte COLS = 4; //four columns
  6. //define the cymbols on the buttons of the keypads
  7.  
  8. char hexaKeys[ROWS][COLS] =
  9. { {'1', '2', '3', 'A'},
  10.   {'4', '5', '6', 'B'},
  11.   {'7', '8', '9', 'C'},
  12.   {'*', '0', '#', 'D'}
  13. };
  14. byte rowPins[ROWS] = {3, 2, 1, 0}; //connect to the row pinouts of the keypad
  15. byte colPins[COLS] = {7, 6, 5, 4}; //connect to the column pinouts of the keypad
  16.  
  17. //initialize an instance of class NewKeypad
  18. Keypad customKeypad = Keypad( makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS);
  19. String minhaStr ;
  20. unsigned long meuValor;
  21. char  kpadState;
  22. char customKey ;
  23. char oldKey ;
  24. //-----------------------------------------
  25. void setup()
  26. {
  27.   Serial.begin(9600);
  28. }
  29. //-----------------------------------------
  30. void loop()
  31. {
  32.   customKey = customKeypad.getKey();
  33.   kpadState = customKeypad.getState();
  34.  
  35.   switch ( kpadState )
  36.   {
  37.     case PRESSED:
  38.       if (customKey)
  39.       {
  40.         oldKey = customKey;
  41.         if ((customKey >= '0' ) and (customKey <= '9'))
  42.         {
  43.           minhaStr += customKey;
  44.           meuValor = minhaStr.toInt();
  45.           Serial.print("meuValor "); Serial.println(meuValor);
  46.         }
  47.       }
  48.       break;
  49.  
  50.     case HOLD:
  51.       switch (oldKey)
  52.       {
  53.         case '2':
  54.           Serial.print("opcao "); Serial.println("A");
  55.           break;
  56.         case '4':
  57.           Serial.print("opcao "); Serial.println("B");
  58.           break;
  59.         case '6':
  60.           Serial.print("opcao "); Serial.println("C");
  61.           break;
  62.         case '8':
  63.           Serial.print("opcao "); Serial.println("D");
  64.           break;
  65.       }
  66.       break;
  67.  
  68.     case RELEASED:
  69.       oldKey = ' ';
  70.       break;
  71.   }
  72. }
RAW Paste Data