2020-11-27 05:10:47 -05:00
|
|
|
#pragma once
|
2019-02-01 09:18:01 -05:00
|
|
|
//
|
|
|
|
// FILE: AnalogKeypad.h
|
|
|
|
// AUTHOR: Rob Tillaart
|
2023-01-22 05:41:01 -05:00
|
|
|
// VERSION: 0.2.3
|
2019-02-01 09:18:01 -05:00
|
|
|
// DATE: 2019-01-31
|
2021-10-17 11:47:04 -04:00
|
|
|
// PURPOSE: Class for (Robotdyn) 4x4 and 4x3 analogue keypad
|
2020-11-27 05:10:47 -05:00
|
|
|
// URL: https://github.com/RobTillaart/AnalogKeypad
|
2019-02-01 09:18:01 -05:00
|
|
|
|
2021-05-28 07:19:00 -04:00
|
|
|
|
2019-02-01 09:18:01 -05:00
|
|
|
#include "Arduino.h"
|
|
|
|
|
2021-05-28 07:19:00 -04:00
|
|
|
|
2023-01-22 05:41:01 -05:00
|
|
|
#define ANALOGKEYPAD_LIB_VERSION (F("0.2.3"))
|
2019-02-01 09:18:01 -05:00
|
|
|
|
2022-10-27 11:49:36 -04:00
|
|
|
#define NOKEY 0x00
|
|
|
|
#define PRESSED 0x80
|
|
|
|
#define RELEASED 0x40
|
|
|
|
#define REPEATED 0x20
|
|
|
|
#define CHANGED 0x10
|
2019-02-01 09:18:01 -05:00
|
|
|
|
2021-05-28 07:19:00 -04:00
|
|
|
|
2019-02-01 09:18:01 -05:00
|
|
|
class AnalogKeypad
|
|
|
|
{
|
|
|
|
public:
|
2021-10-17 11:47:04 -04:00
|
|
|
explicit AnalogKeypad(const uint8_t pin, const uint8_t bits = 10);
|
2019-02-01 09:18:01 -05:00
|
|
|
|
2022-10-27 11:49:36 -04:00
|
|
|
// returns 0 if no key pressed
|
|
|
|
// otherwise returns key pressed first => ignoring fluctuations
|
|
|
|
// 2nd or more presses simultaneous are ignored
|
2019-02-01 09:18:01 -05:00
|
|
|
uint8_t pressed();
|
|
|
|
|
2022-10-27 11:49:36 -04:00
|
|
|
// returns 0 if no key pressed
|
|
|
|
// otherwise returns key pressed (may fluctuate)
|
2019-02-01 09:18:01 -05:00
|
|
|
uint8_t read();
|
|
|
|
|
2022-10-27 11:49:36 -04:00
|
|
|
// event alike approach
|
|
|
|
// switch(int e = event()) see examples
|
2019-02-01 09:18:01 -05:00
|
|
|
uint8_t event();
|
2023-01-22 05:41:01 -05:00
|
|
|
uint8_t key();
|
|
|
|
|
2019-02-01 09:18:01 -05:00
|
|
|
|
|
|
|
private:
|
2021-10-17 11:47:04 -04:00
|
|
|
uint8_t _rawRead();
|
|
|
|
uint8_t _analogPin;
|
|
|
|
uint8_t _analogShift;
|
2019-02-01 09:18:01 -05:00
|
|
|
uint8_t _lastKey;
|
|
|
|
};
|
|
|
|
|
2021-05-28 07:19:00 -04:00
|
|
|
|
2023-01-22 05:41:01 -05:00
|
|
|
// -- END OF FILE --
|
|
|
|
|