Papermind

Keypad multi String

Mar 18th, 2018
4,394
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.05 KB | None | 0 0
  1. /* Input Multi keypad
  2. Created by
  3. papermindvention.blogspot.com
  4. 19 March 2018 */
  5.  
  6. #include <Keypad.h>
  7.  
  8. String inString="";
  9. const byte ROWS = 4;
  10. const byte COLS = 4;
  11. char keys[ROWS][COLS] = {
  12.   {'1','4','7','*'},
  13.   {'2','5','8','0'},
  14.   {'3','6','9','#'},
  15.   {'A','B','C','D'} };
  16. byte rowPins[ROWS] = {5, 4, 3, 2}; //connect to the row pinouts of the keypad
  17. byte colPins[COLS] = {9, 8, 7, 6}; //connect to the column pinouts of the keypad
  18. Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
  19.  
  20. void setup(){ Serial.begin(9600); }
  21.  
  22. void loop(){
  23.   char inChar = keypad.getKey();
  24.   if (inChar){
  25.     /* periksa apakah nilai yang diinputkan berupa angka */
  26.   if (isDigit(inChar)) {  inString += inChar;  }
  27.     /*periksa apakah nilai yang diinputkan berupa huruf Alphabet */
  28.   if (isAlpha(inChar)) {  inString += inChar;  }
  29.     /* jika tombol * ditekan, maka tampilkan nilai yang diinputkan. */
  30.     if (inChar == '*') {  
  31.       Serial.print("nilai yang anda memasukkan :");
  32.       Serial.println(inString);
  33.       inString = "";
  34.   }
  35. }
  36. }
Advertisement
Add Comment
Please, Sign In to add comment