GY-63_MS5611/libraries/AnalogKeypad/README.md

119 lines
3.1 KiB
Markdown
Raw Normal View History

2021-01-29 06:31:58 -05:00
[![Arduino CI](https://github.com/RobTillaart/AnalogKeypad/workflows/Arduino%20CI/badge.svg)](https://github.com/marketplace/actions/arduino_ci)
2021-12-12 09:08:09 -05:00
[![Arduino-lint](https://github.com/RobTillaart/AnalogKeypad/actions/workflows/arduino-lint.yml/badge.svg)](https://github.com/RobTillaart/AnalogKeypad/actions/workflows/arduino-lint.yml)
[![JSON check](https://github.com/RobTillaart/AnalogKeypad/actions/workflows/jsoncheck.yml/badge.svg)](https://github.com/RobTillaart/AnalogKeypad/actions/workflows/jsoncheck.yml)
2021-01-29 06:31:58 -05:00
[![License: MIT](https://img.shields.io/badge/license-MIT-green.svg)](https://github.com/RobTillaart/AnalogKeypad/blob/master/LICENSE)
[![GitHub release](https://img.shields.io/github/release/RobTillaart/AnalogKeypad.svg?maxAge=3600)](https://github.com/RobTillaart/AnalogKeypad/releases)
2021-10-17 11:47:04 -04:00
2020-11-27 05:10:47 -05:00
# AnalogKeypad
2021-12-12 09:08:09 -05:00
Library for (Robotdyn) 4x4 and 4x3 analog keypad.
2020-11-27 05:10:47 -05:00
2021-10-17 11:47:04 -04:00
2020-11-27 05:10:47 -05:00
## Description
2021-01-29 06:31:58 -05:00
2021-12-12 09:08:09 -05:00
AnalogKeypad is a simple library to read the keys from a (Robotdyn) 4x4 or 4x3 keypad.
2020-11-27 05:10:47 -05:00
No other keypads are tested, but they should work with this library after adjusting
the **MAGIC NUMBERS** in the function **rawRead()**.
2021-10-17 11:47:04 -04:00
2023-01-22 05:41:01 -05:00
#### Related
- https://github.com/RobTillaart/I2CKeyPad
- https://github.com/RobTillaart/I2CKeyPad8x8
2021-01-29 06:31:58 -05:00
## Interface
2023-01-22 05:41:01 -05:00
```cpp
#include "AnalogKeypad.h"
```
2021-10-17 11:47:04 -04:00
2023-01-22 05:41:01 -05:00
#### Constructor
2021-01-29 06:31:58 -05:00
2021-12-12 09:08:09 -05:00
- **AnalogKeypad(const uint8_t pin, const uint8_t bits = 10)** constructor, pin is typical A0 etc.
2021-10-17 11:47:04 -04:00
Bits has a default of 10, but need to be set to match the platform.
2021-12-12 09:08:09 -05:00
If bits < 8 then the internal shift would be large causing all reads to return 0 or so.
2021-10-17 11:47:04 -04:00
2021-01-29 06:31:58 -05:00
2023-01-22 05:41:01 -05:00
#### polling interface
2021-01-29 06:31:58 -05:00
2021-12-12 09:08:09 -05:00
- **uint8_t pressed()** returns 0 if no key pressed, otherwise returns key pressed (may fluctuate).
- **uint8_t read()** read the key pressed returns 0 .. 16 where 0 means NOKEY.
2021-10-17 11:47:04 -04:00
2021-01-29 06:31:58 -05:00
2023-01-22 05:41:01 -05:00
#### event interface
2021-01-29 06:31:58 -05:00
2021-10-17 11:47:04 -04:00
- **uint8_t event()** checks if a change has occurred since last time.
2021-12-12 09:08:09 -05:00
- **uint8_t key()** returns the key involved with last event.
2021-01-29 06:31:58 -05:00
2023-01-22 05:41:01 -05:00
```cpp
uint8_t e = AKP.event();
switch (e)
{
case PRESSED:
Serial.print("press\t");
Serial.println(AKP.key());
break;
case RELEASED:
Serial.print("release\t");
Serial.println(AKP.key());
break;
case REPEATED:
Serial.print("repeat\t");
Serial.println(AKP.key());
break;
case CHANGED:
Serial.print("change\t");
Serial.println(AKP.key());
break;
default: // NOKEY
break;
}
```
| Event | value |
|:----------:|:-------:|
| PRESSED | 0x80 |
| RELEASED | 0x40 |
| REPEATED | 0x20 |
| CHANGED | 0x10 |
| NOKEY | 0x00 |
2021-01-29 06:31:58 -05:00
2020-11-27 05:10:47 -05:00
## Operation
2021-01-29 06:31:58 -05:00
2023-01-22 05:41:01 -05:00
The simplest usage is to use the **read()** function.
2020-11-27 05:10:47 -05:00
This will return a 0 (NOKEY) when no key is pressed and
a number 1 to 16 for the keys pressed. Note the return value may
fluctuate randomly when multiple keys are pressed.
The **pressed()** function is a bit more robust.
2023-01-22 05:41:01 -05:00
It returns the key pressed first, so multiple key presses simultaneously
2021-12-12 09:08:09 -05:00
are less likely to disturb your program.
2020-11-27 05:10:47 -05:00
2021-01-29 06:31:58 -05:00
See Examples
2020-11-27 05:10:47 -05:00
2021-12-12 09:08:09 -05:00
2021-10-17 11:47:04 -04:00
## Future
2023-01-22 05:41:01 -05:00
#### Must
#### Should
2021-10-17 11:47:04 -04:00
- more examples
2023-01-22 05:41:01 -05:00
- self-learning example?
#### Could
2021-12-12 09:08:09 -05:00
- make internal mapping array runtime adaptable?
- store in RAM, accessor functions
2023-01-22 05:41:01 -05:00
- version for external ADC
- see ADC712
#### Wont
2021-10-17 11:47:04 -04:00