From cb4102c9a6ac5bb5e9dca30520aa25df5d2c1eea Mon Sep 17 00:00:00 2001
From: Ricardo Moreno <35234626+rmorenojr@users.noreply.github.com>
Date: Fri, 14 Sep 2018 09:02:00 -0600
Subject: [PATCH] Updated Readme.md
Minor format changes.
---
readme.md | 120 ++++++++++++++++++++++++++++--------------------------
1 file changed, 63 insertions(+), 57 deletions(-)
diff --git a/readme.md b/readme.md
index baa0eff..0cea942 100644
--- a/readme.md
+++ b/readme.md
@@ -1,26 +1,49 @@
# New & Improved Arduino Button Library
-_by Ted Hayes, from code originally by Alexander Brevig & Tom Igoe_
+_by Ted Hayes, from code originally by Alexander Brevig & Tom Igoe_
+_latest revisions by Ricardo Moreno_
The Arduino Button library makes it easy to do some very common but rather tedious tasks. Usually when you interact with a button (such as a momentary switch), you mainly want to detect the state change, not just the current state. You have to do something like:
```C++
int lastState = 0;
+void setup() {
+ pinMode (12, INPUT_PULLUP);
+}
+
void loop(){
- int currentState = digitalRead(11);
+ // check button debounce
+ int currentState = debounce(11);
if(currentState != lastState){
// do something
+ // check rising or falling edge
+ if(currentState == LOW) {
+ //button pressed do something
+ // startTime = millis()
+ } else if(currentState == HIGH) {
+ //button released do something
+ }
+ } else if (currentState == LOW) {
+ //check if hold
+ } else if (currentState == HIGH) {
+ //check doubleclick timer
}
lastState = currentState;
}
+
+bool debounce(pin) {
+ //debounce code
+ return value
+}
+
+//add additional button function here
```
-It's not hard, just tedious. This new and improved Button library makes this much simpler but adds so much more. Now you can do it this way:
+It's not hard, just tedious. And what if you wanted to manage multple buttons? This new and improved Button library makes this much simpler but adds so much more. Now you can do it this way:
```C++
-Button button = Button(12);
+Button button(12);
void onPress(Button& b){
- Serial.print("onPress: ");
- Serial.println(b.pin);
+ Serial.print("onPress: "); Serial.println(b.pin);
// will print out "onPress: 12"
}
@@ -37,29 +60,23 @@ void loop(){
```
## Features
-
* Instance-based design
`Button myButton(11);`
-
* Automatic pull-up setting
`Button myButton(11, BUTTON_PULLUP_INTERNAL);`
-
* Simplified state-change detection:
`if(button.isPressed()) ...`
-
* Callback model
`button.pressHandler(onPress)`
-
* Built-in debouncing
`// Sets 50ms debounce duration`
-
+
`Button button = Button(12, BUTTON_PULLUP_INTERNAL, true, 50);`
-
## Installing
To install, [download](https://github.com/virgildisgr4ce/Button/zipball/master) the library, extract it to ~/Documents/Arduino/libraries and rename the folder "Button." (Github generates a different name for the zip link.) Restart Arduino if it was already open.
@@ -68,11 +85,12 @@ I hope you find this useful! Please report any bugs using the [Github issue trac
# Functions
-## constructor - button
-#### Description
- Sets the inital state of this button
+## Constructor - button
+**Description:** `Sets the inital state of this button`
#### Syntax
- Button myButton(int buttonPin, optional int buttonMode, optional bool debounceMode, optional int debounceDuration);
+```C++
+Button myButton(int buttonPin, optional int buttonMode, optional bool debounceMode, optional int debounceDuration);
+```
#### Arguments
| Parameter | Description/Value|
|-----------|------------------|
@@ -80,8 +98,8 @@ I hope you find this useful! Please report any bugs using the [Github issue trac
| buttonMode | [optional]
BUTTON_PULLUP_INTERNAL using internal Arduino resistor \
BUTTON_PULLUP by extenal resistor
BUTTON_PULLDOWN by extenal resistor |
| debounceMode | [optional] bool true OR false \ |
| debounceDuration | [optional] int timeInMilliseconds \ |
-#### Returns
- None.
+
+**Returns:** `None.`
#### Examples
```C++
Button myButton(11);
@@ -90,8 +108,7 @@ Button myButton(11, BUTTON_PULLUP_INTERNAL, true, 50);
```
## pullup
-#### Description
- changes the buttonMode
+**Description:** `changes the buttonMode`
#### Syntax
```C++
myButton.pullup(int buttonMode);
@@ -100,8 +117,8 @@ myButton.pullup(int buttonMode);
| Parameter | Description/Value|
|-----------|------------------|
| buttonMode | BUTTON_PULLUP_INTERNAL using internal Arduino resistor
BUTTON_PULLUP by extenal resistor |
-#### Returns
- None.
+
+**Returns:** `None.`
#### Examples
```C++
myButton.pullup(BUTTON_PULLUP); //assumes external resistor
@@ -109,32 +126,28 @@ myButton.pullup(BUTTON_PULLUP_INTERNAL);
```
## process
-#### Description
- read and write states or isse callbacks
+**Description:** `read and write states or isse callbacks`
#### Syntax
```C++
myButton.process();
```
-#### Arguments
- None.
-#### Returns
- None.
+**Arguments** `None.`
+
+**Returns:** `None.`
#### Examples
```C++
myButton.process();
```
## isPressed
-#### Description
- returns true if button is pressed
+**Description:** `returns true if button is pressed`
#### Syntax
```C++
myButton.isPressed();
```
-#### Arguments
- None.
-#### Returns
- bool true or false
+**Arguments** `None.`
+
+**Returns:** `bool true or false`
#### Examples
```C++
if(myButton.isPressed()){
@@ -143,16 +156,14 @@ if(myButton.isPressed()){
```
## wasPressed
-#### Description
- returns true if button was pressed some time in the past
+**Description:** `returns true if button was pressed some time in the past`
#### Syntax
```C++
myButton.wasPressed();
```
-#### Arguments
- None.
-#### Returns
- bool true or false
+**Arguments** `None.`
+
+**Returns:** `bool true or false`
#### Examples
```C++
if(myButton.wasPressed()){
@@ -163,16 +174,14 @@ if(myButton.wasPressed()){
```
## stateChanged
-#### Description
- detects a state change in the button
+***Description:** `detects a state change in the button`
#### Syntax
```C++
myButton.stateChanged();
```
-#### Arguments
- None.
-#### Returns
- bool true or false
+**Arguments** `None.`
+
+**Returns:** `bool true or false`
#### Examples
```C++
if(myButton.stateChanged()){
@@ -181,16 +190,14 @@ if(myButton.stateChanged()){
```
## uniquePress
-#### Description
- detects if button is pressed and was not pressed before
+**Description:** `detects if button is pressed and was not pressed before`
#### Syntax
```C++
myButton.uniquePress();
```
-#### Arguments
- None.
-#### Returns
- bool true or false
+**Arguments** `None.`
+
+**Returns:** `bool true or false`
#### Examples
```C++
if(myButton.uniquePress()){
@@ -200,8 +207,7 @@ if(myButton.uniquePress()){
# Callbacks
## pressHandler, releaseHandler, clickHandler, holdHandler
-#### Description
- detects if button is pressed and was not pressed before
+**Description:** `detects if button is pressed and was not pressed before`
#### Syntax
```C++
myButton.pressHandler(functionName);
@@ -214,8 +220,8 @@ myButton.holdHandler(functionName, int milliseconds);
|-----------|------------------|
| functionName | the name of the function that will be called when true |
| milliseconds | the amount of time in ms to trigger the event |
-##### Returns
- bool true or false
+
+**Returns:** `bool true or false`
##### Examples
```C++
// Callback functions