Skip to content

Commit 0616e34

Browse files
committed
new file: .github/Compile-Examples.yml
new file: .github/Spell-Check.yml renamed: .github/workflows/arduino.yml -> .github/workflows/Arduino-Lint-Action.yml modified: README.md modified: examples/Button/Button.ino modified: examples/ResetSet/ResetSet.ino modified: examples/Toggle/Toggle.ino modified: library.properties modified: src/ADebouncer.h
1 parent 03cfd82 commit 0616e34

File tree

9 files changed

+226
-8
lines changed

9 files changed

+226
-8
lines changed

.github/Compile-Examples.yml

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
name: Compile Examples
2+
3+
# See: https://docs.github.com/en/free-pro-team@latest/actions/reference/events-that-trigger-workflows
4+
on:
5+
push:
6+
paths:
7+
- ".github/workflows/compile-examples.yml"
8+
- "examples/**"
9+
- "src/**"
10+
pull_request:
11+
paths:
12+
- ".github/workflows/compile-examples.yml"
13+
- "examples/**"
14+
- "src/**"
15+
schedule:
16+
# Run every Tuesday at 8 AM UTC to catch breakage caused by changes to external resources (libraries, platforms).
17+
- cron: "0 8 * * TUE"
18+
workflow_dispatch:
19+
repository_dispatch:
20+
21+
jobs:
22+
build:
23+
name: ${{ matrix.board.fqbn }}
24+
runs-on: ubuntu-latest
25+
26+
env:
27+
SKETCHES_REPORTS_PATH: sketches-reports
28+
29+
strategy:
30+
fail-fast: false
31+
32+
matrix:
33+
board:
34+
- fqbn: arduino:avr:nano
35+
platforms: |
36+
- name: arduino:avr
37+
artifact-name-suffix: arduino-avr-nano
38+
- fqbn: arduino:avr:mega
39+
platforms: |
40+
- name: arduino:avr
41+
artifact-name-suffix: arduino-avr-mega
42+
- fqbn: arduino:avr:leonardo
43+
platforms: |
44+
- name: arduino:avr
45+
artifact-name-suffix: arduino-avr-leonardo
46+
- fqbn: arduino:megaavr:nona4809
47+
platforms: |
48+
- name: arduino:megaavr
49+
artifact-name-suffix: arduino-megaavr-nona4809
50+
- fqbn: arduino:sam:arduino_due_x_dbg
51+
platforms: |
52+
- name: arduino:sam
53+
artifact-name-suffix: arduino-sam-arduino_due_x_dbg
54+
- fqbn: arduino:samd:mkrzero
55+
platforms: |
56+
- name: arduino:samd
57+
artifact-name-suffix: arduino-samd-mkrzero
58+
- fqbn: arduino:mbed_portenta:envie_m7:target_core=cm4
59+
platforms: |
60+
- name: arduino:mbed_portenta
61+
artifact-name-suffix: arduino-mbed_portenta-envie_m7-target_core-cm4
62+
- fqbn: arduino:mbed_portenta:envie_m7
63+
platforms: |
64+
- name: arduino:mbed_portenta
65+
artifact-name-suffix: arduino-mbed_portenta-envie_m7
66+
- fqbn: arduino:mbed_nano:nano33ble
67+
platforms: |
68+
- name: arduino:mbed_nano
69+
artifact-name-suffix: arduino-mbed_nano-nano33ble
70+
- fqbn: arduino:mbed_nano:nanorp2040connect
71+
platforms: |
72+
- name: arduino:mbed_nano
73+
artifact-name-suffix: arduino-mbed_nano-nanorp2040connect
74+
75+
steps:
76+
- name: Checkout repository
77+
uses: actions/checkout@v4
78+
79+
- name: Compile examples
80+
uses: arduino/compile-sketches@v1
81+
with:
82+
github-token: ${{ secrets.GITHUB_TOKEN }}
83+
fqbn: ${{ matrix.board.fqbn }}
84+
platforms: ${{ matrix.board.platforms }}
85+
libraries: |
86+
# Install the library from the local path.
87+
- source-path: ./
88+
# Additional library dependencies can be listed here.
89+
# See: https://github.com/arduino/compile-sketches#libraries
90+
sketch-paths: |
91+
- examples
92+
enable-deltas-report: true
93+
sketches-report-path: ${{ env.SKETCHES_REPORTS_PATH }}
94+
95+
- name: Save sketches report as workflow artifact
96+
uses: actions/upload-artifact@v4
97+
with:
98+
if-no-files-found: error
99+
path: ${{ env.SKETCHES_REPORTS_PATH }}
100+
name: sketches-report-${{ matrix.board.artifact-name-suffix }}

