1
1
## Bugtton
2
- Fast button debounce library for ATmega328P, uses registers.
3
-
4
- ### Why another button library?
5
- I've tried plenty of different button libraries with ATmega328P, but most of them lacked something, or were too bulky for my own use.
6
-
7
- ### Fast
8
- It uses registers, and it's fast. 1000 cycles with various button amounts gave following:
9
-
10
- * Unpressed buttons 0.003 ms per cycle regardless button count.
11
- * Pressed buttons 0.010 - 0.085 ms per cycle with 1-18 buttons.
2
+ Fast button debounce library for ATmega328P. Uses registers instead of digitalRead.
12
3
13
4
### Usage In nutshell
5
+ Compact to use.
14
6
```
15
7
#include <Bugtton.h>
16
-
17
- const uint8_t buttonCount = 5;
18
- const uint8_t buttonPins[buttonCount] = {2,3,4,5,6};
19
- Bugtton buttons(buttonCount, buttonPins, INPUT_PULLUP, 25);
20
- -
8
+ Bugtton buttons(5, {2,3,4,5,6}, INPUT_PULLUP, 25);
9
+ --
21
10
void loop() {
22
11
buttons.update();
23
12
24
13
if (buttons.fell(0)) //B0 down and debounced
25
14
if (buttons.heldUntil(1,3000)) //B1 has been pressed 3 seconds
26
- -
15
+ --
27
16
```
28
17
29
18
### Usable functions
@@ -40,3 +29,18 @@ Function|Notes
40
29
** ` bool held(button_i) ` ** <br >|* Is button_i pressed?*
41
30
** ` bool heldUntil(button_i, time) ` ** <br >|* Returns true ONCE when button_i have been pressed x time.*
42
31
** ` bool upUntil(button_i, time) ` ** <br >|* Returns true ONCE when button_i have been unpressed x time.*
32
+
33
+ I use long press functionality alot in my codes, so I wanted to add suitable functions for it. Feel free to suggest new ideas.
34
+
35
+ ### Why this library was made
36
+ Idea was to make fast button library when nothing is pressed so it would affect to the cycle time as little as possible.
37
+
38
+ ** Times per one cycle**
39
+ Button amount|unpressed|pressed
40
+ -|-|-
41
+ 1|0.003 ms|0.010 ms
42
+ 2|0.003 ms|0.014 ms
43
+ 3|0.003 ms|0.018 ms
44
+ 5|0.003 ms|0.027 ms
45
+ 10|0.003 ms|0.049 ms
46
+ 18|0.003 ms|0.085 ms
0 commit comments