Skip to content

Commit

Permalink
Renamed EasyButtonAtInt01.cpp.h to EasyButtonAtInt01.hpp. Bumped vers…
Browse files Browse the repository at this point in the history
…ion to 3.3.0
  • Loading branch information
ArminJo committed Sep 15, 2021
1 parent 4fbaefd commit 313c819
Show file tree
Hide file tree
Showing 12 changed files with 804 additions and 719 deletions.
21 changes: 10 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,15 @@ So **button state is instantly available** without debouncing delay!
| 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/>
To use the PCINT buttons instead of the default one, just define INT1_PIN **before** including *EasyButtonAtInt01.hpp*.<br/>
E.g. `#define INT1_PIN 7`. See [EasyButtonExample.cpp](examples/EasyButtonExample/EasyButtonExample.ino#L52).

## Usage
To use a single button, it needs only:

```
#define USE_BUTTON_0 // Enable code for button at INT0 (pin2)
#include "EasyButtonAtInt01.cpp.h"
#include "EasyButtonAtInt01.hpp"
EasyButton Button0AtPin2;
void setup() {}
Expand All @@ -51,7 +51,7 @@ To use 2 buttons, it needs only:
```
#define USE_BUTTON_0 // Enable code for button at INT0 (pin2)
#define USE_BUTTON_1 // Enable code for button at INT1 (pin3) or PCINT[0:7]
#include "EasyButtonAtInt01.cpp.h"
#include "EasyButtonAtInt01.hpp"
EasyButton Button0AtPin2(); // no parameter -> Button is connected to INT0 (pin2)
EasyButton Button1AtPin3(BUTTON_AT_INT1_OR_PCINT); // Button is connected to INT1 (pin3)
Expand All @@ -69,14 +69,13 @@ void loop() {
## Usage of callback functions
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.
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**.
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/fast as possible.
In this library, interrupts are enabled before the callback function is called. This allows the timer interrupt for millis() to work and therfore **delay() and millis() can be used in a callback function**.

```
#define USE_BUTTON_0 // Enable code for button at INT0 (pin2)
#include "EasyButtonAtInt01.cpp.h"
#include "EasyButtonAtInt01.hpp"
// Initial value is false, so first call is with true
void handleButtonPress(bool aButtonToggleState) {
Expand All @@ -93,7 +92,7 @@ The easiest way is to check it in the button release handler. Do not forget, tha

```
#define USE_BUTTON_0 // Enable code for button at INT0 (pin2)
#include "EasyButtonAtInt01.cpp.h"
#include "EasyButtonAtInt01.hpp"
void handleButtonRelease(bool aButtonToggleState, uint16_t aButtonPressDurationMillis);
EasyButton Button0AtPin2(NULL, &handleButtonRelease); // Button is connected to INT0 (pin2)
Expand All @@ -116,7 +115,7 @@ Call checkForDoublePress() only from button press callback function. It will not

```
#define USE_BUTTON_0 // Enable code for button at INT0 (pin2)
#include "EasyButtonAtInt01.cpp.h"
#include "EasyButtonAtInt01.hpp"
void handleButtonPress(bool aButtonToggleState);
EasyButton Button0AtPin2(&printButtonToggleState);
Expand Down Expand Up @@ -189,7 +188,7 @@ bool checkForForButtonNotPressedTime(uint16_t aTimeoutMillis);
- Analyzes maximum debouncing period.
- Double button press detection support.
- Very short button press handling.
- Renamed to EasyButtonAtInt01.cpp.h
- Renamed to EasyButtonAtInt01.hpp

### Version 1.0.0
- initial version for ATmega328.
Expand Down
4 changes: 2 additions & 2 deletions examples/Callback/Callback.ino
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
//#define USE_ATTACH_INTERRUPT // enable it if you get the error " multiple definition of `__vector_1'" (or `__vector_2')

#define USE_BUTTON_0 // Enable code for 1. button at INT0 (pin2)
#include "EasyButtonAtInt01.cpp.h"
#include "EasyButtonAtInt01.hpp"

void handleButtonPress(bool aButtonToggleState); // The button press callback function
void handleButtonRelease(bool aButtonToggleState, uint16_t aButtonPressDurationMillis);
Expand All @@ -50,7 +50,7 @@ void setup() {

Serial.begin(115200);
#if defined(__AVR_ATmega32U4__) || defined(SERIAL_USB) || defined(SERIAL_PORT_USBVIRTUAL) || defined(ARDUINO_attiny3217)
delay(4000); // To be able to connect Serial monitor after reset or power up and before first printout
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__));
Expand Down
4 changes: 2 additions & 2 deletions examples/DebounceTest/DebounceTest.ino
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
#define BUTTON_DEBOUNCING_MILLIS 2