.github/Spell-Check.yml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
name: Spell Check
2+
3+
# See: https://docs.github.com/en/free-pro-team@latest/actions/reference/events-that-trigger-workflows
4+
on:
5+
push:
6+
pull_request:
7+
schedule:
8+
# Run every Tuesday at 8 AM UTC to catch new misspelling detections resulting from dictionary updates.
9+
- cron: "0 8 * * TUE"
10+
workflow_dispatch:
11+
repository_dispatch:
12+
13+
jobs:
14+
spellcheck:
15+
runs-on: ubuntu-latest
16+
17+
steps:
18+
- name: Checkout repository
19+
uses: actions/checkout@v4
20+
21+
- name: Spell check
22+
uses: codespell-project/actions-codespell@master

.github/workflows/arduino.yml renamed to .github/workflows/Arduino-Lint-Action.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: ArduinoLintAction
1+
name: Arduino Lint Action
22

33
# Controls when the workflow will run
44
on:
@@ -21,10 +21,10 @@ jobs:
2121
# Steps represent a sequence of tasks that will be executed as part of the job
2222
steps:
2323
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
24-
- uses: actions/checkout@v3
25-
24+
- uses: actions/checkout@v4
25+
2626
# Arduino Lint
2727
- uses: arduino/arduino-lint-action@v1
2828
with:
2929
library-manager: update
30-
compliance: strict
30+
compliance: strict

README.md

