-
Notifications
You must be signed in to change notification settings - Fork 1
/
DebounceTest.ino
83 lines (72 loc) · 3.19 KB
/
DebounceTest.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
/*
* DebounceTest.cpp
*
* Test button with reduced debounce time.
* If one bounce is not suppressed, the internal LED sometimes toggles because of bouncing.
*
* Copyright (C) 2018 Armin Joachimsmeyer
* armin.joachimsmeyer@gmail.com
*
* This file is part of EasyButtonAtInt01 https://github.com/ArminJo/EasyButtonAtInt01.
*
* EasyButtonAtInt01 is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/gpl.html>.
*
*/
#include <Arduino.h>
//#define USE_ATTACH_INTERRUPT // enable it if you get the error " multiple definition of `__vector_1'" (or `__vector_2')
//#define MEASURE_INTERRUPT_TIMING
#define ANALYZE_MAX_BOUNCING_PERIOD
#define BUTTON_DEBOUNCING_MILLIS 2
#define USE_BUTTON_0 // Enable code for 1. button at INT0
#include "EasyButtonAtInt01.hpp"
EasyButton Button0AtPin2; // Only 1. button (USE_BUTTON_0) enabled -> button is connected to INT0
#if defined(ARDUINO_AVR_DIGISPARK)
#define LED_BUILTIN PB1
#elif defined(ARDUINO_AVR_DIGISPARKPRO)
// On a Digispark Pro we have PB1 / D9 / PCB pin 1
#define LED_BUILTIN (9)
#elif ! defined(LED_BUILTIN)
#define LED_BUILTIN PB1 // define port of built in LED for your ATtiny
#endif
#define STR_HELPER(x) #x
#define STR(x) STR_HELPER(x)
void setup() {
// initialize the digital pin as an output.
pinMode(LED_BUILTIN, OUTPUT);
Serial.begin(115200);
#if defined(__AVR_ATmega32U4__) || defined(SERIAL_PORT_USBVIRTUAL) || defined(SERIAL_USB) /*stm32duino*/|| defined(USBCON) /*STM32_stm32*/ \
|| defined(SERIALUSB_PID) || defined(ARDUINO_ARCH_RP2040) || defined(ARDUINO_attiny3217)
delay(4000); // To be able to connect Serial monitor after reset or power up and before first print out. Do not wait for an attached Serial Monitor!
#endif
// Just to know which program is running on my Arduino
Serial.println(F("START " __FILE__ "\r\nUsing library version " VERSION_EASY_BUTTON " from " __DATE__));
Serial.print(F("Button pin="));
Serial.println(INT0_PIN);
Serial.println(F("Button debouncing time is reduced to " STR(BUTTON_DEBOUNCING_MILLIS) " ms"));
Serial.println(F("Please press the button and watch for \"Bouncing, MBP=...\" output at the Serial Monitor"));
}
void loop() {
digitalWrite(LED_BUILTIN, Button0AtPin2.ButtonToggleState);
if (Button0AtPin2.ButtonStateHasJustChanged) {
Button0AtPin2.ButtonStateHasJustChanged = false; // Acknowledge button state change flag
/*
* Print new status
*/
Serial.print(F("Button1 IsActive="));
Serial.print(Button0AtPin2.getButtonStateIsActive());
Serial.print(F(" ToggleState="));
Serial.println(Button0AtPin2.ButtonToggleState);
}
delay(10);
}