Skip to content

Commit aaad24a

Browse files
committed
Initial commit.
0 parents  commit aaad24a

File tree

10 files changed

+501
-0
lines changed

10 files changed

+501
-0
lines changed

LICENSE

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2021 caiofrota
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.
22+

README.md

+99
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
![alt text](https://cftechsol.com/wp-content/uploads/2017/12/caiofrota-logo-300x171.png)
2+
3+
[![GitHub issues](https://img.shields.io/github/issues/caiofrota/cf-arduino-lib-pushbutton.svg)](https://github.com/caiofrota/cf-arduino-lib-pushbutton/issues)
4+
[![Fork](https://img.shields.io/github/forks/caiofrota/cf-arduino-lib-pushbutton.svg)](#)
5+
[![Stars](https://img.shields.io/github/stars/caiofrota/cf-arduino-lib-pushbutton.svg)](#)
6+
[![License](https://img.shields.io/github/license/caiofrota/cf-arduino-lib-pushbutton.svg)](#)
7+
[![Total Downloads](https://img.shields.io/github/downloads/caiofrota/cf-arduino-lib-pushbutton/total.svg)](https://github.com/caiofrota/cf-arduino-lib-pushbutton/releases)
8+
[![Slack Chat](https://img.shields.io/badge/chat-slack-green.svg)](https://cftechsol.slack.com)
9+
[![Website](https://img.shields.io/badge/website-cftechsol.com-green.svg)](https://cftechsol.com)
10+
11+
# CF Push Button for Arduino
12+
13+
A library for Arduino that helps interface for Push Buttons.
14+
15+
Version 1.0.0
16+
17+
## Quick Start
18+
19+
### Prerequisites
20+
21+
What things you need to install the software and how to install them
22+
23+
* [Arduino IDE](https://www.arduino.cc/) - Development IDE
24+
25+
### Installing
26+
27+
You can either install through the Arduino Library Manager or checkout the latest changes or a release from GitHub.
28+
29+
#### Checkout from github
30+
31+
- Checkout library to your Arduino libraries folder
32+
33+
### Using
34+
- Schematic
35+
![SCHEME](https://github.com/caiofrota/cf-arduino-lib-pushbutton/blob/main/img/scheme.png)
36+
37+
- Include in your sketch.
38+
```cpp
39+
#include <CFPushButton.h>
40+
```
41+
42+
- Initialize library.
43+
```cpp
44+
#define PIN_PUSH_BUTTON D2
45+
CFPushButton pushButton(PIN_PUSH_BUTTON);
46+
```
47+
48+
- Create a function for OnPressCallback
49+
```cpp
50+
void onPressCallback() {
51+
// Do something...
52+
}
53+
```
54+
55+
- Also in the setup function add
56+
```cpp
57+
void setup() {
58+
// ... YOUR CODE ...
59+
// Define callback.
60+
pushButton..setOnPressCallback(onPressCallback);
61+
62+
// Start push button.
63+
pushButton.begin();
64+
// ... YOUR CODE ...
65+
}
66+
```
67+
68+
- And in your loop function
69+
```cpp
70+
void loop() {
71+
// ... YOUR CODE ...
72+
pushButton.loop();
73+
// ... YOUR CODE ...
74+
}
75+
```
76+
77+
### For more info about usage
78+
79+
- Please read our [Wiki](https://github.com/caiofrota/cf-arduino-lib-pushbutton/wiki).
80+
81+
## Support or Contact
82+
83+
Contact us at [email protected] for questions and we'll help you sort it out.
84+
85+
## Issues
86+
87+
Find a bug or want to request a new feature? Please let us know by [submitting an issue](https://github.com/caiofrota/cf-arduino-lib-pushbutton/issues).
88+
89+
## Contributing
90+
91+
Please read [CONTRIBUTING.md](https://gist.github.com/caiofrota/6e65a17fd3bf100d058cb48dcc780b21) for details on our code of conduct, and the process for submitting pull requests to us.
92+
93+
## Authors
94+
95+
* **Caio Frota** - *Initial work* - [caiofrota](https://github.com/caiofrota) | [CF Technology Solutions](https://cftechsol.com)
96+
97+
## License
98+
99+
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
#include <CFPushButton.h> // CF Push Button.
2+
3+
CFPushButton pushButton(D5); // Push Button.
4+
5+
void setup() {
6+
Serial.begin(9600);
7+
// Button cofig.
8+
//pushButton.setPulledUp(); // Uncomment this line if you have a pulled up push button.
9+
//pushButton.setPulledDown(); // Pulled down is default.
10+
//pushButton.setShortPressTime(3000); // Time that identifies a short press in millis. 3 seconds default.
11+
//pushButton.setLongPressTime(10000); // Time that identifies a long press in millis. 10 seconds default.
12+
13+
// Define callbacks.
14+
pushButton.setOnShortPressReachedCallback(onShortPressReachedCallback);
15+
pushButton.setOnLongPressReachedCallback(onLongPressReachedCallback);
16+
pushButton.setOnPressCallback(onPressCallback);
17+
pushButton.setOnShortPressCallback(onShortPressCallback);
18+
pushButton.setOnLongPressCallback(onLongPressCallback);
19+
20+
// Start button.
21+
pushButton.begin();
22+
}
23+
24+
void loop() {
25+
// Loop button.
26+
pushButton.loop();
27+
}
28+
29+
// ====================
30+
// Callbacks.
31+
// ====================
32+
33+
void onShortPressReachedCallback() {
34+
Serial.println("SHORT time was reached.");
35+
}
36+
37+
void onLongPressReachedCallback() {
38+
Serial.println("LONG time was reached.");
39+
}
40+
41+
void onPressCallback() {
42+
Serial.println("Button was pressed.");
43+
}
44+
45+
void onShortPressCallback() {
46+
Serial.println("Button was SHORT Pressed.");
47+
}
48+
49+
void onLongPressCallback() {
50+
Serial.println("Button was LONG Pressed.");
51+
}

img/scheme.fzz

90.7 KB
Binary file not shown.

img/scheme.png

115 KB
Loading

keywords.txt

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#######################################
2+
# Syntax Coloring Map For CFPushButton
3+
#######################################
4+
5+
#######################################
6+
# Datatypes (KEYWORD1)
7+
#######################################
8+
9+
CFPushButton KEYWORD1
10+
11+
#######################################
12+
# Methods and Functions (KEYWORD2)
13+
#######################################
14+
15+
getState KEYWORD2
16+
isPulledUp KEYWORD2
17+
setPulledUp KEYWORD2
18+
setPulledDown KEYWORD2
19+
getShortPressTime KEYWORD2
20+
setShortPressTime KEYWORD2
21+
getLongPressTime KEYWORD2
22+
setLongPressTime KEYWORD2
23+
setOnShortPressReachedCallback KEYWORD2
24+
setOnLongPressReachedCallback KEYWORD2
25+
setOnPressCallback KEYWORD2
26+
setOnShortPressCallback KEYWORD2
27+
setOnLongPressCallback KEYWORD2
28+
29+
#######################################
30+
# Constants (LITERAL1)
31+
#######################################

library.json

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"name": "CFPushButton",
3+
"keywords": "cf, arduino, cpp, pushbutton, push, button",
4+
"description": "A library for Arduino that helps interface for Push Buttons.",
5+
"repository": {
6+
"type": "git",
7+
"url": "https://github.com/caiofrota/cf-arduino-lib-pushbutton"
8+
},
9+
"authors": [
10+
{
11+
"name": "caiofrota",
12+
"url": "https://github.com/caiofrota"
13+
}
14+
],
15+
"contributors": [
16+
],
17+
"version": "1.0.0",
18+
"examples": "examples/*/*.ino",
19+
"frameworks": "arduino"
20+
}

library.properties

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
name=CFPushButton
2+
version=1.0.0
3+
author=Caio Frota <[email protected]>
4+
maintainer=Caio Frota <[email protected]>
5+
sentence=A library for Arduino that helps interface for Push Buttons.
6+
paragraph=A library for Arduino that helps interface for Push Buttons.
7+
url=https://github.com/caiofrota/cf-arduino-lib-pushbutton
8+
architectures=*
9+
category=Signal Input/Output

0 commit comments

Comments
 (0)