Skip to content

Commit

Permalink
Allow button1 on pin 8 to 13 and A0 to A5 for ATmega328.
Browse files Browse the repository at this point in the history
  • Loading branch information
ArminJo committed Jan 4, 2021
1 parent f36451f commit 2f20c5e
Show file tree
Hide file tree
Showing 13 changed files with 366 additions and 266 deletions.
14 changes: 7 additions & 7 deletions .github/workflows/LibraryBuild.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,17 +38,17 @@ jobs:
- arduino:avr:uno
- arduino:avr:leonardo
- arduino:avr:mega
- digistump:avr:digispark-tiny1
- digistump:avr:digispark-tiny:clock=clock1
- digistump:avr:digispark-pro
- ATTinyCore:avr:attinyx5:chip=85,clock=1internal

# Choose the right platform for the boards we want to test. (maybe in the future Arduino will automatically do this for you)
# With examples-exclude you may exclude specific examples for a board. Use a comma separated list.
# With sketches-exclude you may exclude specific examples for a board. Use a comma separated list.
#############################################################################################################
include:
- arduino-boards-fqbn: digistump:avr:digispark-tiny1 # ATtiny85 board @1 MHz
- arduino-boards-fqbn: digistump:avr:digispark-tiny:clock=clock1 # ATtiny85 board @1 MHz
platform-url: https://raw.githubusercontent.com/ArminJo/DigistumpArduino/master/package_digistump_index.json
examples-build-properties:
build-properties:
EasyButtonExample:
-DTX_PIN=PB0

Expand All @@ -57,7 +57,7 @@ jobs:

- arduino-boards-fqbn: ATTinyCore:avr:attinyx5:chip=85,clock=1internal
platform-url: http://drazzy.com/package_drazzy.com_index.json
examples-build-properties:
build-properties:
EasyButtonExample:
-DTX_PIN=PB0

Expand All @@ -73,5 +73,5 @@ jobs:
with:
arduino-board-fqbn: ${{ matrix.arduino-boards-fqbn }}
platform-url: ${{ matrix.platform-url }}
examples-exclude: ${{ matrix.examples-exclude }}
examples-build-properties: ${{ toJson(matrix.examples-build-properties) }}
sketches-exclude: ${{ matrix.sketches-exclude }}
build-properties: ${{ toJson(matrix.build-properties) }}
23 changes: 13 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# [EasyButton](https://github.com/ArminJo/EasyButtonAtInt01)
Available as Arduino library "EasyButtonAtInt01"

### [Version 3.1.0](https://github.com/ArminJo/EasyButtonAtInt01/releases)
### [Version 3.2.0](https://github.com/ArminJo/EasyButtonAtInt01/releases)

