2020-11-27 05:10:47 -05:00
|
|
|
#pragma once
|
2019-02-01 09:18:01 -05:00
|
|
|
//
|
|
|
|
// FILE: AnalogKeypad.h
|
|
|
|
// AUTHOR: Rob Tillaart
|
2020-11-27 05:10:47 -05:00
|
|
|
// VERSION: 0.1.4
|
2019-02-01 09:18:01 -05:00
|
|
|
// DATE: 2019-01-31
|
2020-11-27 05:10:47 -05:00
|
|
|
// PURPOSE: Class for (Robotdyn) 4x4 and 4x3 analog keypad
|
|
|
|
// URL: https://github.com/RobTillaart/AnalogKeypad
|
2019-02-01 09:18:01 -05:00
|
|
|
//
|
|
|
|
|
|
|
|
#include "Arduino.h"
|
|
|
|
|
2020-11-27 05:10:47 -05:00
|
|
|
#define ANALOGKEYPAD_LIB_VERSION "0.1.4"
|
2019-02-01 09:18:01 -05:00
|
|
|
|
|
|
|
#define NOKEY 0x00
|
|
|
|
#define PRESSED 0x80
|
|
|
|
#define RELEASED 0x40
|
|
|
|
#define REPEATED 0x20
|
|
|
|
#define CHANGED 0x10
|
|
|
|
|
|
|
|
class AnalogKeypad
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
explicit AnalogKeypad(const uint8_t pin);
|
|
|
|
|
|
|
|
// returns 0 if no key pressed
|
|
|
|
// otherwise returns key pressed first => ignoring fluctuations
|
|
|
|
// 2nd or more presses simultaneous are ignored
|
|
|
|
uint8_t pressed();
|
|
|
|
|
|
|
|
// returns 0 if no key pressed
|
|
|
|
// otherwise returns key pressed (may fluctuate)
|
|
|
|
uint8_t read();
|
|
|
|
|
|
|
|
|
|
|
|
// event alike approach
|
|
|
|
// switch(int e = event())
|
|
|
|
uint8_t event();
|
|
|
|
uint8_t key() { return _lastKey; } ;
|
|
|
|
|
|
|
|
private:
|
|
|
|
uint8_t rawRead();
|
|
|
|
uint8_t _pin;
|
|
|
|
uint8_t _lastKey;
|
|
|
|
};
|
|
|
|
|
2020-11-27 05:10:47 -05:00
|
|
|
// -- END OF FILE --
|