Skip to content

Commit 24d68cd

Browse files
author
Evert Arias
authored
Merge pull request #43 from evert-arias/v2
v2
2 parents 94c2ca6 + 4632a5c commit 24d68cd

File tree

21 files changed

+575
-218
lines changed

21 files changed

+575
-218
lines changed

examples/Interrupts/Interrupts.ino

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,17 @@
88
#include <Arduino.h>
99
#include <EasyButton.h>
1010

11+
// Arduino pin where the buttons are connected to.
1112
#define BUTTON_PIN 2
12-
#define BAUDRATE 9600
1313

14+
#define BAUDRATE 115200
15+
16+
// Instance of the button.
1417
EasyButton button(BUTTON_PIN);
1518

1619
void buttonPressed()
1720
{
18-
Serial.println("Button Pressed");
21+
Serial.println("Button pressed");
1922
}
2023

2124
void sequenceEllapsed()
@@ -25,17 +28,29 @@ void sequenceEllapsed()
2528

2629
void buttonISR()
2730
{
28-
//When button is being used through external interrupts, parameter INTERRUPT must be passed to read() function
29-
button.read(EASYBUTTON_READ_TYPE_INTERRUPT);
31+
/*
32+
When button is being used through external interrupts,
33+
parameter INTERRUPT must be passed to read() function
34+
*/
35+
button.read();
3036
}
3137

3238
void setup()
3339
{
34-
// put your setup code here, to run once:
40+
41+
// Initialize Serial for debuging purposes.
3542
Serial.begin(BAUDRATE);
43+
44+
Serial.println();
45+
Serial.println(">>> EasyButton interrupts example <<<");
46+
47+
// Initialize the button.
3648
button.begin();
49+
3750
button.onPressed(buttonPressed);
51+
3852
button.onSequence(2, 1500, sequenceEllapsed);
53+
3954
if (button.supportsInterrupt())
4055
{
4156
button.enableInterrupt(buttonISR);

examples/InterruptsOnPressedFor/InterruptsOnPressedFor.ino

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,36 +8,53 @@
88
#include <Arduino.h>
99
#include <EasyButton.h>
1010

11-
#define BUTTON_PIN 2 //Should be a pin that supports external interrupts
12-
#define BAUDRATE 9600
11+
/*
12+
Arduino pin where the buttons are connected to.
13+
Should be a pin that supports external interrupts.
14+
*/
15+
#define BUTTON_PIN 2
1316

17+
#define BAUDRATE 115200
18+
19+
// Instance of the button.
1420
EasyButton button(BUTTON_PIN);
1521

1622
void buttonPressedTwoSeconds()
1723
{
18-
Serial.println("Button Pressed for two seconds");
24+
Serial.println("Button pressed for two seconds");
1925
}
2026

2127
void buttonISR()
2228
{
23-
//When button is being used through external interrupts, parameter INTERRUPT must be passed to read() function
24-
button.read(EASYBUTTON_READ_TYPE_INTERRUPT);
29+
// When button is being used through external interrupts, parameter INTERRUPT must be passed to read() function.
30+
button.read();
2531
}
2632

27-
void setup() {
28-
// put your setup code here, to run once:
33+
void setup()
34+
{
35+
// Initialize Serial for debuging purposes.
2936
Serial.begin(BAUDRATE);
37+
38+
Serial.println();
39+
Serial.println(">>> EasyButton onPressedFor interrupt example <<<");
40+
41+
// Initialize the button.
3042
button.begin();
43+
3144
button.onPressedFor(2000, buttonPressedTwoSeconds);
45+
3246
if (button.supportsInterrupt())
3347
{
3448
button.enableInterrupt(buttonISR);
35-
Serial.println("EasyButton onPressedFor Interrupt example");
49+
Serial.println("Button will be used through interrupts");
3650
}
3751
}
3852

39-
void loop() {
40-
// put your main code here, to run repeatedly:
41-
// update() function must be called repeatedly only if onPressedFor functionality is being used and interrupt is enabled
53+
void loop()
54+
{
55+
/*
56+
update() function must be called repeatedly only if onPressedFor
57+
functionality is being used and interrupt is enabled.
58+
*/
4259
button.update();
4360
}

examples/MultipleButtons/MultipleButtons.ino

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,27 +8,36 @@
88
#include <EasyButton.h>
99

1010
// Arduino pin where the buttons are connected to
11-
#define BUTTON_ONE_PIN 26
12-
#define BUTTON_TWO_PIN 27
11+
#define BUTTON_ONE_PIN 2
12+
#define BUTTON_TWO_PIN 4
13+
14+
#define BAUDRATE 115200
1315

1416
// Button1
1517
EasyButton button1(BUTTON_ONE_PIN);
1618
// Button2
1719
EasyButton button2(BUTTON_TWO_PIN);
1820

1921
// Callback function to be called when button1 is pressed
20-
void onButton1Pressed() {
21-
Serial.println("Button1 has been pressed!");
22+
void onButton1Pressed()
23+
{
24+
Serial.println("Button1 pressed");
2225
}
2326

2427
// Callback function to be called when button2 is pressed
25-
void onButton2Pressed() {
26-
Serial.println("Button2 has been pressed!");
28+
void onButton2Pressed()
29+
{
30+
Serial.println("Button2 pressed");
2731
}
2832

29-
void setup() {
33+
void setup()
34+
{
3035
// Initialize Serial for debuging purposes
31-
Serial.begin(115200);
36+
Serial.begin(BAUDRATE);
37+
38+
Serial.println();
39+
Serial.println(">>> EasyButton multiple buttons example <<<");
40+
3241
// Initialize the button1
3342
button1.begin();
3443
// Initialize the button2
@@ -39,7 +48,8 @@ void setup() {
3948
button2.onPressed(onButton2Pressed);
4049
}
4150

42-
void loop() {
51+
void loop()
52+
{
4353
// Continuously read the status of the buttons
4454
button1.read();
4555
button2.read();

examples/MultipleSequence/MultipleSequence.ino

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,10 @@
88
#include <Arduino.h>
99
#include <EasyButton.h>
1010

11-
#define BUTTON_PIN 16
12-
#define BAUDRATE 19200
11+
// Arduino pin where the button is connected to.
12+
#define BUTTON_PIN 2
13+
14+
#define BAUDRATE 115200
1315

1416
void sequenceEllapsed()
1517
{
@@ -21,18 +23,27 @@ void otherSequence()
2123
Serial.println("Other sequence");
2224
}
2325

26+
// Instance of the button.
2427
EasyButton button(BUTTON_PIN);
2528

26-
void setup() {
27-
// put your setup code here, to run once:
29+
void setup()
30+
{
31+
// Initialize Serial for debuging purposes.
2832
Serial.begin(BAUDRATE);
33+
34+
Serial.println();
35+
Serial.println(">>> EasyButton multiple onSequence example <<<");
36+
37+
// Initialize the button.
2938
button.begin();
39+
3040
button.onSequence(2, 1500, sequenceEllapsed);
41+
3142
button.onSequence(3, 2500, otherSequence);
32-
Serial.println("Multiple onSequence example");
3343
}
3444

35-
void loop() {
36-
// put your main code here, to run repeatedly:
45+
void loop()
46+
{
47+
// Continuously read the status of the button.
3748
button.read();
3849
}

examples/Pressed/Pressed.ino

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,26 +8,35 @@
88
#include <EasyButton.h>
99

1010
// Arduino pin where the button is connected to.
11-
#define BUTTON_PIN 26
11+
#define BUTTON_PIN 2
12+
13+
#define BAUDRATE 115200
1214

1315
// Instance of the button.
1416
EasyButton button(BUTTON_PIN);
1517

1618
// Callback function to be called when the button is pressed.
17-
void onPressed() {
18-
Serial.println("Button has been pressed!");
19+
void onPressed()
20+
{
21+
Serial.println("Button pressed");
1922
}
2023

21-
void setup() {
24+
void setup()
25+
{
2226
// Initialize Serial for debuging purposes.
23-
Serial.begin(115200);
27+
Serial.begin(BAUDRATE);
28+
29+
Serial.println();
30+
Serial.println(">>> EasyButton pressed example <<<");
31+
2432
// Initialize the button.
2533
button.begin();
2634
// Add the callback function to be called when the button is pressed.
2735
button.onPressed(onPressed);
2836
}
2937

30-
void loop() {
31-
// Continuously read the status of the button.
38+
void loop()
39+
{
40+
// Continuously read the status of the button.
3241
button.read();
3342
}
Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,42 @@
11
/*
2-
Name: PressedForDuration.ino
3-
Created: 9/5/2018 10:49:52 AM
4-
Author: Evert Arias
5-
Description: Example to demostrate how to use the library to detect a pressed for a given duration on a button.
2+
Name: PressedForDuration.ino
3+
Created: 9/5/2018 10:49:52 AM
4+
Author: Evert Arias
5+
Description: Example to demostrate how to use the library to detect a pressed for a given duration on a button.
66
*/
77

88
#include <EasyButton.h>
99

1010
// Arduino pin where the button is connected to.
11-
#define BUTTON_PIN 26
11+
#define BUTTON_PIN 2
12+
13+
#define BAUDRATE 115200
1214

1315
// Instance of the button.
1416
EasyButton button(BUTTON_PIN);
1517

1618
// Callback function to be called when the button is pressed.
17-
void onPressedForDuration() {
18-
Serial.println("Button has been pressed!");
19+
void onPressedForDuration()
20+
{
21+
Serial.println("Button pressed");
1922
}
2023

21-
void setup() {
24+
void setup()
25+
{
2226
// Initialize Serial for debuging purposes.
23-
Serial.begin(115200);
27+
Serial.begin(BAUDRATE);
28+
29+
Serial.println();
30+
Serial.println(">>> EasyButton pressedFor example <<<");
31+
2432
// Initialize the button.
2533
button.begin();
2634
// Add the callback function to be called when the button is pressed for at least the given time.
2735
button.onPressedFor(2000, onPressedForDuration);
2836
}
2937

30-
void loop() {
31-
// Continuously read the status of the button.
38+
void loop()
39+
{
40+
// Continuously read the status of the button.
3241
button.read();
3342
}

examples/Sequence/Sequence.ino

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,42 @@
11
/*
2-
Name: Sequence.ino
3-
Created: 9/5/2018 10:49:52 AM
4-
Author: Evert Arias
5-
Description: Example to demostrate how to use the library to detect a sequence of presses on a button.
2+
Name: Sequence.ino
3+
Created: 9/5/2018 10:49:52 AM
4+
Author: Evert Arias
5+
Description: Example to demostrate how to use the library to detect a sequence of presses on a button.
66
*/
77

88
#include <EasyButton.h>
99

1010
// Arduino pin where the button is connected to.
11-
#define BUTTON_PIN 26
11+
#define BUTTON_PIN 2
12+
13+
#define BAUDRATE 115200
1214

1315
// Instance of the button.
1416
EasyButton button(BUTTON_PIN);
1517

1618
// Callback function to be called when the button is pressed.
17-
void onSequenceMatched() {
18-
Serial.println("Button has been pressed!");
19+
void onSequenceMatched()
20+
{
21+
Serial.println("Button pressed");
1922
}
2023

21-
void setup() {
24+
void setup()
25+
{
2226
// Initialize Serial for debuging purposes.
23-
Serial.begin(115200);
27+
Serial.begin(BAUDRATE);
28+
29+
Serial.println();
30+
Serial.println(">>> EasyButton sequence example <<<");
31+
2432
// Initialize the button.
2533
button.begin();
2634
// Add the callback function to be called when the given sequence of presses is matched.
2735
button.onSequence(5 /* number of presses */, 2000 /* timeout */, onSequenceMatched /* callback */);
2836
}
2937

30-
void loop() {
31-
// Continuously read the status of the button.
38+
void loop()
39+
{
40+
// Continuously read the status of the button.
3241
button.read();
3342
}

0 commit comments

Comments
 (0)