Advertisement
Guest User

Untitled

a guest
Apr 20th, 2018
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.56 KB | None | 0 0
  1. #include <Keypad.h>
  2.  
  3. const byte ROWS = 4; //four rows
  4. const byte COLS = 4; //three columns
  5. char keys[ROWS][COLS] = {
  6. {'1','2','3','A'},
  7. {'4','5','6','B'},
  8. {'7','8','9','C'},
  9. {'*','0','#','D'}
  10. };
  11. byte rowPins[ROWS] = {9, 8, 7, 6}; //connect to the row pinouts of the keypad
  12. byte colPins[COLS] = {5, 4, 3, 2}; //connect to the column pinouts of the keypad
  13.  
  14. Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
  15. byte heaterPin = 13;
  16.  
  17. boolean blink = false;
  18.  
  19. void setup(){
  20. Serial.begin(9600);
  21. pinMode(heaterPin, OUTPUT); // sets the digital pin as output
  22. digitalWrite(heaterPin, HIGH); // sets the LED on
  23. keypad.addEventListener(keypadEvent); //add an event listener for this keypad
  24. }
  25.  
  26. void loop(){
  27. char key = keypad.getKey();
  28.  
  29. if (key) {
  30. Serial.println(key);
  31. }
  32. if (blink){
  33. digitalWrite(heaterPin,!digitalRead(heaterPin));
  34. delay(100);
  35. }
  36. }
  37.  
  38. //take care of some special events
  39. void keypadEvent(KeypadEvent key){
  40. switch (keypad.getState()){
  41. case PRESSED:
  42. switch (key){
  43. case '#': digitalWrite(heaterPin,!digitalRead(heaterPin)); break;
  44. case '*':
  45. digitalWrite(heaterPin,!digitalRead(heaterPin));
  46. break;
  47. }
  48. break;
  49. case RELEASED:
  50. switch (key){
  51. case '*':
  52. digitalWrite(heaterPin,!digitalRead(heaterPin));
  53. blink = false;
  54. break;
  55. }
  56. break;
  57. case HOLD:
  58. switch (key){
  59. case '*': blink = true; break;
  60. }
  61. break;
  62. }
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement