Arduino-GPIO
General Purpose Input/Output (GPIO) library for Arduino
Keypad.h
Go to the documentation of this file.
1 
19 #ifndef KEYPAD_H
20 #define KEYPAD_H
21 
27 template<int PIN, uint16_t DEBOUNCE = 50>
28 class Keypad {
29 public:
33  Keypad(const uint16_t* map = NULL) :
34  m_timestamp(0),
35  m_key(0),
36  m_map(map)
37  {
38  }
39 
45  bool ischanged()
46  {
47  // Check if debounce time limit has elapsed
48  if (millis() - m_timestamp < DEBOUNCE) return (false);
49  m_timestamp = millis();
50 
51  // Read the analog pin and map
52  uint16_t value = analogRead(PIN);
53  uint8_t key = 0;
54  if (m_map == NULL) return (false);
55  while (value < (uint16_t) pgm_read_word(&m_map[key])) key++;
56  if (key == m_key) return (false);
57  m_key = key;
58  return (true);
59  }
60 
65  uint8_t key()
66  __attribute__((always_inline))
67  {
68  return (m_key);
69  }
70 
75  uint16_t timestamp()
76  __attribute__((always_inline))
77  {
78  return (m_timestamp);
79  }
80 
81 protected:
83  uint16_t m_timestamp;
84 
86  uint8_t m_key;
87 
89  const uint16_t* m_map;
90 };
91 
92 #endif
uint16_t m_timestamp
Definition: Keypad.h:83
Keypad(const uint16_t *map=NULL)
Definition: Keypad.h:33
uint8_t key()
Definition: Keypad.h:65
uint8_t m_key
Definition: Keypad.h:86
Definition: Keypad.h:28
const uint16_t * m_map
Definition: Keypad.h:89
bool ischanged()
Definition: Keypad.h:45
uint16_t timestamp()
Definition: Keypad.h:75