Skip to content

Commit a820fc8

Browse files
committed
Updated for v4.0.0, first public release
1 parent f4fb5fb commit a820fc8

File tree

30 files changed

+1075
-45
lines changed

30 files changed

+1075
-45
lines changed

examples/01_DbncdMPBttn_1a/01_DbncdMPBttn_1a.ino

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
22
******************************************************************************
33
* @file : 01_DbncdMPBttn_1a.ino
4-
* @brief : Example for the ButtonToSwitch_AVR library DbncdMPBttn class
4+
* @brief : Example for the ButtonToSwitch library DbncdMPBttn class
55
*
66
* Framework: Arduino
77
* Platform: AVR
@@ -23,7 +23,7 @@
2323
* 07/10/2024 Last update
2424
*
2525
******************************************************************************
26-
* @attention This file is part of the examples folder for the ButtonToSwitch_AVR
26+
* @attention This file is part of the examples folder for the ButtonToSwitch
2727
* library. All files needed are provided as part of the source code for the library.
2828
*
2929
* Released into the public domain in accordance with "GPL-3.0-or-later" license terms.

examples/01_DbncdMPBttn_1b/01_DbncdMPBttn_1b.ino

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
22
******************************************************************************
33
* @file : 01_DbncdMPBttn_1b.ino
4-
* @brief : Example for the ButtonToSwitch_AVR library DbncdMPBttn class
4+
* @brief : Example for the ButtonToSwitch library DbncdMPBttn class
55
*
66
* Framework: Arduino
77
* Platform: AVR
@@ -11,7 +11,7 @@
1111
* - 1 led with it's corresponding resistor between GND and dmpbIsOnOtpt
1212
* - 1 led with it's corresponding resistor between GND and dmpbIsEnabledOtpt
1313
*
14-
* This simple example instantiates the SnglSrvcVdblMPBttn object in the setup(),
14+
* This simple example instantiates the DbncdMPBttn object in the setup(),
1515
* and then checks it's attributes flags through the getters methods in the
1616
* loop().
1717
*
@@ -32,7 +32,7 @@
3232
* 07/10/2024 Last update
3333
*
3434
******************************************************************************
35-
* @attention This file is part of the examples folder for the ButtonToSwitch_AVR
35+
* @attention This file is part of the examples folder for the ButtonToSwitch
3636
* library. All files needed are provided as part of the source code for the library.
3737
*
3838
* Released into the public domain in accordance with "GPL-3.0-or-later" license terms.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
/**
2+
******************************************************************************
3+
* @file : 01_DbncdMPBttn_1e.ino
4+
* @brief : Example for the ButtonToSwitch library DbncdMPBttn class
5+
*
6+
* Framework: Arduino
7+
* Platform: AVR
8+
*
9+
* The example instantiates a DbncdMPBttn object using:
10+
* - 1 push button between GND and dmpbMainInpt
11+
* - 1 led with it's corresponding resistor between GND and dmpbIsOnOtpt
12+
* - 1 led with it's corresponding resistor between GND and dmpbIsEnabledOtpt
13+
* - 1 led with it's corresponding resistor between GND and dmpbOnOffFnOtpt
14+
*
15+
* This simple example instantiates the DbncdMPBttn object in the setup(),
16+
* and then checks it's attributes flags through the getters methods in the
17+
* loop(). Two functions are added to be executed when the object's isOn
18+
* attribute flag value changes.
19+
*
20+
* The fnWhnTrnOn() will be called when the object enters the isOn=True state,
21+
* and fnWhnTrnOff() when the object enters the isOn=false state.
22+
* For this example purpose the functions code was kept to the bare minimum,
23+
* please keep in mind that for more complex and time consuming functions a valid
24+
* approach would be to treat the function as an INT callback execution: instead
25+
* of executing a complex and time consuming code in the function set flags and
26+
* values needed to identify the situation in the loop() and add the needed code
27+
* at it.
28+
*
29+
* When a change in the object's outputs attribute flags values is detected, it
30+
* manages the loads and resources that the switch turns On and Off, in this
31+
* example case are the output of some GPIO pins.
32+
*
33+
* A time controlling code section changes the isEnabled attribute of the MPBttn
34+
* after a time period, changing the MPBttn from enabled to disabled and then
35+
* back, to test the MPBttn behavior when enabling and disabling the MPBttn.
36+
*
37+
* Note: The setIsOnDisabled() method affects the behavior of the MPBttn when it
38+
* enters the Disabled state, check the documentation and experiment with it.
39+
*
40+
* @author : Gabriel D. Goldman
41+
*
42+
* @date : 01/08/2023 First release
43+
* 07/10/2024 Last update
44+
*
45+
******************************************************************************
46+
* @attention This file is part of the examples folder for the ButtonToSwitch
47+
* library. All files needed are provided as part of the source code for the library.
48+
*
49+
* Released into the public domain in accordance with "GPL-3.0-or-later" license terms.
50+
*
51+
******************************************************************************
52+
*/
53+
#include <Arduino.h>
54+
#include <ButtonToSwitch.h>
55+
56+
//==========================================>> BEGIN Function Prototypes
57+
void fnWhnTrnOn();
58+
void fnWhnTrnOff();
59+
//==========================================>> END Function Prototypes
60+
61+
//------------------------------> Inputs/Outputs related values
62+
const uint8_t dmpbMainInpt{6};
63+
const uint8_t dmpbIsOnOtpt{3};
64+
const uint8_t dmpbIsEnabledOtpt{4};
65+
const uint8_t dmpbOnOffFnOtpt{10};
66+
67+
//------------------------------> isEnabled state related values
68+
unsigned long int enbldOnOffTm{10000};
69+
unsigned long int lstEnblSwpTm{0};
70+
71+
//------------------------------> DbncdMPBttn class object instantiation
72+
DbncdMPBttn myDMPBttn (dmpbMainInpt);
73+
74+
void setup() {
75+
digitalWrite(dmpbIsOnOtpt, LOW);
76+
digitalWrite(dmpbIsEnabledOtpt, LOW);
77+
digitalWrite(dmpbOnOffFnOtpt, LOW);
78+
79+
pinMode(dmpbIsOnOtpt, OUTPUT);
80+
pinMode(dmpbIsEnabledOtpt, OUTPUT);
81+
pinMode(dmpbOnOffFnOtpt, OUTPUT);
82+
83+
myDMPBttn.setFnWhnTrnOnPtr(fnWhnTrnOn);
84+
myDMPBttn.setFnWhnTrnOffPtr(fnWhnTrnOff);
85+
myDMPBttn.setIsOnDisabled(false);
86+
myDMPBttn.begin(20);
87+
}
88+
89+
void loop() {
90+
if((millis() - lstEnblSwpTm) > enbldOnOffTm ){
91+
if(myDMPBttn.getIsEnabled() == true)
92+
myDMPBttn.disable();
93+
else
94+
myDMPBttn.enable();
95+
lstEnblSwpTm = millis();
96+
}
97+
98+
if(myDMPBttn.getOutputsChange()){ //This checking is done for saving resources, avoiding the rewriting of the pin value if there are no state changes in the MPB status
99+
digitalWrite(dmpbIsOnOtpt, (myDMPBttn.getIsOn())?HIGH:LOW);
100+
digitalWrite(dmpbIsEnabledOtpt, (myDMPBttn.getIsEnabled())?LOW:HIGH);
101+
myDMPBttn.setOutputsChange(false); //If the OutputChanges attibute flag is used, reset it's value to detect the next need to refresh outputs.
102+
}
103+
}
104+
105+
//==========================================>> BEGIN Functions declarations to executed when isOn status is modified
106+
void fnWhnTrnOn(){
107+
digitalWrite(dmpbOnOffFnOtpt, HIGH);
108+
109+
return;
110+
}
111+
112+
void fnWhnTrnOff(){
113+
digitalWrite(dmpbOnOffFnOtpt, LOW);
114+
115+
return;
116+
}
117+
//==========================================>> END Functions declarations to executed when isOn status is modified

