Skip to content

Commit beb7a91

Browse files
committed
Rename library & repository from Button to JC_Button.
1 parent 3b10b31 commit beb7a91

File tree

7 files changed

+37
-47
lines changed

7 files changed

+37
-47
lines changed

Button.cpp renamed to JC_Button.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* San Francisco, California, 94105, USA. *
1515
*----------------------------------------------------------------------*/
1616

17-
#include "Button.h"
17+
#include "JC_Button.h"
1818

1919
/*----------------------------------------------------------------------*
2020
* Button(pin, puEnable, invert, dbTime) instantiates a button object. *

Button.h renamed to JC_Button.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,4 @@ class Button
3939
uint32_t _lastChange; //time of last state change
4040
uint32_t _dbTime; //debounce time
4141
};
42-
#endif
42+
#endif

README.md

Lines changed: 13 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,20 @@
1-
# Arduino Button Library v1.0
2-
https://github.com/JChristensen/Button
3-
ReadMe file
4-
Jack Christensen Mar 2012
1+
# Arduino Button Library
2+
https://github.com/JChristensen/JC_Button
3+
README file
54

65
![CC BY-SA](http://mirrors.creativecommons.org/presskit/buttons/80x15/png/by-sa.png)
76

87
## Introduction
98
The Button library is for debouncing and reading momentary contact switches like tactile button switches. "Long presses" of arbitrary length can be detected. Works well in state machine constructs. Use the read() function to read each button in the main loop, which should execute as fast as possible.
109

11-
## Installation
12-
To use the **Button** library:
13-
- Go to https://github.com/JChristensen/Button, click the **Download ZIP** button and save the ZIP file to a convenient location on your PC.
14-
- Uncompress the downloaded file. This will result in a folder containing all the files for the library, that has a name that includes the branch name, usually **Button-master**.
15-
- Rename the folder to just **Button**.
16-
- Copy the renamed folder to the Arduino sketchbook\libraries folder.
17-
1810
## Examples
1911
The following example sketches are included with the **Button** library:
2012

2113
- **SimpleOnOff**: Just turns the Arduino's pin 13 LED on and off.
2214
- **LongPress**: Demonstrates detecting long and short button presses.
2315
- **UpDown**: Counts up or down, one number at a time or rapidly by holding the button down.
2416

25-
## Button library methods
17+
## Button library functions
2618

2719
### Button(pin, puEnable, invert, dbTime)
2820
##### Description
@@ -41,7 +33,7 @@ None.
4133
Button myButton = Button(2, true, true, 25); //25 ms debounce
4234
```
4335

44-
### read(void)
36+
### read()
4537
##### Description
4638
Reads the button and returns a *boolean* value (*true* or *false*) to indicate whether the button is pressed. The read() function needs to execute very frequently in order for the sketch to be responsive. A good place for read() is at the top of loop(). Often, the return value from read() will not be needed if the other functions below are used.
4739
##### Syntax
@@ -55,12 +47,12 @@ None.
5547
myButton.read();
5648
```
5749

58-
### isPressed(void)
59-
### isReleased(void)
50+
### isPressed()
51+
### isReleased()
6052
##### Description
6153
These methods check the button state at the point in time when it was last read, and return false or true accordingly. These functions **do not** cause the button to be read.
6254
##### Syntax
63-
`myButton.isPressed();`
55+
`myButton.isPressed();`
6456
`myButton.isReleased();`
6557
##### Parameters
6658
None.
@@ -76,12 +68,12 @@ else {
7668
}
7769
```
7870

79-
### wasPressed(void)
80-
### wasReleased(void)
71+
### wasPressed()
72+
### wasReleased()
8173
##### Description
8274
These methods check the button state to see if it changed between the last two reads and return false or true accordingly. These functions **do not** cause the button to be read. Note that these functions may be more useful than `isPressed()` and `isReleased()` since they actually detect a **change** in the state of the button, which is usually what we want in order to cause some action.
8375
##### Syntax
84-
`myButton.wasPressed();`
76+
`myButton.wasPressed();`
8577
`myButton.wasReleased();`
8678
##### Parameters
8779
None.
@@ -97,7 +89,7 @@ if ( myButton.wasPressed() ) { ...
9789
##### Description
9890
These methods check to see if the button is pressed (or released), and has been in that state for the specified time in milliseconds. Returns false or true accordingly. These functions are useful to detect "long presses". Note that these functions **do not** cause the button to be read.
9991
##### Syntax
100-
`myButton.pressedFor(ms);`
92+
`myButton.pressedFor(ms);`
10193
`myButton.releasedFor(ms);`
10294
##### Parameters
10395
**ms:** The number of milliseconds *(unsigned long)*
@@ -108,7 +100,7 @@ These methods check to see if the button is pressed (or released), and has been
108100
if ( myButton.pressedFor(1000) ) { //has the button been pressed for one second?
109101
```
110102

111-
### lastChange(void)
103+
### lastChange()
112104
##### Description
113105
Under certain circumstances, it may be useful to know when a button last changed state. lastChange() returns the time the button last changed state, in milliseconds (the value is derived from the Arduino millis() function).
114106
##### Syntax

examples/LongPress/LongPress.ino

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,21 +15,20 @@
1515
* San Francisco, California, 94105, USA. *
1616
*----------------------------------------------------------------------*/
1717