#define USE_BUTTON_0 // Enable code for 1. button at INT0
#include "EasyButtonAtInt01.cpp.h"
#include "EasyButtonAtInt01.hpp"

EasyButton Button0AtPin2; // Only 1. button (USE_BUTTON_0) enabled -> button is connected to INT0

Expand All @@ -54,7 +54,7 @@ void setup() {

Serial.begin(115200);
#if defined(__AVR_ATmega32U4__) || defined(SERIAL_USB) || defined(SERIAL_PORT_USBVIRTUAL) || defined(ARDUINO_attiny3217)
delay(4000); // To be able to connect Serial monitor after reset or power up and before first printout
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__));
Expand Down
58 changes: 45 additions & 13 deletions examples/EasyButtonExample/ATtinySerialOut.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* ATtinySerialOut.h
*
* Copyright (C) 2015-2020 Armin Joachimsmeyer
* Copyright (C) 2015-2021 Armin Joachimsmeyer
* Email: [email protected]
*
* This file is part of TinySerialOut https://github.com/ArminJo/ATtinySerialOut.
Expand Down Expand Up @@ -33,7 +33,7 @@

// ATMEL ATTINY167
// Pin numbers are for Digispark core
// Pin numbers in Parenthesis are for ATTinyCore
// Pin numbers in parenthesis are for ATTinyCore
//
// +-\/-+
// RX 6 (0) PA0 1| |20 PB0 (D8) 0 OC1AU TONE Timer 1 Channel A
Expand All @@ -49,28 +49,52 @@
// +----+
//

// MH-ET LIVE Tiny88 (16.0MHz) board
// Digital Pin numbers in parenthesis are for ATTinyCore library
// USB
// +-\__/-+
// PA2 15| |14 PB7
// PA3 16| |13 PB5 SCK
// 17 PA0 A6| |12 PB4 MISO
// 18 PA1 A7| |11 PB3 MOSI
// (D17) 19 PC0 A0| |10 PB2 OC1B/PWM SS
// (D18) 20 PC1 A1| |9 PB1 OC1A/PWM
// (D19) 21 PC2 A2| |8 PB0
// (D20) 22 PC3 A3| |7 PD7 RX
//SDA (D21) 23 PC4 A4| |6 PD6 TX
//SCL (D22) 24 PC5 A5| |5 PD5
// (D23) PC1 25| |4 PD4
//RESET PC6 RST| |3 PD3 INT1
//LED PD0 0| |5V
//USB+ PD1 1| |GND
//USB- INT0 PD2 2| |VIN
// +------+

#ifndef ATTINY_SERIAL_OUT_H_
#define ATTINY_SERIAL_OUT_H_

#if defined(__AVR_ATtiny25__) || defined(__AVR_ATtiny45__) || defined(__AVR_ATtiny85__) \
|| defined(__AVR_ATtiny24__) || defined(__AVR_ATtiny44__) || defined(__AVR_ATtiny84__) \
|| defined(__AVR_ATtiny87__) || defined(__AVR_ATtiny167__)
|| defined(__AVR_ATtiny87__) || defined(__AVR_ATtiny167__) \
|| defined(__AVR_ATtiny88__)
#include <Arduino.h>

#define VERSION_ATTINY_SERIAL_OUT "1.2.1"
#define VERSION_ATTINY_SERIAL_OUT_MAJOR 1
#define VERSION_ATTINY_SERIAL_OUT_MINOR 2
#define VERSION_ATTINY_SERIAL_OUT "2.0.0"
#define VERSION_ATTINY_SERIAL_OUT_MAJOR 2
#define VERSION_ATTINY_SERIAL_OUT_MINOR 0