examples/02_DbncdDlydMPBttn_1a/02_DbncdDlydMPBttn_1a.ino

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
22
******************************************************************************
33
* @file : 01_DbncdDlydMPBttn_1a.ino
4-
* @brief : Example for the ButtonToSwitch_AVR library DbncdDlydMPBttn class
4+
* @brief : Example for the ButtonToSwitch library DbncdDlydMPBttn class
55
*
66
* Framework: Arduino
77
* Platform: AVR
@@ -23,7 +23,7 @@
2323
* 07/10/2024 Last update
2424
*
2525
******************************************************************************
26-
* @attention This file is part of the examples folder for the ButtonToSwitch_AVR
26+
* @attention This file is part of the examples folder for the ButtonToSwitch
2727
* library. All files needed are provided as part of the source code for the library.
2828
*
2929
* Released into the public domain in accordance with "GPL-3.0-or-later" license terms.

examples/02_DbncdDlydMPBttn_1b/02_DbncdDlydMPBttn_1b.ino

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
22
******************************************************************************
33
* @file : 02_DbncdDlydMPBttn_1b.ino
4-
* @brief : Example for the ButtonToSwitch_AVR library DbncdDlydMPBttn class
4+
* @brief : Example for the ButtonToSwitch library DbncdDlydMPBttn class
55
*
66
* Framework: Arduino
77
* Platform: AVR
@@ -31,7 +31,7 @@
3131
* 07/10/2024 Last update
3232
*
3333
******************************************************************************
34-
* @attention This file is part of the examples folder for the ButtonToSwitch_AVR
34+
* @attention This file is part of the examples folder for the ButtonToSwitch
3535
* library. All files needed are provided as part of the source code for the library.
3636
*
3737
* Released into the public domain in accordance with "GPL-3.0-or-later" license terms.
@@ -59,6 +59,7 @@ void setup() {
5959

6060
myDMPBttn.setStrtDelay(200);
6161
myDMPBttn.setIsOnDisabled(false);
62+
6263
myDMPBttn.begin(40);
6364
}
6465

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
/**
2+
******************************************************************************
3+
* @file : 02_DbncdDlydMPBttn_1e.ino
4+
* @brief : Example for the ButtonToSwitch library DbncdDlydMPBttn class
5+
*
6+
* Framework: Arduino
7+
* Platform: AVR
8+
*
9+
* The example instantiates a DbncdDlydMPBttn object using:
10+
* - 1 push button between GND and dmpbMainInpt
11+
* - 1 led with it's corresponding resistor between GND and dmpbIsOnOtpt
12+
* - 1 led with it's corresponding resistor between GND and dmpbIsEnabledOtpt
13+
* - 1 led with it's corresponding resistor between GND and dmpbOnOffFnOtpt
14+
*
15+
* This simple example instantiates the DbncdDlydMPBttn object in the setup(),
16+
* and then checks it's attributes flags through the getters methods in the
17+
* loop(). Two functions are added to be executed when the object's isOn
18+
* attribute flag value changes.
19+
*
20+
* The fnWhnTrnOn() will be called when the object enters the isOn=True state,
21+
* and fnWhnTrnOff() when the object enters the isOn=false state.
22+
* For this example purpose the functions code was kept to the bare minimum,
23+
* please keep in mind that for more complex and time consuming functions a valid
24+
* approach would be to treat the function as an INT callback execution: instead
25+
* of executing a complex and time consuming code in the function set flags and
26+
* values needed to identify the situation in the loop() and add the needed code
27+
* at it.
28+
*
29+
* When a change in the object's outputs attribute flags values is detected, it
30+
* manages the loads and resources that the switch turns On and Off, in this
31+
* example case are the output of some GPIO pins.
32+
*
33+
* A time controlling code section changes the isEnabled attribute of the MPBttn
34+
* after a time period, changing the MPBttn from enabled to disabled and then
35+
* back, to test the MPBttn behavior when enabling and disabling the MPBttn.
36+
*
37+
* Note: The setIsOnDisabled() method affects the behavior of the MPBttn when it
38+
* enters the Disabled state, check the documentation and experiment with it.
39+
*
40+
* @author : Gabriel D. Goldman
41+
*
42+
* @date : 01/08/2023 First release
43+
* 07/10/2024 Last update
44+
*
45+
******************************************************************************
46+
* @attention This file is part of the examples folder for the ButtonToSwitch
47+
* library. All files needed are provided as part of the source code for the library.
48+
*
49+
* Released into the public domain in accordance with "GPL-3.0-or-later" license terms.
50+
*
51+
******************************************************************************
52+
*/
53+
#include <Arduino.h>
54+
#include <ButtonToSwitch.h>
55+
56+
//==========================================>> BEGIN Function Prototypes
57+
void fnWhnTrnOn();
58+
void fnWhnTrnOff();
59+
//==========================================>> END Function Prototypes
60+
61+
//------------------------------> Inputs/Outputs related values
62+
const uint8_t dmpbMainInpt{6};
63+
const uint8_t dmpbIsOnOtpt{3};
64+
const uint8_t dmpbIsEnabledOtpt{4};
65+
const uint8_t dmpbOnOffFnOtpt{10};
66+
67+
//------------------------------> isEnabled state related values
68+
unsigned long int enbldOnOffTm{10000};
69+
unsigned long int lstEnblSwpTm{0};
70+
71+
//------------------------------> DbncdDlydMPBttn class object instantiation
72+
DbncdDlydMPBttn myDMPBttn (dmpbMainInpt);
73+
74+
void setup() {
75+
digitalWrite(dmpbIsOnOtpt, LOW);
76+
digitalWrite(dmpbIsEnabledOtpt, LOW);
77+
digitalWrite(dmpbOnOffFnOtpt, LOW);
78+
79+
pinMode(dmpbIsOnOtpt, OUTPUT);
80+
pinMode(dmpbIsEnabledOtpt, OUTPUT);
81+
pinMode(dmpbOnOffFnOtpt, OUTPUT);
82+
83+
myDMPBttn.setFnWhnTrnOnPtr(fnWhnTrnOn);
84+
myDMPBttn.setFnWhnTrnOffPtr(fnWhnTrnOff);
85+
myDMPBttn.setStrtDelay(200);
86+
myDMPBttn.setIsOnDisabled(false);
87+
88+
myDMPBttn.begin(20);
89+
}
90+
91+
void loop() {
92+
if((millis() - lstEnblSwpTm) > enbldOnOffTm ){
93+
if(myDMPBttn.getIsEnabled() == true)
94+
myDMPBttn.disable();
95+
else
96+
myDMPBttn.enable();
97+
lstEnblSwpTm = millis();
98+
}
99+
100+
if(myDMPBttn.getOutputsChange()){ //This checking is done for saving resources, avoiding the rewriting of the pin value if there are no state changes in the MPB status
101+
digitalWrite(dmpbIsOnOtpt, (myDMPBttn.getIsOn())?HIGH:LOW);
102+
digitalWrite(dmpbIsEnabledOtpt, (myDMPBttn.getIsEnabled())?LOW:HIGH);
103+
myDMPBttn.setOutputsChange(false); //If the OutputChanges attibute flag is used, reset it's value to detect the next need to refresh outputs.
104+
}
105+
}
106+
107+
//==========================================>> BEGIN Functions declarations to executed when isOn status is modified
108+
void fnWhnTrnOn(){
109+
digitalWrite(dmpbOnOffFnOtpt, HIGH);
110+
111+
return;
112+
}
113+
114+
void fnWhnTrnOff(){
115+
digitalWrite(dmpbOnOffFnOtpt, LOW);
116+
117+
return;
118+
}
119+
//==========================================>> END Functions declarations to executed when isOn status is modified