18-
#include <Button.h> //https://github.com/JChristensen/Button
18+
#include <JC_Button.h> //https://github.com/JChristensen/JC_Button
1919

20-
#define BUTTON_PIN 2 //Connect a tactile button switch (or something similar)
21-
//from Arduino pin 2 to ground.
20+
#define BUTTON_PIN 7 //Connect a tactile button switch (or something similar) from this pin to ground.
2221
#define PULLUP true //To keep things simple, we use the Arduino's internal pullup resistor.
2322
#define INVERT true //Since the pullup resistor will keep the pin high unless the
2423
//switch is closed, this is negative logic, i.e. a high state
2524
//means the button is NOT pressed. (Assuming a normally open switch.)
26-
#define DEBOUNCE_MS 20 //A debounce time of 20 milliseconds usually works well for tactile button switches.
25+
#define DEBOUNCE_MS 25 //A debounce time of 20 milliseconds usually works well for tactile button switches.
2726

2827
#define LED_PIN 13 //The standard Arduino "Pin 13" LED.
2928
#define LONG_PRESS 1000 //We define a "long press" to be 1000 milliseconds.
3029
#define BLINK_INTERVAL 100 //In the BLINK state, switch the LED every 100 milliseconds.
3130

32-
Button myBtn(BUTTON_PIN, PULLUP, INVERT, DEBOUNCE_MS); //Declare the button
31+
Button myBtn(BUTTON_PIN, PULLUP, INVERT, DEBOUNCE_MS); //Define the button
3332

3433
//The list of possible states for the state machine. This state machine has a fixed
3534
//sequence of states, i.e. ONOFF --> TO_BLINK --> BLINK --> TO_ONOFF --> ONOFF
@@ -41,12 +40,12 @@ boolean ledState; //The current LED status
4140
unsigned long ms; //The current time from millis()
4241
unsigned long msLast; //The last time the LED was switched
4342

44-
void setup(void)
43+
void setup()
4544
{
4645
pinMode(LED_PIN, OUTPUT); //Set the LED pin as an output
4746
}
4847

