@@ -43,9 +43,9 @@ Bugtton::Bugtton(const uint8_t a, const uint8_t *b, uint8_t mode, uint8_t dt){
43
43
44
44
// Create buttons (was first separate classes, but this is the way I went)
45
45
_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];
49
49
// Init button data
50
50
for (uint8_t i=0 ; i<_count; i++){
51
51
setMode (b[i], mode);
@@ -69,7 +69,7 @@ void Bugtton::makeMasks(){
69
69
}
70
70
71
71
// For debugging purposes
72
- void Bugtton::printBIN (byte b){
72
+ void Bugtton::printBIN (uint8_t b){
73
73
for (int i = 7 ; i >= 0 ; i--)
74
74
Serial.print (bitRead (b,i));
75
75
Serial.println ();
@@ -146,9 +146,9 @@ void Bugtton::tickBit(uint8_t i, bool a) { bitWrite(_bits[i], 2, a); }
146
146
bool Bugtton::tickBit (uint8_t i) { return bitRead (_bits[i], 2 ); }
147
147
148
148
// 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]; }
152
152
153
153
// Set pin mode here
154
154
void Bugtton::setMode (uint8_t i, uint8_t mode){
@@ -213,7 +213,7 @@ bool Bugtton::held(uint8_t i){
213
213
}
214
214
215
215
// 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){
217
217
// printBIN(_bits[i]);
218
218
if ( (_bits[i]&B11111000) == B01000000 && duration (i) >= t) {
219
219
bitWrite (_bits[i], 3 , 1 );
@@ -223,7 +223,7 @@ bool Bugtton::heldUntil(uint8_t i, int t){
223
223
}
224
224
225
225
// 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){
227
227
if ( (_bits[i]&B11111000) == B11100000 && duration (i) >= t) {
228
228
bitWrite (_bits[i], 3 , 1 );
229
229
return true ;
@@ -232,7 +232,7 @@ bool Bugtton::upUntil(uint8_t i, int t){
232
232
}
233
233
234
234
// 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){
236
236
if ( (_bits[i]&B11110000) == B01000000){
237
237
if ( (millis () - _ticksStarted[i]) >= t && !tickBit (i) ){
238
238
tickBit (i, 1 );
0 commit comments