0.2.2 AnalogKeypad

This commit is contained in:
rob tillaart 2022-10-27 17:49:36 +02:00
parent edc6ff45c9
commit 5a23134dbd
8 changed files with 90 additions and 43 deletions

View File

@ -1,3 +1,18 @@
platforms:
rpipico:
board: rp2040:rp2040:rpipico
package: rp2040:rp2040
gcc:
features:
defines:
- ARDUINO_ARCH_RP2040
warnings:
flags:
packages:
rp2040:rp2040:
url: https://github.com/earlephilhower/arduino-pico/releases/download/global/package_rp2040_index.json
compile:
# Choosing to run compilation tests on 2 different Arduino platforms
platforms:
@ -8,4 +23,6 @@ compile:
- m4
- esp32
# - esp8266
# - mega2560
# - mega2560
- rpipico

View File

@ -1,35 +1,24 @@
//
// FILE: AnalogKeypad.cpp
// AUTHOR: Rob Tillaart
// VERSION: 0.2.1
// VERSION: 0.2.2
// DATE: 2019-01-31
// PURPOSE: Class for (Robotdyn) 4x4 and 4x3 analog keypad
//
// HISTORY:
// 0.1.0 2019-01-31 initial version
// 0.1.1 2019-02-01 add pressed() event() last()
// 0.1.2 2019-02-01 refactored rawRead(), first stable version
// 0.1.3 2020-03-25 minor refactoring
// 0.1.4 2020-05-27 update library.json
// 0.1.5 2020-12-09 add Arduino-CI
// 0.1.6 2021-05-27 fix Arduino-lint
// 0.2.0 2021-10-17 update build-CI, readme,
// add bits as parameter in constructor.
// 0.2.1 2021-12-12 update library.json, license
// add test_constants to unit test.
// HISTORY: see changelog.md
#include "AnalogKeypad.h"
// NOTE the MAGIC NUMBERS in rawRead() are for 8 BIT ADC
// as 8 bit compares are fast
// NOTE the MAGIC NUMBERS in rawRead() are for 8 BIT ADC
// as 8 bit compares are fast
//
// The _analogShift takes care if the ADC has more
// than e.g. 10 bits.
// The _analogShift takes care if the ADC has more
// than e.g. 10 bits.
//
// Arduino UNO3 build in ==> 10 bits
// Other may have 12 or even 16 bits.
// Arduino UNO3 build in ==> 10 bits
// Other may have 12 or even 16 bits.
AnalogKeypad::AnalogKeypad(const uint8_t pin, const uint8_t bits)
@ -92,16 +81,16 @@ uint8_t AnalogKeypad::read()
}
// Adjust numbers for other than 4x4 keypad
// Adjust numbers for other than 4x4 keypad
uint8_t AnalogKeypad::_rawRead()
{
// spends most time in analogRead (UNO ~110 microseconds)
// spends most time in analogRead (UNO ~110 microseconds)
uint8_t val = (analogRead(_analogPin) >> _analogShift);
// handle NOKEY first
// handle NOKEY first
if (val < 57) return 0;
// reduce average # compares by 2 (4x4 keypad)
// reduce average # compares by 2 (4x4 keypad)
if (val < 135)
{
if (val < 62) return 16;

View File

@ -2,7 +2,7 @@
//
// FILE: AnalogKeypad.h
// AUTHOR: Rob Tillaart
// VERSION: 0.2.1
// VERSION: 0.2.2
// DATE: 2019-01-31
// PURPOSE: Class for (Robotdyn) 4x4 and 4x3 analogue keypad
// URL: https://github.com/RobTillaart/AnalogKeypad
@ -12,13 +12,13 @@
#include "Arduino.h"
#define ANALOGKEYPAD_LIB_VERSION (F("0.2.1"))
#define ANALOGKEYPAD_LIB_VERSION (F("0.2.2"))
#define NOKEY 0x00
#define PRESSED 0x80
#define RELEASED 0x40
#define REPEATED 0x20
#define CHANGED 0x10
#define NOKEY 0x00
#define PRESSED 0x80
#define RELEASED 0x40
#define REPEATED 0x20
#define CHANGED 0x10
class AnalogKeypad
@ -26,17 +26,17 @@ class AnalogKeypad
public:
explicit AnalogKeypad(const uint8_t pin, const uint8_t bits = 10);
// returns 0 if no key pressed
// otherwise returns key pressed first => ignoring fluctuations
// 2nd or more presses simultaneous are ignored
// 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)
// returns 0 if no key pressed
// otherwise returns key pressed (may fluctuate)
uint8_t read();
// event alike approach
// switch(int e = event()) see examples
// event alike approach
// switch(int e = event()) see examples
uint8_t event();
uint8_t key() { return _lastKey; } ;

View File

@ -0,0 +1,42 @@
# Change Log analogKeypad
All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).
## [0.2.2] - 2022-10-27
- Add RP2040 support to build-CI.
- Add CHANGELOG.md
## [0.2.1] - 2021-12-12
- update library.json, license
- add test_constants to unit test.
## [0.2.0] - 2021-10-17
- update build-CI, readme,
- add bits as parameter in constructor.
----
## [0.1.6] - 2021-05-27
- fix Arduino-lint
## [0.1.5] - 2020-12-09
- add Arduino-CI
## [0.1.4] - 2020-05-27
- update library.json
## [0.1.3] - 2020-03-25
- minor refactoring
## [0.1.2] - 2019-02-01
- refactored rawRead(), first stable version
## [0.1.1] - 2019-02-01
- add pressed() event() last()
## [0.1.0] - 2019-01-31
- initial version

View File

@ -58,7 +58,7 @@ 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.
It returns the key pressed first, so multiple key presses simultaniously
It returns the key pressed first, so multiple key presses simultaneously
are less likely to disturb your program.
See Examples

View File

@ -15,7 +15,7 @@
"type": "git",
"url": "https://github.com/RobTillaart/AnalogKeypad"
},
"version": "0.2.1",
"version": "0.2.2",
"license": "MIT",
"frameworks": "arduino",
"platforms": "*",

View File

@ -1,5 +1,5 @@
name=AnalogKeypad
version=0.2.1
version=0.2.2
author=Rob Tillaart <rob.tillaart@gmail.com>
maintainer=Rob Tillaart <rob.tillaart@gmail.com>
sentence=Arduino Library for (Robotdyn) 4x4 and 4x3 AnalogKeypad

View File

@ -27,6 +27,7 @@
unittest_setup()
{
fprintf(stderr, "ANALOGKEYPAD_LIB_VERSION: %s\n", (char *) ANALOGKEYPAD_LIB_VERSION);
}
unittest_teardown()
@ -36,8 +37,6 @@ unittest_teardown()
unittest(test_constants)
{
fprintf(stderr, "ANALOGKEYPAD_LIB_VERSION: %s\n", (char *) ANALOGKEYPAD_LIB_VERSION);
assertEqual(0x00, NOKEY );
assertEqual(0x80, PRESSED );
assertEqual(0x40, RELEASED);