Lines changed: 74 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
# Advanced-Debouncer
2+
[![Arduino-Lint-Action](https://github.com/MicroBeaut/ADebouncer/actions/workflows/Arduino-Lint-Action.yml/badge.svg)](https://github.com/MicroBeaut/ADebouncer/actions/workflows/Arduino-Lint-Action.yml)
3+
[![Spell-Check](https://github.com/MicroBeaut/ADebouncer/actions/workflows/Spell-Check.yml/badge.svg)](https://github.com/MicroBeaut/ADebouncer/actions/workflows/Spell-Check.yml)
4+
[![Compile-Examples](https://github.com/MicroBeaut/ADebouncer/actions/workflows/Compile-Examples.yml/badge.svg)](https://github.com/MicroBeaut/ADebouncer/actions/workflows/Compile-Examples.yml)
5+
![Github](https://img.shields.io/github/v/release/MicroBeaut/ADebouncer)
26
The advanced debounce removes the resulting ripple signal and provides a clean transition at its output with `delayed` and `instant` modes.
37

48
## Delayed Mode
59
The delayed mode responds to the signal to update the output when input is stable for the fully qualified debounce period.
610
<p align="center">
7-
<img src="./images/adebouncer-delayed.svg" width="100%" />
11+
<img src="./images/adebouncer-delayed.svg" width="%" />
812
<h3 align="center">Delayed Mode Timing Diagram</h3>
913
</p>
1014

@@ -156,11 +160,52 @@ if (debouncer.falling()) toggle = !toggle;
156160
Declare debounce mode as delayed mode. Debounce the input signal from the button and update LED_BUILTIN with the debounced state.
157161

158162
Click [ here](examples/Button/Button.ino) the Button sketch.
163+
```c
164+
#include "ADebouncer.h"
165+
166+
#define buttonPin 2 // Define the button input pin.
167+
#define debouncePeroid 10 // Define the debounce period in milliseconds
168+
169+
ADebouncer debouncer; // Declare debouncer variable.
170+
171+
void setup() {
172+
pinMode(buttonPin, INPUT_PULLUP); // Set the button mode as input pullup.
173+
pinMode(LED_BUILTIN, OUTPUT); // Set the LED_BUILTIN mode as output.
174+
debouncer.mode(DELAYED, debouncePeroid, HIGH); // Set the debounce mode as delayed mode and debounce period as 10 ms, with the initial output in a HIGH state.
175+
}
176+
177+
void loop() {
178+
bool buttonState = debouncer.debounce(digitalRead(buttonPin)); // Save the debounced of the button state.
179+
digitalWrite(LED_BUILTIN, buttonState); // Update LED_BUILTIN with the button state.
180+
}
181+
```
159182

160183
## Toggle
161184
Declare debounce mode as delayed mode. Debounce the input signal from the button. Toggle the state when pressing the button and update LED_BUILTIN with the toggle state.
162185

163186
Click [ here](examples/Toggle/Toggle.ino) the Toggle sketch.
187+
```c
188+
#include "ADebouncer.h"
189+
190+
#define buttonPin 12 // Define the button input pin.
191+
#define debouncePeroid 10 // Define the debounce period in milliseconds
192+
193+
ADebouncer debouncer; // Declare debouncer variable.
194+
bool state; // Declare state variable.
195+
196+
void setup() {
197+
pinMode(buttonPin, INPUT_PULLUP); // Set the button mode as input pullup.
198+
pinMode(LED_BUILTIN, OUTPUT); // Set the LED_BUILTIN mode as output.
199+
debouncer.mode(DELAYED, debouncePeroid, HIGH); // Set the debounce mode as delayed mode and debounce period, with the initial output in a HIGH state.
200+
state = HIGH; // Initial state in a HIGH state.
201+
}
202+
203+
void loop() {
204+
debouncer.debounce(digitalRead(buttonPin)); // Debounce input of the button state.
205+
if (debouncer.falling()) state = !state; // Toggle state of the state variable.
206+
digitalWrite(LED_BUILTIN, state); // Update LED_BUILTIN with the state.
207+
}
208+
```
164209

165210
## ResetSet
166211
This example is designed to have a set button and a reset button to Reset-Set the state.
@@ -173,4 +218,31 @@ Both set and reset buttons have the same debounce period. in this example, will
173218

174219
The LED_BUILTIN will be updated with the state value.
175220

176-
Click [ here](examples/ResetSet/ResetSet.ino) the ResetSet sketch.
221+
Click [ here](examples/ResetSet/ResetSet.ino) the ResetSet sketch.
222+
```c
223+
#include "ADebouncer.h"
224+
225+
#define setPin 12 // Define the set input pin.
226+
#define resetPin 11 // Define the reset input pin.
227+
#define debouncePeroid 1000 // Define the debounce period in milliseconds
228+
229+
ADebouncer setButton; // Declare set debouncer variable.
230+
ADebouncer resetButton; // Declare reset debouncer variable.
231+
bool state; // Declare state variable for ResetSet.
232+
233+
void setup() {
234+
pinMode(setPin, INPUT_PULLUP); // Set the button mode as input pullup.
235+
pinMode(resetPin, INPUT_PULLUP); // Set the button mode as input pullup.
236+
pinMode(LED_BUILTIN, OUTPUT); // Set the LED_BUILTIN mode as output.
237+
setButton.mode(DELAYED, debouncePeroid, HIGH); // Set the debounce mode as delayed mode and debounce period, with the initial output in a HIGH state.
238+
resetButton.mode(INSTANT, debouncePeroid, HIGH); // Set the debounce mode as instant mode and debounce period, with the initial output in a HIGH state.
239+
state = LOW; // Initial state in a LOW state.
240+
}
241+
242+
void loop() {
243+
setButton.debounce(digitalRead(setPin)); // Debounce input of the set button state.
244+
resetButton.debounce(digitalRead(resetPin)); // Debounce input of the reset button state.
245+
state = (state | !setButton.debounced()) & resetButton.debounced(); // Reset and Set the state
246+
digitalWrite(LED_BUILTIN, state); // Update LED_BUILTIN with the state.
247+
}
248+
```

examples/Button/Button.ino

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
/*
2+
Declare debounce mode as delayed mode.
3+
Debounce the input signal from the button
4+
and update LED_BUILTIN with the debounced state.
5+
*/
6+
17
#include "ADebouncer.h"
28

39
#define buttonPin 2 // Define the button input pin.

examples/ResetSet/ResetSet.ino

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
/*
2+
Declare debounce mode as delayed mode.
3+
Debounce the input signal from the button.
4+
Toggle the state when pressing the button and update LED_BUILTIN with the toggle state.
5+
*/
6+
17
#include "ADebouncer.h"
28

39
#define setPin 12 // Define the set input pin.

examples/Toggle/Toggle.ino

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,15 @@
1+
/*
2+
This example is designed to have a set button and a reset button to Reset-Set the state.
3+
- Declare debouncer for the set button. set the debounce as a delayed mode
4+
- Declare debouncer for the reset button. Set the debounce as an instant mode
5+
6+
Both set and reset buttons have the same debounce period. in this example, will be set to debounce period for 1 second,
7+
- To set the state, press the set button for 1 second.
8+
- To reset the state, the state will be instantly reset after pressing the reset button.
9+
10+
The LED_BUILTIN will be updated with the state value.
11+
*/
12+
113
#include "ADebouncer.h"
214

315
#define buttonPin 12 // Define the button input pin.

library.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name=ADebouncer
2-
version=1.1.0
2+
version=1.1.1
33
author=MicroBeaut
44
maintainer=MicroBeaut
55
sentence=Advanced Debouncer Library for Arduino.

src/ADebouncer.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
#include <Arduino.h>
1414

15-
#define ADEBOUNCER_VERSION "1.1.0"
15+
#define ADEBOUNCER_VERSION "1.1.1"
1616
#define ADEBOUNCER_AUTHOR "MicroBeaut"
1717

1818
enum debounce_t : boolean {DELAYED, INSTANT};

0 commit comments

Comments
 (0)