#if (F_CPU != 1000000) && (F_CPU != 8000000) && (F_CPU != 16000000)
#error F_CPU value must be 1000000, 8000000 or 16000000.
#endif

#if defined(__AVR_ATtiny87__) || defined(__AVR_ATtiny167__)
# ifndef TX_PIN
#if !defined(TX_PIN)
# if defined(__AVR_ATtiny87__) || defined(__AVR_ATtiny167__) // Digispark PRO board
#define TX_PIN PA1 // (package pin 2 / TXD on Tiny167) - can use one of PA0 to PA7 here
# endif
#else // defined(__AVR_ATtiny87__) || defined(__AVR_ATtiny167__)
# ifndef TX_PIN

# elif defined(__AVR_ATtiny88__) // MH-ET LIVE Tiny88(16.0MHz) board
#define TX_PIN PD6 // (board pin 6) - can use one of PD3 to PD7 here

# else // Tiny X4 + X5 Digispark board
#define TX_PIN PB2 // (package pin 7 on Tiny85) - can use one of PB0 to PB4 (+PB5) here
# endif
#endif
Expand All @@ -86,7 +110,7 @@
* @8/16 MHz use 115200 baud instead of 230400 baud.
*/
//#define TINY_SERIAL_DO_NOT_USE_115200BAUD
#ifndef TINY_SERIAL_DO_NOT_USE_115200BAUD // define this to force using other baud rates
#if !defined(TINY_SERIAL_DO_NOT_USE_115200BAUD) // define this to force using other baud rates
#define USE_115200BAUD
#endif

Expand Down Expand Up @@ -128,7 +152,11 @@ void writeFloat(double aFloat, uint8_t aDigits);

char nibbleToHex(uint8_t aByte);

#if defined(TINY_SERIAL_INHERIT_FROM_PRINT)
class TinySerialOut: public Print
#else
class TinySerialOut
#endif
{
public:

Expand All @@ -145,6 +173,7 @@ class TinySerialOut
size_t write(uint8_t aByte);
operator bool(); // To support "while (!Serial); // wait for serial port to connect. Required for Leonardo only

#if !defined(TINY_SERIAL_INHERIT_FROM_PRINT)
void print(const __FlashStringHelper *aStringPtr);
void print(const char *aStringPtr);
void print(char aChar);
Expand All @@ -166,13 +195,14 @@ class TinySerialOut
void println(double aFloat, uint8_t aDigits = 2);

void println(void);
#endif // TINY_SERIAL_INHERIT_FROM_PRINT

};

// #if ... to be compatible with ATTinyCores and AttinyDigisparkCores
#if (!defined(UBRRH) && !defined(UBRR0H)) /*AttinyDigisparkCore and AttinyDigisparkCore condition*/ \
|| USE_SOFTWARE_SERIAL /*AttinyDigisparkCore condition*/\
|| ((defined(UBRRH) || defined(UBRR0H) || defined(UBRR1H) || defined(LINBRRH)) && !USE_SOFTWARE_SERIAL)/*AttinyDigisparkCore condition for HardwareSerial*/
|| ((defined(UBRRH) || defined(UBRR0H) || defined(UBRR1H) || (defined(LINBRRH)) && !USE_SOFTWARE_SERIAL))/*AttinyDigisparkCore condition for HardwareSerial*/
// Switch to SerialOut since Serial is already defined
// or activate line 745 in TinyDebugSerial.h included in AttinyDigisparkCores/src/tiny/WProgram.h at line 24 for AttinyDigisparkCores
extern TinySerialOut SerialOut;
Expand All @@ -183,7 +213,9 @@ extern TinySerialOut SerialOut;
# endif
extern TinySerialOut Serial;
#endif
#if !defined(TINY_SERIAL_INHERIT_FROM_PRINT)
#define Print TinySerialOut
#endif

#endif // defined(__AVR_ATtiny25__) || defined(__AVR_ATtiny45__) || defined(__AVR_ATtiny85__) || defined(__AVR_ATtiny87__) || defined(__AVR_ATtiny167__)

Expand Down
Loading

0 comments on commit 313c819

Please sign in to comment.