49-
void loop(void)
48+
void loop()
5049
{
5150
ms = millis(); //record the current time
5251
myBtn.read(); //Read the button

examples/SimpleOnOff/SimpleOnOff.ino

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,26 +12,25 @@
1212
* San Francisco, California, 94105, USA. *
1313
*----------------------------------------------------------------------*/
1414

15-
#include <Button.h> //https://github.com/JChristensen/Button
15+
#include <JC_Button.h> //https://github.com/JChristensen/JC_Button
1616

17-
#define BUTTON_PIN 2 //Connect a tactile button switch (or something similar)
18-
//from Arduino pin 2 to ground.
17+
#define BUTTON_PIN 7 //Connect a tactile button switch (or something similar) from this pin to ground.
1918
#define PULLUP true //To keep things simple, we use the Arduino's internal pullup resistor.
2019
#define INVERT true //Since the pullup resistor will keep the pin high unless the
2120
//switch is closed, this is negative logic, i.e. a high state
2221
//means the button is NOT pressed. (Assuming a normally open switch.)
23-
#define DEBOUNCE_MS 20 //A debounce time of 20 milliseconds usually works well for tactile button switches.
22+
#define DEBOUNCE_MS 25 //A debounce time of 25 milliseconds usually works well for tactile button switches.
2423
#define LED_PIN 13 //The standard Arduino "Pin 13" LED
2524

26-
Button myBtn(BUTTON_PIN, PULLUP, INVERT, DEBOUNCE_MS); //Declare the button
25+
Button myBtn(BUTTON_PIN, PULLUP, INVERT, DEBOUNCE_MS); //Define the button
2726
boolean ledState; //A variable that keeps the current LED status
2827

29-
void setup(void)
28+
void setup()
3029
{
3130
pinMode(LED_PIN, OUTPUT); //Set the LED pin as an output
3231
}
3332

34-
void loop(void)
33+
void loop()
3534
{
3635
myBtn.read(); //Read the button
3736

examples/UpDown/UpDown.ino

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,22 +13,22 @@
1313
* San Francisco, California, 94105, USA. *
1414
*----------------------------------------------------------------------*/
1515

16-
#include <Button.h> //https://github.com/JChristensen/Button
16+
#include <JC_Button.h> //https://github.com/JChristensen/JC_Button
1717

18-
#define DN_PIN 2 //Connect two tactile button switches (or something similar)
19-
#define UP_PIN 3 //from Arduino pin 2 to ground and from pin 3 to ground.
18+
#define DN_PIN 7 //Connect two tactile button switches (or something similar)
19+
#define UP_PIN 8 //from Arduino pin 7 to ground and from pin 8 to ground.
2020
#define PULLUP true //To keep things simple, we use the Arduino's internal pullup resistor.
2121
#define INVERT true //Since the pullup resistor will keep the pin high unless the
2222
//switch is closed, this is negative logic, i.e. a high state
2323
//means the button is NOT pressed. (Assuming a normally open switch.)
24-
#define DEBOUNCE_MS 20 //A debounce time of 20 milliseconds usually works well for tactile button switches.
24+
#define DEBOUNCE_MS 25 //A debounce time of 20 milliseconds usually works well for tactile button switches.
2525

2626
#define REPEAT_FIRST 500 //ms required before repeating on long press
2727
#define REPEAT_INCR 100 //repeat interval for long press
2828
#define MIN_COUNT 0
2929
#define MAX_COUNT 59
3030

31-
Button btnUP(UP_PIN, PULLUP, INVERT, DEBOUNCE_MS); //Declare the buttons
31+
Button btnUP(UP_PIN, PULLUP, INVERT, DEBOUNCE_MS); //Define the buttons
3232
Button btnDN(DN_PIN, PULLUP, INVERT, DEBOUNCE_MS);
3333

3434
enum {WAIT, INCR, DECR}; //The possible states for the state machine
@@ -37,12 +37,12 @@ int count; //The number that is adjusted
3737
int lastCount = -1; //Previous value of count (initialized to ensure it's different when the sketch starts)
3838
unsigned long rpt = REPEAT_FIRST; //A variable time that is used to drive the repeats for long presses
3939

40-
void setup(void)
40+
void setup()
4141
{
4242
Serial.begin(115200);
4343
}
4444

45-
void loop(void)
45+
void loop()
4646
{
4747
btnUP.read(); //read the buttons
4848
btnDN.read();

library.properties

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
name=Button
2-
version=1.0.1
1+
name=JC_Button
2+
version=1.0.2
33
author=Jack Christensen <jack.christensen@outlook.com>
44
maintainer=Jack Christensen <jack.christensen@outlook.com>
55
sentence=Arduino library to debounce button switches, detect presses, releases, and long presses.
66
paragraph=The Button library is for debouncing and reading momentary contact switches like tactile button switches. "Long presses" of arbitrary length can be detected. Works well in state machine constructs. Use the read() function to read each button in the main loop, which should execute as fast as possible.
77
category=Signal Input/Output
8-
url=https://github.com/JChristensen/Button
8+
url=https://github.com/JChristensen/JC_Button
99
architectures=avr

0 commit comments

Comments
 (0)