[![License: GPL v3](https://img.shields.io/badge/License-GPLv3-blue.svg)](https://www.gnu.org/licenses/gpl-3.0)
[![Installation instructions](https://www.ardu-badge.com/badge/EasyButtonAtInt01.svg?)](https://www.ardu-badge.com/EasyButtonAtInt01)
Expand All @@ -11,10 +11,10 @@ Available as Arduino library "EasyButtonAtInt01"

Lightweight Arduino library for handling push buttons just connected between ground and INT0 and / or INT1 pin.<br/>
- No external pullup, **no polling needed**.
- The library is totally **based on interrupt** and **debouncing is implemented in a not blocking way**.
- The library is totally **based on interrupt** and **debouncing is implemented in a not blocking way**.
Debouncing is merely done by ignoring a button change within the debouncing time (default 50 ms).
So **button state is instantly available** without debouncing delay!
- Each button press toggles a state variable, so **no external logic for implementing a toggle button is needed**.
- Implements **toggle button** functionality.
- Support for **double press detection** is included. See [EasyButtonExample](examples/EasyButtonExample/EasyButtonExample.ino#L112) and [Callback example](examples/Callback/Callback.ino#L78).
- Support for **long press detection**, is included. See [Callback example](examples/Callback/Callback.ino#L98).
- Support for **active high buttons**.
Expand All @@ -24,12 +24,12 @@ So **button state is instantly available** without debouncing delay!
## Table of available pins for the 2 buttons
| CPU | Button 0 | Button 1 using INT1 | Button 1 using PCINT, if INT1_PIN is defined !=3 |
|-|-|-|-|
| ATmega328* | D2 | D3 | Pin 0 to 2, 4 to 7 |
| ATmega328* | D2 | D3 | Pin 0 to 2, 4 to 13, A0 to A5 |
| ATtiny5x | PB2 | | PB0 - PB5 |
| ATtiny167 | PB6 | PA3 | PA0 to PA2, PA4 to PA7 |

To use the PCINT buttons instead of the default one, just define INT1_PIN **before** including *EasyButtonAtInt01.cpp.h*.<br/>
E.g. `#define INT1_PIN 7`. See [EasyButtonExample.cpp](examples/EasyButtonExample/EasyButtonExample.ino#L46).
E.g. `#define INT1_PIN 7`. See [EasyButtonExample.cpp](examples/EasyButtonExample/EasyButtonExample.ino#L52).

## Usage
To use a single button, it needs only:
Expand Down Expand Up @@ -70,7 +70,7 @@ void loop() {
The button press callback function is is called on every button press with ButtonToggleState as parameter.<br/>
**The value at the first call (after first press) is true**.<br/>
The button release callback function is called on every button release with the additional parameter ButtonPressDurationMillis.<br/>
Both callback functions run in an interrupt service context, which means they should be as short as possible.
Both callback functions run in an interrupt service context, which means they should be as short as possible.
But before a callback function is called, interrupts are enabled.
This allows the timer interrupt for millis() to work and therfore **delay() and millis() can be used in a callback function**.

Expand Down Expand Up @@ -136,11 +136,11 @@ void loop() {}

## Handling the `multiple definition` error
If you get the error `multiple definition of __vector_1` (or `__vector_2`) because another library uses the attachInterrupt() function,
then comment out the line `#define USE_ATTACH_INTERRUPT` in *EasyButtonAtInt01.h* or
then activate the line `#define USE_ATTACH_INTERRUPT` in *EasyButtonAtInt01.h* or
define global symbol with `-DUSE_ATTACH_INTERRUPT` which is not yet possible in Arduino IDE:-(.<br/>

## Consider to use [Sloeber](http://eclipse.baeyens.it/stable.php?OS=Windows) as IDE<br/>
If you are using Sloeber as your IDE, you can easily define global symbols at *Properties/Arduino/CompileOptions*.<br/>
## Consider using [Sloeber](http://eclipse.baeyens.it/stable.php?OS=Windows) as IDE<br/>
If you are using Sloeber as your IDE, you can easily define global symbols at *Properties > Arduino > CompileOptions*.<br/>

## Class methods
```
Expand All @@ -165,6 +165,9 @@ bool checkForForButtonNotPressedTime(uint16_t aTimeoutMillis);
```

# Revision History
### Version 3.2.0
- Allow button1 on pin 8 to 13 and A0 to A5 for ATmega328.

### Version 3.1.0
- 2 sets of constructors, one for only one button used and one for the second button if two buttons used.
- Map pin numbers for Digispark pro boards, for use with with digispark library.
Expand Down Expand Up @@ -196,7 +199,7 @@ The library examples are tested with GitHub Actions for the following boards:

- arduino:avr:uno
- arduino:avr:leonardo
- arduino:avr:mega
- arduino:avr:mega
- digistump:avr:digispark-tiny1
- digistump:avr:digispark-pro
- ATTinyCore:avr:attinyx5:chip=85,clock=1internal
Expand Down
13 changes: 6 additions & 7 deletions examples/Callback/Callback.ino
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,8 @@ void setup() {
pinMode(LED_BUILTIN, OUTPUT);

Serial.begin(115200);
#if defined(__AVR_ATmega32U4__)
while (!Serial)
; //delay for Leonardo
#if defined(__AVR_ATmega32U4__) || defined(SERIAL_USB) || defined(SERIAL_PORT_USBVIRTUAL)
delay(2000); // To be able to connect Serial monitor after reset and before first printout
#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__));
Expand All @@ -61,8 +60,8 @@ void loop() {
delay(10);
}

void blinkLEDBlocking(uint8_t aLedPin, uint16_t aDelay, uint8_t aRepetitions) {
for (uint8_t i = 0; i < aRepetitions; ++i) {
void blinkLEDBlocking(uint8_t aLedPin, uint8_t aBlinkCount, uint16_t aDelay) {
for (int i = 0; i < aBlinkCount; ++i) {
digitalWrite(aLedPin, HIGH);
delay(aDelay);
digitalWrite(aLedPin, LOW);
Expand All @@ -84,7 +83,7 @@ void handleButtonPress(bool aButtonToggleState) {
Serial.println(F(" ms detected"));

// let the led blink twice short
blinkLEDBlocking(LED_BUILTIN, BLINK_SHORT_MILLIS, 2);
blinkLEDBlocking(2, LED_BUILTIN, BLINK_SHORT_MILLIS);
Button0AtPin2.ButtonToggleState = false;
}
Serial.println(F("Button pressed"));
Expand All @@ -104,7 +103,7 @@ void handleButtonRelease(bool aButtonToggleState, uint16_t aButtonPressDurationM
Serial.println(F(" ms detected"));

// let the led blink long
blinkLEDBlocking(LED_BUILTIN, BLINK_LONG_MILLIS, 2);
blinkLEDBlocking(2, LED_BUILTIN, BLINK_LONG_MILLIS);
Button0AtPin2.ButtonToggleState = false;
}
}
5 changes: 2 additions & 3 deletions examples/DebounceTest/DebounceTest.ino
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,8 @@ void setup() {
pinMode(LED_BUILTIN, OUTPUT);

Serial.begin(115200);
#if defined(__AVR_ATmega32U4__)
while (!Serial)
; //delay for Leonardo
#if defined(__AVR_ATmega32U4__) || defined(SERIAL_USB) || defined(SERIAL_PORT_USBVIRTUAL)
delay(2000); // To be able to connect Serial monitor after reset and before first printout
#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__));
Expand Down
Loading

0 comments on commit 2f20c5e

Please sign in to comment.