Advertisement
Guest User

Untitled

a guest
Jul 8th, 2016
334
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.28 KB | None | 0 0
  1. #include <Keyboard.h>
  2. #include <Keypad.h>
  3.  
  4. const byte ROWS = 4; //four rows
  5. const byte COLS = 4; //three columns
  6. char keys[ROWS][COLS] = {
  7. {'1','2','3','A'},
  8. {'4','5','6','B'},
  9. {'7','8','9','C'},
  10. {'*','0','#','D'}
  11. };
  12. byte rowPins[ROWS] = {13,12,11,10}; //connect to the row pinouts of the keypad
  13. byte colPins[COLS] = {9, 8, 7, 6}; //connect to the column pinouts of the keypad
  14.  
  15. Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
  16.  
  17. bool lightsOn = false;
  18.  
  19. void setup(){
  20. Serial.begin(9600);
  21. Keyboard.begin();
  22. }
  23.  
  24. void loop(){
  25. char key = keypad.getKey();
  26. if (key != NO_KEY){
  27. if (key == 'A') {
  28. if (lightsOn) {
  29. lightsOn = false;
  30. Keyboard.print('J');
  31. } else {
  32. lightsOn = true;
  33. Keyboard.print('J');
  34. delay(200);
  35. Keyboard.print('J');
  36. delay(200);
  37. Keyboard.print('J');
  38. delay(200);
  39. Keyboard.print('K');
  40. delay(200);
  41. Keyboard.print('L');
  42. }
  43. } else if (key == 'B') {
  44. Keyboard.press('G');
  45. delay(200);
  46. Keyboard.release('G');
  47. } else if (key == 'C') {
  48. Keyboard.print('K');
  49. } else if (key == 'D') {
  50. Keyboard.print('L');
  51. } else if (key == '*') {
  52. lightsOn = false;
  53. }
  54. }
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement