Skip to content

Commit 695c60b

Browse files
committed
0.2.0 AnalogKeypad
1 parent 5461be5 commit 695c60b

File tree

9 files changed

+89
-60
lines changed

9 files changed

+89
-60
lines changed

libraries/AnalogKeypad/.arduino-ci.yml

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@ compile:
22
# Choosing to run compilation tests on 2 different Arduino platforms
33
platforms:
44
- uno
5-
- leonardo
6-
- due
7-
- zero
5+
# - due
6+
# - zero
7+
# - leonardo
8+
- m4
9+
- esp32
10+
# - esp8266
11+
# - mega2560

libraries/AnalogKeypad/.github/workflows/arduino_test_runner.yml

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,14 @@ name: Arduino CI
44
on: [push, pull_request]
55

66
jobs:
7-
arduino_ci:
7+
runTest:
88
runs-on: ubuntu-latest
99

1010
steps:
1111
- uses: actions/checkout@v2
12-
- uses: Arduino-CI/action@master
13-
# Arduino-CI/[email protected]
12+
- uses: ruby/setup-ruby@v1
13+
with:
14+
ruby-version: 2.6
15+
- run: |
16+
gem install arduino_ci
17+
arduino_ci.rb

libraries/AnalogKeypad/AnalogKeypad.cpp

Lines changed: 27 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,49 @@
11
//
22
// FILE: AnalogKeypad.cpp
33
// AUTHOR: Rob Tillaart
4-
// VERSION: 0.1.6
4+
// VERSION: 0.2.0
55
// DATE: 2019-01-31
66
// PURPOSE: Class for (Robotdyn) 4x4 and 4x3 analog keypad
77
//
8-
// HISTORY:
9-
// 0.1.0 2019-01-31 initial version
10-
// 0.1.1 2019-02-01 add pressed() event() last()
11-
// 0.1.2 2019-02-01 refactored rawRead(), first stable version
12-
// 0.1.3 2020-03-25 minor refactoring
13-
// 0.1.4 2020-05-27 update library.json
14-
// 0.1.5 2020-12-09 add arduino-ci
15-
// 0.1.6 2021-05-27 fix arduino-lint
8+
// HISTORY:
9+
// 0.1.0 2019-01-31 initial version
10+
// 0.1.1 2019-02-01 add pressed() event() last()
11+
// 0.1.2 2019-02-01 refactored rawRead(), first stable version
12+
// 0.1.3 2020-03-25 minor refactoring
13+
// 0.1.4 2020-05-27 update library.json
14+
// 0.1.5 2020-12-09 add arduino-ci
15+
// 0.1.6 2021-05-27 fix arduino-lint
16+
// 0.2.0 2021-10-17 update build-ci, readme,
17+
// add bits as parameter in constructor.
1618

1719

1820
#include "AnalogKeypad.h"
1921

2022

2123
// NOTE the MAGIC NUMBERS in rawRead() are for 8 BIT ADC
22-
// (8 bit compares are fast)
24+
// as 8 bit compares are fast
2325
//
24-
// The AKP_SHIFT takes care if the ADC generates more
25-
// than e.g. 10 bits. Change AKP_BITS to match your
26-
// build in ADC.
26+
// The _analogShift takes care if the ADC has more
27+
// than e.g. 10 bits.
2728
//
28-
// Arduino UNO3 build in ==> 10 BITS
29-
// so AKP_SHIFT ==> 2
30-
//
31-
#define AKP_BITS 10
32-
#define AKP_SHIFT (AKP_BITS - 8)
29+
// Arduino UNO3 build in ==> 10 bits
30+
// Other may have 12 or even 16 bits.
3331

3432

35-
AnalogKeypad::AnalogKeypad(const uint8_t pin)
33+
AnalogKeypad::AnalogKeypad(const uint8_t pin, const uint8_t bits)
3634
{
37-
_pin = pin;
38-
_lastKey = NOKEY;
35+
_analogPin = pin;
36+
_analogShift = bits - 8;
37+
_lastKey = NOKEY;
3938
}
4039

4140

