Skip to content

Commit bb087e1

Browse files
committed
Formatting and comments updating.
Formatting and comments updating to improve documentation and make the code more readable.
1 parent f3ef0d2 commit bb087e1

13 files changed

Lines changed: 85 additions & 45 deletions

File tree

examples/CountingButton_Demo_01/CountingButton_Demo_01.ino

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
/*
2-
Toggles an LED on when the button is held down and off when the button
3-
is released.
2+
This example counts and displays the number of times a button is pressed.
3+
Once the specified count is reached, an LED is turned on. A long press
4+
will reset the counter and turn the LED off.
45
56
The button should be wired such that when pressed, the "buttonPin" is
67
connected to ground.
@@ -34,12 +35,17 @@ void setup()
3435

3536
void loop()
3637
{
37-
// Press the button once to turn it on, and again to turn it off.
38+
// During each loop, the number of times the button is pressed is retrieved
39+
// from the button.
3840
int count = button.getCount();
3941

42+
// Display the button count on the serial monitor.
4043
Serial.print("Button press count: ");
4144
Serial.println(count);
4245

46+
// If the count is above a specified value, turn the LED on, otherwise turn
47+
// if off. If the button is reset with a long press, the counter is reset
48+
// and the LED is turned off.
4349
if (count > 4)
4450
{
4551
digitalWrite(ledPin, HIGH);
Lines changed: 37 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
/*
2-
Displays the current value of the CycleButton to the serial monitor. When
3-
the value is greater than a set value, an LED is turned on.
4-
5-
The value is incremented each time the button is pushed. If the value is
6-
higher than the maximum value, it resets to the minimum value. Holding
7-
the button down longer than the long press time will also reset the counter.
8-
9-
The button should be wired such that when pressed, the "buttonPin" is
10-
connected to ground.
2+
Displays the current value of the CycleButton to the serial monitor. When
3+
the value is greater than a set value, an LED is turned on.
4+
5+
The value is incremented each time the button is pushed. If the value is
6+
higher than the maximum value, it resets to the minimum value. Holding
7+
the button down longer than the long press time will also reset the counter.
8+
9+
The button should be wired such that when pressed, the "buttonPin" is
10+
connected to ground.
1111
12-
The LED should be wired with the "ledPin" to the positive lead and the
13-
negative lead should be connected to ground. A current limiting resistor
14-
should be used.
12+
The LED should be wired with the "ledPin" to the positive lead and the
13+
negative lead should be connected to ground. A current limiting resistor
14+
should be used.
1515
*/
1616

1717
#include "CycleButton.h"
@@ -23,33 +23,38 @@
2323
int buttonPin = 8;
2424
int ledPin = 9;
2525

26-
// The CycleButton will automatically configure the button pin.
26+
// The CycleButton will automatically configure the button pin. The second number is
27+
// the maximum value of the counter.
2728
CycleButton button(buttonPin, 6);
2829

2930
void setup()
3031
{
31-
Serial.begin(9600);
32-
Serial.println("*** Cycle Button Demo 01 ***");
32+
Serial.begin(9600);
33+
Serial.println("*** Cycle Button Demo 01 ***");
3334

34-
// Setup the output LED.
35-
pinMode(ledPin, OUTPUT);
36-
digitalWrite(ledPin, LOW);
35+
// Setup the output LED.
36+
pinMode(ledPin, OUTPUT);
37+
digitalWrite(ledPin, LOW);
3738
}
3839

3940
void loop()
4041
{
41-
// Press the button once to turn it on, and again to turn it off.
42-
int value = button.getValue();
43-
44-
Serial.print("Cycle button value: ");
45-
Serial.println(value);
42+
// During each loop, the number of times the button is pressed is retrieved
43+
// from the button.
44+
int value = button.getValue();
45+
46+
Serial.print("Cycle button value: ");
47+
Serial.println(value);
4648

47-
if (value > 3)
48-
{
49-
digitalWrite(ledPin, HIGH);
50-
}
51-
else
52-
{
53-
digitalWrite(ledPin, LOW);
54-
}
55-
}
49+
// If the count is above a specified value, turn the LED on, otherwise turn
50+
// if off. Once the button's max value is reached, it will reset to the first
51+
// value and the LED is turned off. The button can also be manually reset.
52+
if (value > 2)
53+
{
54+
digitalWrite(ledPin, HIGH);
55+
}
56+
else
57+
{
58+
digitalWrite(ledPin, LOW);
59+
}
60+
}

examples/LatchingButton_Demo_01/LatchingButton_Demo_01.ino

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
/*
2-
Toggles an LED on when the button is held down and off when the button
3-
is released.
2+
Toggles an LED when a button is pressed and released. The LED is set to
3+
the current state of the button. If the button is latched, the LED is on,
4+
if the button is not latched, the LED is off. This button uses the "isLatched"
5+
function to determine the buttons state.
46
57
The button should be wired such that when pressed, the "buttonPin" is
68
connected to ground.

examples/LatchingButton_Demo_02/LatchingButton_Demo_02.ino

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
/*
2-
Toggles an LED on when the button is held down and off when the button
3-
is released.
2+
Toggles an LED when a button is pressed and released. The LED is set to
3+
the current state of the button. If the button is latched, the LED is on,
4+
if the button is not latched, the LED is off. This example uses the "getStatus"
5+
function to determine the current state of the button.
46
57
The button should be wired such that when pressed, the "buttonPin" is
68
connected to ground.

examples/MomentaryButton_Demo_01/MomentaryButton_Demo_01.ino

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/*
2-
Toggles an LED between on and off with each press of the button.
2+
Turns an LED on when the button is pressed and off when the button is released.
3+
This example demonstrates the "isPressed" function.
34
45
The button should be wired such that when pressed, the "buttonPin" is
56
connected to ground.

examples/MomentaryButton_Demo_02/MomentaryButton_Demo_02.ino

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/*
2-
Toggles an LED between on and off with each press of the button.
2+
Toggles an LED between on and off each time the button is pressed and released.
3+
This example demonstrates the "wasPressed" function.
34
45
The button should be wired such that when pressed, the "buttonPin" is
56
connected to ground.

examples/MomentaryButton_Demo_03/MomentaryButton_Demo_03.ino

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/*
2-
Toggles an LED between on and off with each press of the button.
2+
Toggles an LED between on and off with each time a button is pressed and released.
3+
This example demonstrates the "getStatus" function.
34
45
The button should be wired such that when pressed, the "buttonPin" is
56
connected to ground.

src/AlwaysOffButton.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,10 @@ class AlwaysOffButton : public SimpleButton
3636
public:
3737
AlwaysOffButton(int pin);
3838
AlwaysOffButton(int pin, int debounceInterval);
39+
3940
~AlwaysOffButton();
4041

42+
// Status access functions. Call in the "loop" to get the status of the button.
4143
public:
4244
// Returns true if the button is currently pressed.
4345
BUTTONSTATUS getStatus();

src/AlwaysOnButton.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,10 @@ class AlwaysOnButton : public SimpleButton
3636
public:
3737
AlwaysOnButton(int pin);
3838
AlwaysOnButton(int pin, int debounceInterval);
39+
3940
~AlwaysOnButton();
4041

42+
// Status access functions. Call in the "loop" to get the status of the button.
4143
public:
4244
// Returns true if the button is currently pressed.
4345
BUTTONSTATUS getStatus();

src/CountingButton.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,20 @@ class CountingButton : public ButtonBase, public ResetableButton
4545
public:
4646
CountingButton(int pin);
4747
CountingButton(int pin, int debounceInterval);
48+
4849
~CountingButton();
4950

51+
// Set up functions. Normally, these would be called in the "setup" function of your sketch.
5052
public:
5153
void setLongPressInterval(int longPressInterval);
5254

55+
// Status access functions. Call in the "loop" to get the status of the button.
56+
public:
5357
// Checks the button and returns the current count.
5458
int getCount();
5559

60+
// Other control functions.
61+
public:
5662
// Return to zero.
5763
void reset();
5864

0 commit comments

Comments
 (0)