examples/05_TgglLtchMPBttn_1a/05_TgglLtchMPBttn_1a.ino

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
22
******************************************************************************
33
* @file : 05_TgglLtchMPBttn_1a.ino
4-
* @brief : Example for the ButtonToSwitch_AVR library TgglLtchMPBttn class
4+
* @brief : Example for the ButtonToSwitch library TgglLtchMPBttn class
55
*
66
* Framework: Arduino
77
* Platform: AVR
@@ -23,7 +23,7 @@
2323
* 07/10/2024 Last update
2424
*
2525
******************************************************************************
26-
* @attention This file is part of the examples folder for the ButtonToSwitch_AVR
26+
* @attention This file is part of the examples folder for the ButtonToSwitch
2727
* library. All files needed are provided as part of the source code for the library.
2828
*
2929
* Released into the public domain in accordance with "GPL-3.0-or-later" license terms.

examples/05_TgglLtchMPBttn_1b/05_TgglLtchMPBttn_1b.ino

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
22
******************************************************************************
33
* @file : 05_TgglLtchMPBttn_1b.ino
4-
* @brief : Example for the ButtonToSwitch_AVR library TgglLtchMPBttn class
4+
* @brief : Example for the ButtonToSwitch library TgglLtchMPBttn class
55
*
66
* Framework: Arduino
77
* Platform: AVR
@@ -31,7 +31,7 @@
3131
* 07/10/2024 Last update
3232
*
3333
******************************************************************************
34-
* @attention This file is part of the examples folder for the ButtonToSwitch_AVR
34+
* @attention This file is part of the examples folder for the ButtonToSwitch
3535
* library. All files needed are provided as part of the source code for the library.
3636
*
3737
* Released into the public domain in accordance with "GPL-3.0-or-later" license terms.

0 commit comments

Comments
 (0)