Skip to content

Commit 7f06f8a

Browse files
committed
_debounceTime typo fix and few edits
1 parent 2b237a4 commit 7f06f8a

File tree

3 files changed

+31
-30
lines changed

3 files changed

+31
-30
lines changed

library.properties

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
name=Bugtton
2-
version=1.0.2
2+
version=1.0.3
33
author=Sami Kaukasalo <sami.kaukasalo@puimurigames.fi>
44
maintainer=Sami Kaukasalo <sami.kaukasalo@puimurigames.fi>
55
sentence=Fast button debounce library for ATmega328P. Uses registers instead of digitalRead.
6-
paragraph=Cycle speed 0.003ms unpressed, 0.010-0.085ms pressed (1-18 buttons).
6+
paragraph=It's fast and I want it faster.
77
category=Signal Input/Output
88
url=https://github.com/sakabug/Bugtton
9-
architectures=avr
9+
architectures=avr

src/Bugtton.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,9 @@ Bugtton::Bugtton(const uint8_t a, const uint8_t *b, uint8_t mode, uint8_t dt){
4343

4444
// Create buttons (was first separate classes, but this is the way I went)
4545
_pins = new uint8_t[_count];
46-
_bits = new byte[_count];
47-
_stateStarted = new unsigned long[_count];
48-
_ticksStarted = new unsigned long[_count];
46+
_bits = new uint8_t[_count];
47+
_stateStarted = new uint32_t[_count];
48+
_ticksStarted = new uint32_t[_count];
4949
// Init button data
5050
for(uint8_t i=0; i<_count; i++){
5151
setMode(b[i], mode);
@@ -69,7 +69,7 @@ void Bugtton::makeMasks(){
6969
}
7070

7171
// For debugging purposes
72-
void Bugtton::printBIN(byte b){
72+
void Bugtton::printBIN(uint8_t b){
7373
for(int i = 7; i >= 0; i--)
7474
Serial.print(bitRead(b,i));
7575
Serial.println();
@@ -146,9 +146,9 @@ void Bugtton::tickBit(uint8_t i, bool a) { bitWrite(_bits[i], 2, a); }
146146
bool Bugtton::tickBit(uint8_t i) { return bitRead(_bits[i], 2); }
147147

148148
// Timestamps for debounce, and duration function
149-
void Bugtton::stateStarted(uint8_t i, unsigned long a){ _stateStarted[i] = a; }
150-
unsigned long Bugtton::stateStarted(uint8_t i) { return _stateStarted[i]; }
151-
unsigned long Bugtton::duration(uint8_t i) { return millis() - _stateStarted[i]; }
149+
void Bugtton::stateStarted(uint8_t i, uint32_t a){ _stateStarted[i] = a; }
150+
uint32_t Bugtton::stateStarted(uint8_t i) { return _stateStarted[i]; }
151+
uint32_t Bugtton::duration(uint8_t i) { return millis() - _stateStarted[i]; }
152152

153153
// Set pin mode here
154154
void Bugtton::setMode(uint8_t i, uint8_t mode){
@@ -213,7 +213,7 @@ bool Bugtton::held(uint8_t i){
213213
}
214214

215215
// Returns true once when <time> ms reached while button pressed state
216-
bool Bugtton::heldUntil(uint8_t i, int t){
216+
bool Bugtton::heldUntil(uint8_t i, uint16_t t){
217217
//printBIN(_bits[i]);
218218
if ( (_bits[i]&B11111000) == B01000000 && duration(i) >= t) {
219219
bitWrite(_bits[i], 3, 1);
@@ -223,7 +223,7 @@ bool Bugtton::heldUntil(uint8_t i, int t){
223223
}
224224

225225
// Returns true once when <time> ms reached while button unpressed state
226-
bool Bugtton::upUntil(uint8_t i, int t){
226+
bool Bugtton::upUntil(uint8_t i, uint16_t t){
227227
if ( (_bits[i]&B11111000) == B11100000 && duration(i) >= t) {
228228
bitWrite(_bits[i], 3, 1);
229229
return true;
@@ -232,7 +232,7 @@ bool Bugtton::upUntil(uint8_t i, int t){
232232
}
233233

234234
// Returns true once every <time> ms
235-
bool Bugtton::intervalTick(uint8_t i, unsigned long t){
235+
bool Bugtton::intervalTick(uint8_t i, uint32_t t){
236236
if ( (_bits[i]&B11110000) == B01000000){
237237
if ( (millis() - _ticksStarted[i]) >= t && !tickBit(i) ){
238238
tickBit(i, 1);

src/Bugtton.h

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -38,24 +38,24 @@ class Bugtton {
3838

3939
private:
4040

41-
byte _maskD;
42-
byte _maskB;
43-
byte _maskC;
41+
uint8_t _maskD;
42+
uint8_t _maskB;
43+
uint8_t _maskC;
4444
uint8_t _count;
45-
uint8_t *_debounceTime;
45+
uint8_t _debounceTime;
4646
bool _allStable;
4747
bool _flag1;
4848
bool _allUp;
4949
bool _allUpUsed;
5050

5151
uint8_t *_pins;
52-
byte *_bits;
53-
unsigned long *_stateStarted;
54-
unsigned long *_ticksStarted;
55-
unsigned long _allUpStarted;
52+
uint8_t *_bits;
53+
uint32_t *_stateStarted;
54+
uint32_t *_ticksStarted;
55+
uint32_t _allUpStarted;
5656

5757
void makeMasks();
58-
void printBIN(byte b);
58+
void printBIN(uint8_t b);
5959

6060
void currentBit(uint8_t i, bool a);
6161
bool currentBit(uint8_t i);
@@ -67,10 +67,11 @@ class Bugtton {
6767
bool changedBit(uint8_t i);
6868
void heldUntilUsed(uint8_t i, bool a);
6969
bool heldUntilUsed(uint8_t i);
70-
void stateStarted(uint8_t i, unsigned long a);
71-
unsigned long stateStarted(uint8_t i);
70+
void stateStarted(uint8_t i, uint32_t a);
71+
uint32_t stateStarted(uint8_t i);
7272
void tickBit(uint8_t i, bool a);
7373
bool tickBit(uint8_t i);
74+
7475

7576
public:
7677

@@ -79,14 +80,14 @@ class Bugtton {
7980
void update();
8081

8182
void setMode(uint8_t i, uint8_t mode);
82-
unsigned long duration(uint8_t);
83+
uint32_t duration(uint8_t);
8384
bool fell(uint8_t i);
84-
bool rose(uint8_t i);
85-
bool up(uint8_t i);
85+
bool rose(uint8_t i);
86+
bool up(uint8_t i);
8687
bool held(uint8_t i);
87-
bool heldUntil(uint8_t i, int t);
88-
bool upUntil(uint8_t i, int t);
89-
bool intervalTick(uint8_t i, unsigned long t);
88+
bool heldUntil(uint8_t i, uint16_t t);
89+
bool upUntil(uint8_t i, uint16_t t);
90+
bool intervalTick(uint8_t i, uint32_t t);
9091

9192
};
9293

0 commit comments

Comments
 (0)