Advertisement
computermuseo

keypad 16 tasti arduino

Apr 18th, 2015
2,088
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.05 KB | None | 0 0
  1. #include <Keypad.h>
  2.  
  3. const byte numRows= 4; //number of rows on the keypad
  4. const byte numCols= 4; //number of columns on the keypad
  5.  
  6. //keymap defines the key pressed according to the row and columns just as appears on the keypad
  7. char keymap[numRows][numCols]=
  8. {
  9. {'1', '2', '3', 'A'},
  10. {'4', '5', '6', 'B'},
  11. {'7', '8', '9', 'C'},
  12. {'*', '0', '#', 'D'}
  13. };
  14.  
  15. //Code that shows the the keypad connections to the arduino terminals
  16. byte rowPins[numRows] = {9,8,7,6}; //Rows 0 to 3
  17. byte colPins[numCols]= {5,4,3,2}; //Columns 0 to 3
  18.  
  19. //initializes an instance of the Keypad class
  20. Keypad myKeypad= Keypad(makeKeymap(keymap), rowPins, colPins, numRows, numCols);
  21.  
  22. void setup()
  23. {
  24. Serial.begin(9600);
  25. }
  26.  
  27. //If key is pressed, this key is stored in 'keypressed' variable
  28. //If key is not equal to 'NO_KEY', then this key is printed out
  29. //if count=17, then count is reset back to 0 (this means no key is pressed during the whole keypad scan process
  30. void loop()
  31. {
  32. char keypressed = myKeypad.getKey();
  33. if (keypressed != NO_KEY)
  34. {
  35. Serial.print(keypressed);
  36. }
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement