Skip to content

Commit 2941215

Browse files
...
1 parent 2a2f031 commit 2941215

File tree

12 files changed

+205
-178
lines changed

12 files changed

+205
-178
lines changed

examples/Button/Button.ino

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,28 +2,28 @@
22

33
Button button(4, HIGH);
44

5-
void pressed(Button & button)
5+
void pressed(Button &button)
66
{
77
Serial.println("pressed");
88
}
99

10-
void held(Button & button)
10+
void held(Button &button)
1111
{
1212
Serial.println("held");
1313
}
1414

15-
void click(Button & button)
15+
void click(Button &button)
1616
{
1717
Serial.print("click: ");
1818
Serial.println(button.clicks());
1919
}
2020

21-
void double_click(Button & button)
21+
void double_click(Button &button)
2222
{
2323
Serial.println("double click");
2424
}
2525

26-
//The setup function is called once at startup of the sketch
26+
// The setup function is called once at startup of the sketch
2727
void setup()
2828
{
2929
Serial.begin(9600);

examples/Button_And_Led/Button_And_Led.ino

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
#include <Led.h>
22
#include <Button.h>
33

4-
Led led(6, HIGH); // led attached to pin 6 and requires a high (+5v) to light
4+
Led led(6, HIGH); // led attached to pin 6 and requires a high (+5v) to light
55
Button button(4, HIGH); // button attached to pin 4 and will pull it high (+5v) when closed
66

77
// called whenever a "pressed" event occurs.
8-
void pressed(Button & button)
8+
void pressed(Button &button)
99
{
1010
Serial.println("pressed");
1111
}
1212

1313
// called whenever a "click" event occurs.
14-
void click(Button & button)
14+
void click(Button &button)
1515
{
1616
// if the button is on
1717
if (led.isOn())
@@ -28,7 +28,7 @@ void click(Button & button)
2828
Serial.println("click");
2929
}
3030

31-
//The setup function is called once at startup of the sketch
31+
// The setup function is called once at startup of the sketch
3232
void setup()
3333
{
3434
Serial.begin(9600);

examples/Led/Led.ino

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
#include "Led.h"
1+
#include <Led.h>
22

33
// create an LED object that uses PIN 13 and uses 5+ for on
44
Led led(6, HIGH);
55

6-
void done(Led & led)
6+
void done(Led &led)
77
{
88
if (led.brightness() == 0)
99
{
@@ -15,7 +15,7 @@ void done(Led & led)
1515
}
1616
}
1717

18-
//The setup function is called once at startup of the sketch
18+
// The setup function is called once at startup of the sketch
1919
void setup()
2020
{
2121
Serial.begin(9600);

examples/Relay/Relay.ino

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,38 @@
1-
#include "Relay.h"
1+
#include <Relay.h>
2+
3+
Relay relay(13);
4+
5+
// The setup function is called once at startup of the sketch
6+
void setup()
7+
{
8+
Serial.begin(9600);
9+
10+
Serial.print("Relay state: ");
11+
Serial.print(relay.state());
12+
13+
// engage the relay
14+
relay.on();
15+
16+
Serial.print("Relay state: ");
17+
Serial.println(relay.state());
18+
19+
delay(1000);
20+
21+
// disengage the relay
22+
relay.off();
23+
24+
Serial.print("Relay state: ");
25+
Serial.println(relay.state());
26+
27+
delay(1000);
28+
29+
// temporarily engage the relay as if clicking a button
30+
relay.flash();
31+
}
32+
33+
// The loop function is called in an endless loop
34+
void loop()
35+
{
36+
// required for flash program to run
37+
relay.run();
38+
}

examples/Timer/Timer.ino

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ void wake()
1919
Serial.println("Time to wake!")
2020
}
2121

22+
// The setup function is called once at startup of the sketch
2223
void setup()
2324
{
2425
Serial.begin(9600);
@@ -28,6 +29,7 @@ void setup()
2829
Timer.repeat(minute, MINUTE);
2930
}
3031

32+
// The loop function is called in an endless loop
3133
void loop()
3234
{
3335
Timer.run();

library.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
],
1717
"dependencies": [],
1818
"version": "2.0.0",
19-
"excelude": "tests",
2019
"frameworks": "arduino",
2120
"platforms": ["atmelavr", "espressif"]
2221
}

src/Button.cpp

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,14 @@
11
#include "Button.h"
22

3-
Button::Button(uint8_t pin, uint8_t pressed_value, bool use_pullup) :
4-
m_pin(pin),
5-
m_pressed_is_high(pressed_value == HIGH),
6-
7-
m_debounce_t(0),
8-
m_click_t(0),
9-
m_dbl_click_t(0),
10-
m_click_count(0),
11-
m_last_read(false),
12-
m_current_state(false),
13-
m_held(false)
3+
Button::Button(uint8_t pin, uint8_t pressed_value, bool use_pullup) : m_pin(pin),
4+
m_pressed_is_high(pressed_value == HIGH),
5+
m_debounce_t(0),
6+
m_click_t(0),
7+
m_dbl_click_t(0),
8+
m_click_count(0),
9+
m_last_read(false),
10+
m_current_state(false),
11+
m_held(false)
1412
{
1513
memset(m_handler, 0, ButtonEvent_Count);
1614

@@ -56,8 +54,8 @@ void Button::run()
5654
fire(bePressed);
5755
}
5856
else
59-
// if latch down
60-
if (!state && m_current_state)
57+
// if latch down
58+
if (!state && m_current_state)
6159
{
6260
m_current_state = state;
6361
m_held = false;
@@ -119,8 +117,7 @@ bool Button::read()
119117

120118
// read the button
121119
bool current_read =
122-
m_pressed_is_high ?
123-
(digitalRead(m_pin) == HIGH) : (digitalRead(m_pin) == LOW);
120+
m_pressed_is_high ? (digitalRead(m_pin) == HIGH) : (digitalRead(m_pin) == LOW);
124121

125122
// if the button state changed
126123
if (current_read != m_last_read)

src/Button.h

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#ifndef __Button_h_
22
#define __Button_h_
33

4-
#include "Arduino.h"
4+
#include <Arduino.h>
55

66
// the amount of time required to identify a latch
77
#define BUTTON_DEBOUNCE_DELAY 50
@@ -13,11 +13,16 @@
1313

1414
class Button;
1515

16-
typedef void (*ButtonEventHandler)(Button & button);
16+
typedef void (*ButtonEventHandler)(Button &button);
1717

1818
enum ButtonEvent
1919
{
20-
bePressed, beReleased, beClick, beDblClick, beHeld, ButtonEvent_Count
20+
bePressed,
21+
beReleased,
22+
beClick,
23+
beDblClick,
24+
beHeld,
25+
ButtonEvent_Count
2126
};
2227

2328
class Button
@@ -43,12 +48,11 @@ class Button
4348
void run();
4449

4550
private:
46-
4751
// executes an event
4852
void fire(ButtonEvent event);
4953

50-
Button(const Button & rhs);
51-
Button & operator=(const Button & rhs);
54+
Button(const Button &rhs);
55+
Button &operator=(const Button &rhs);
5256

5357
uint8_t m_pin;
5458
bool m_pressed_is_high;

src/Led.cpp

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,16 @@
11
#include "Led.h"
22

3-
Led::Led(uint8_t pin, uint8_t on_value) :
4-
m_on_is_high(on_value == HIGH),
3+
Led::Led(uint8_t pin, uint8_t on_value) : m_on_is_high(on_value == HIGH),
54

6-
m_millis(millis()),
7-
m_value(0),
8-
m_pin(pin),
5+
m_millis(millis()),
6+
m_value(0),
7+
m_pin(pin),
98

10-
m_frame(0),
11-
m_frame_count(0),
12-
m_handler(NULL),
9+
m_frame(0),
10+
m_frame_count(0),
11+
m_handler(NULL),
1312

14-
m_max(100)
13+
m_max(100)
1514
{
1615
memset(m_program, 0, LED_MAX_FRAMES);
1716

@@ -42,7 +41,7 @@ void Led::setMax(uint8_t precent)
4241

4342
void Led::brightness(uint8_t percent)
4443
{
45-
if( percent > m_max )
44+
if (percent > m_max)
4645
{
4746
percent = m_max;
4847
}
@@ -111,12 +110,12 @@ void Led::flash(LedEventHandler handler)
111110
void Led::fadeOn(LedEventHandler handler, uint8_t delay)
112111
{
113112
m_frame_count = 0;
114-
115-
for( uint8_t x = 0; x < delay; x++ )
113+
114+
for (uint8_t x = 0; x < delay; x++)
116115
{
117116
m_program[m_frame_count++] = 0;
118117
}
119-
118+
120119
m_program[m_frame_count++] = 0;
121120
m_program[m_frame_count++] = 25;
122121
m_program[m_frame_count++] = 50;
@@ -131,7 +130,7 @@ void Led::fadeOff(LedEventHandler handler, uint8_t delay)
131130
{
132131
m_frame_count = 0;
133132

134-
for( uint8_t x = 0; x < delay; x++ )
133+
for (uint8_t x = 0; x < delay; x++)
135134
{
136135
m_program[m_frame_count++] = 100;
137136
}
@@ -160,13 +159,13 @@ void Led::display()
160159
{
161160
LedEventHandler handler = m_handler;
162161
m_handler = NULL;
163-
162+
164163
handler(*this);
165164
}
166165
}
167166
}
168167

169-
bool operator==(const Led & lhs, const Led & rhs)
168+
bool operator==(const Led &lhs, const Led &rhs)
170169
{
171170
return lhs.pin() == rhs.pin();
172171
}

src/Led.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
#ifndef __LED_h_
22
#define __LED_h_
33

4-
#include "Arduino.h"
4+
#include <Arduino.h>
55

66
#define LED_MAX_FRAMES 20
77
#define LED_FRAME_INTERVAL 60
88

99
class Led;
1010

11-
typedef void (*LedEventHandler)(Led & led);
11+
typedef void (*LedEventHandler)(Led &led);
1212

1313
class Led
1414
{
@@ -48,8 +48,8 @@ class Led
4848
void display();
4949

5050
private:
51-
Led(const Led & rhs);
52-
Led & operator=(const Led & rhs);
51+
Led(const Led &rhs);
52+
Led &operator=(const Led &rhs);
5353

5454
bool m_on_is_high;
5555

@@ -65,6 +65,6 @@ class Led
6565
uint8_t m_max;
6666
};
6767

68-
bool operator==(const Led & lhs, const Led & rhs);
68+
bool operator==(const Led &lhs, const Led &rhs);
6969

7070
#endif // __LED_h_

0 commit comments

Comments
 (0)