4241
uint8_t AnalogKeypad::event()
4342
{
4443
int rv = NOKEY;
45-
uint8_t _key = rawRead();
44+
uint8_t _key = _rawRead();
4645

47-
if (_key == 0 && _lastKey == 0) rv = NOKEY;
46+
if (_key == 0 && _lastKey == 0) rv = NOKEY;
4847
else if (_key != 0 && _lastKey == 0) rv = PRESSED;
4948
else if (_key == 0 && _lastKey != 0) rv = RELEASED;
5049
else if (_key != 0 && _lastKey != 0 && _key == _lastKey) rv = REPEATED;
@@ -60,7 +59,7 @@ uint8_t AnalogKeypad::pressed()
6059
{
6160
int rv = NOKEY;
6261

63-
uint8_t _key = rawRead();
62+
uint8_t _key = _rawRead();
6463
if (_key == _lastKey) // NOKEY OR REPEAT
6564
{
6665
rv = _lastKey;
@@ -86,16 +85,16 @@ uint8_t AnalogKeypad::pressed()
8685

8786
uint8_t AnalogKeypad::read()
8887
{
89-
_lastKey = rawRead();
88+
_lastKey = _rawRead();
9089
return _lastKey;
9190
}
9291

9392

9493
// Adjust numbers for other than 4x4 keypad
95-
uint8_t AnalogKeypad::rawRead()
94+
uint8_t AnalogKeypad::_rawRead()
9695
{
97-
// spends most time in analogRead (uno ~110 usec)
98-
uint8_t val = analogRead(_pin) >> AKP_SHIFT;
96+
// spends most time in analogRead (UNO ~110 microseconds)
97+
uint8_t val = (analogRead(_analogPin) >> _analogShift);
9998

10099
// handle NOKEY first
101100
if (val < 57) return 0;

libraries/AnalogKeypad/AnalogKeypad.h

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,17 @@
22
//
33
// FILE: AnalogKeypad.h
44
// AUTHOR: Rob Tillaart
5-
// VERSION: 0.1.6
5+
// VERSION: 0.2.0
66
// DATE: 2019-01-31
7-
// PURPOSE: Class for (Robotdyn) 4x4 and 4x3 analog keypad
7+
// PURPOSE: Class for (Robotdyn) 4x4 and 4x3 analogue keypad
88
// URL: https://github.com/RobTillaart/AnalogKeypad
99
//
1010

1111

1212
#include "Arduino.h"
1313

1414

15-
#define ANALOGKEYPAD_LIB_VERSION "0.1.6"
15+
#define ANALOGKEYPAD_LIB_VERSION (F("0.2.0"))
1616

1717
#define NOKEY 0x00
1818
#define PRESSED 0x80
@@ -24,7 +24,7 @@
2424
class AnalogKeypad
2525
{
2626
public:
27-
explicit AnalogKeypad(const uint8_t pin);
27+
explicit AnalogKeypad(const uint8_t pin, const uint8_t bits = 10);
2828

2929
// returns 0 if no key pressed
3030
// otherwise returns key pressed first => ignoring fluctuations
@@ -36,13 +36,14 @@ class AnalogKeypad
3636
uint8_t read();
3737

3838
// event alike approach
39-
// switch(int e = event())
39+
// switch(int e = event()) see examples
4040
uint8_t event();
4141
uint8_t key() { return _lastKey; } ;
4242

4343
private:
44-
uint8_t rawRead();
45-
uint8_t _pin;
44+
uint8_t _rawRead();
45+
uint8_t _analogPin;
46+
uint8_t _analogShift;
4647
uint8_t _lastKey;
4748
};
4849

libraries/AnalogKeypad/README.md

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,51 @@
11

22
[![Arduino CI](https://github.com/RobTillaart/AnalogKeypad/workflows/Arduino%20CI/badge.svg)](https://github.com/marketplace/actions/arduino_ci)
3+
34
[![License: MIT](https://img.shields.io/badge/license-MIT-green.svg)](https://github.com/RobTillaart/AnalogKeypad/blob/master/LICENSE)
45
[![GitHub release](https://img.shields.io/github/release/RobTillaart/AnalogKeypad.svg?maxAge=3600)](https://github.com/RobTillaart/AnalogKeypad/releases)
56

7+
68
# AnalogKeypad
79

810
Library for (Robotdyn) 4x4 and 4x3 analog keypad
911

12+
1013
## Description
1114

1215
AnalogKeypad is a simple library to read the keys from a (robotdyn) 4x4 or 4x3 keypad.
1316
No other keypads are tested, but they should work with this library after adjusting
1417
the **MAGIC NUMBERS** in the function **rawRead()**.
1518

19+
1620
## Interface
1721

22+
1823
### Constructor
1924

20-
- **AnalogKeypad(pin)** constructor, pin is typical A0 etc
25+
- **AnalogKeypad(const uint8_t pin, const uint8_t bits = 10)** constructor, pin is typical A0 etc
26+
Bits has a default of 10, but need to be set to match the platform.
27+
2128

2229
### polling interface
2330

24-
- **pressed()** returns 0 if no key pressed, otherwise returns key pressed (may fluctuate)
25-
- **read()** read the key pressed returns 0..16
31+
- **uint8_t pressed()** returns 0 if no key pressed, otherwise returns key pressed (may fluctuate)
32+
- **uint8_t read()** read the key pressed returns 0..16
33+
2634

2735
### event interface
2836

29-
- **event()** checks if a change has occurred since last time.
30-
- **key()** returns the key involved with last event
37+
- **uint8_t event()** checks if a change has occurred since last time.
38+
- **uint8_t key()** returns the key involved with last event
3139

3240
Switch(int e = event())
3341

34-
| Event | value |
35-
|:----:|:----:|
36-
| PRESSED | 0x80 |
37-
| RELEASED | 0x40 |
38-
| REPEATED | 0x20 |
39-
| CHANGED | 0x10 |
40-
| NOKEY | 0x00 |
42+
| Event | value |
43+
|:--------:|:-----:|
44+
| PRESSED | 0x80 |
45+
| RELEASED | 0x40 |
46+
| REPEATED | 0x20 |
47+
| CHANGED | 0x10 |
48+
| NOKEY | 0x00 |
4149

4250

4351
## Operation
@@ -53,3 +61,9 @@ are less likely to disturbe your program.
5361

5462
See Examples
5563

64+
## Future
65+
66+
- more examples
67+
- self-learning example?
68+
69+

libraries/AnalogKeypad/examples/analogKeypad/analogKeypad.ino

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,28 @@
11
//
22
// FILE: analogKeypad.ino
33
// AUTHOR: Rob Tillaart
4-
// VERSION: 0.0.1
5-
// PURPOSE:
4+
// PURPOSE: demo 4x4 analogue keypad
65
//
7-
// HISTORY:
86
// https://www.tinytronics.nl/shop/nl/arduino/accessoires/robotdyn-keypad-4x4-matrix-analoog?search=matrix
97
//
108

9+
1110
#include "AnalogKeypad.h"
1211

1312
AnalogKeypad AKP(A0);
1413
uint32_t start, stop;
1514

15+
1616
void setup()
1717
{
1818
Serial.begin(115200);
1919
Serial.println(__FILE__);
2020
Serial.print("ANALOGKEYPAD_LIB_VERSION:\t");
2121
Serial.println(ANALOGKEYPAD_LIB_VERSION);
2222

23+
Serial.println();
24+
test3();
25+
2326
for (int i = 0; i < 100; i++) test1();
2427
for (int i = 0; i < 100; i++) test2();
2528
}
@@ -28,6 +31,7 @@ void loop()
2831
{
2932
}
3033

34+
3135
//
3236
void test1()
3337
{
@@ -40,6 +44,7 @@ void test1()
4044
delay(100);
4145
}
4246

47+
4348
// use the "event" interface
4449
void test2()
4550
{
@@ -79,3 +84,5 @@ void test3()
7984
Serial.println(button);
8085
delay(100);
8186
}
87+
88+
// -- END OF FILE --

libraries/AnalogKeypad/keywords.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
# Syntax Coloring Map For AnalogKeypad
1+
# Syntax Colouring Map For AnalogKeypad
22

3-
# Datatypes (KEYWORD1)
3+
# Data types (KEYWORD1)
44
AnalogKeypad KEYWORD1
55

66

libraries/AnalogKeypad/library.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
"type": "git",
1616
"url": "https://github.com/RobTillaart/AnalogKeypad"
1717
},
18-
"version": "0.1.6",
18+
"version": "0.2.0",
1919
"license": "MIT",
2020
"frameworks": "arduino",
2121
"platforms": "*"

libraries/AnalogKeypad/library.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name=AnalogKeypad
2-
version=0.1.6
2+
version=0.2.0
33
author=Rob Tillaart <[email protected]>
44
maintainer=Rob Tillaart <[email protected]>
55
sentence=Arduino Library for (Robotdyn) 4x4 and 4x3 AnalogKeypad

0 commit comments

Comments
 (0)