Skip to content

Commit

Permalink
Version 1.4.2 - New example ReactionTimeTestGame
Browse files Browse the repository at this point in the history
  • Loading branch information
ArminJo committed Dec 7, 2020
1 parent f4fe048 commit de0f579
Show file tree
Hide file tree
Showing 27 changed files with 3,076 additions and 238 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/LibraryBuild.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,22 +65,22 @@ jobs:

- 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
sketches-exclude: LightToTone PlayChristmasMelodyUSDistance RandomMelody # Only OneMelody example
sketches-exclude: LightToTone PlayChristmasMelodyUSDistance RandomMelody ReactionTimeTestGame # Only OneMelody example
build-properties: # the flags were put in compiler.cpp.extra_flags
OneMelody:
-DDEBUG

- arduino-boards-fqbn: esp8266:esp8266:huzzah:eesz=4M3M,xtal=80
platform-url: https://arduino.esp8266.com/stable/package_esp8266com_index.json
sketches-exclude: LightToTone PlayChristmasMelodyUSDistance # EasyButton and Talkie library not available
sketches-exclude: LightToTone PlayChristmasMelodyUSDistance ReactionTimeTestGame # EasyButton and Talkie library not available

- arduino-boards-fqbn: esp32:esp32:featheresp32:FlashFreq=80
platform-url: https://dl.espressif.com/dl/package_esp32_index.json
sketches-exclude: LightToTone PlayChristmasMelodyUSDistance # EasyButton and Talkie library not available
sketches-exclude: LightToTone PlayChristmasMelodyUSDistance ReactionTimeTestGame # EasyButton and Talkie library not available

- arduino-boards-fqbn: STM32:stm32:GenF1:pnum=BLUEPILL_F103C8
platform-url: https://github.com/stm32duino/BoardManagerFiles/raw/master/STM32/package_stm_index.json
sketches-exclude: LightToTone PlayChristmasMelodyUSDistance # EasyButton and Talkie library not available
sketches-exclude: LightToTone PlayChristmasMelodyUSDistance ReactionTimeTestGame # EasyButton and Talkie library not available

# Do not cancel all jobs / architectures if one job fails
fail-fast: false
Expand Down
18 changes: 15 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# [PlayRtttl](https://github.com/ArminJo/PlayRtttl)
Available as Arduino library "PlayRtttl"

### [Version 1.4.1](https://github.com/ArminJo/PlayRtttl/releases)
### [Version 1.4.2](https://github.com/ArminJo/PlayRtttl/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/PlayRtttl.svg?)](https://www.ardu-badge.com/PlayRtttl)
Expand Down Expand Up @@ -48,14 +48,24 @@ const int TONE_PIN = 11;

# Compile options / macros for this library
To customize the library to different requirements, there are some compile options / makros available.<br/>
Modify it by commenting them out or in, or change the values if applicable. Or define the macro with the -D compiler option for gobal compile (the latter is not possible with the Arduino IDE, so consider to use [sloeber](https://eclipse.baeyens.it).
Modify it by commenting them out or in, or change the values if applicable. Or define the macro with the -D compiler option for gobal compile (the latter is not possible with the Arduino IDE, so consider to use [Sloeber](https://eclipse.baeyens.it).
Some options which are enabed by default can be disabled also by defining a *inhibit* macro like `USE_NO_RTX_EXTENSIONS`.
| Macro | Default | File | Disable macro | Description |
|-|-|-|-|-|
| `SUPPORT_RTX_EXTENSIONS` | enabled | PlayRtttl.h | `USE_NO_RTX_EXTENSIONS` | Support loop and style.<br/>Even without `SUPPORT_RTX_EXTENSIONS` the default style is natural (Tone length = note length - 1/16).<br/>Requires around 182 additional bytes FLASH. |
| `SUPPORT_RTX_FORMAT` | enabled | PlayRtttl.h | `USE_NO_RTX_EXTENSIONS` | Enables evaluating RTX format definitions `'s'` and `'l'`. |
| `RTX_STYLE_DEFAULT` | 'N' | PlayRtttl.h | | (Natural) Tone length = note length - 1/16. |

### Modifying compile options with Arduino IDE
First use *Sketch > Show Sketch Folder (Ctrl+K)*.<br/>
If you did not yet stored the example as your own sketch, then you are instantly in the right library folder.<br/>
Otherwise you have to navigate to the parallel `libraries` folder and select the library you want to access.<br/>
In both cases the library files itself are located in the `src` directory.<br/>

### Modifying compile options with Sloeber IDE
If you are using Sloeber as your IDE, you can easily define global symbols with *Properties > Arduino > CompileOptions*.<br/>
![Sloeber settings](https://github.com/ArminJo/ServoEasing/blob/master/pictures/SloeberDefineSymbols.png)

# Running with 1 MHz
If running with 1 MHz, e.g on an ATtiny, the millis() interrupt needs so much time, that it disturbes the tone() generation by interrupt. You can avoid this by using a tone pin, which is directly supported by hardware. Look at the appropriate *pins_arduino.h*, find `digital_pin_to_timer_PGM[]` and choose pins with TIMER1x entries.

Expand All @@ -64,6 +74,8 @@ More RTTTL songs can be found under http://www.picaxe.com/RTTTL-Ringtones-for-Tu
[C array of songs on GitHub](https://github.com/granadaxronos/120-SONG_NOKIA_RTTTL_RINGTONE_PLAYER_FOR_ARDUINO_UNO/blob/master/RTTTL_PLAYER/songs.h)

# Revision History
### Version 1.4.2
- New example ReactionTimeTestGame.

### Version 1.4.1
- Removed blocking wait for ATmega32U4 Serial in examples.
Expand Down Expand Up @@ -91,7 +103,7 @@ More RTTTL songs can be found under http://www.picaxe.com/RTTTL-Ringtones-for-Tu
### Version 1.2.0
- No Serial.print statements in this library anymore, to avoid problems with different Serial implementations.
- Function `playRandomRtttlBlocking()` + `startPlayRandomRtttlFromArrayPGM()` do not print name now. If needed, use new functions `playRandomRtttlSampleBlockingAndPrintName()` + `startPlayRandomRtttlFromArrayPGMAndPrintName()`.
- Printing functions have parameter (..., Stream * aSerial) to print to any serial. Call it (..., &Serial) to use standard Serial;
- Printing functions have parameter (..., Stream *aSerial) to print to any serial. Call it (..., &Serial) to use standard Serial;
- `playRandomRtttlBlocking()` renamed to `playRandomRtttlSampleBlocking()` and bug fixing.

### Version 1.1.0
Expand Down
6 changes: 3 additions & 3 deletions examples/LightToTone/EasyButtonAtInt01.cpp.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,15 @@

// For external measurement of code timing
//#define MEASURE_EASY_BUTTON_INTERRUPT_TIMING
#if defined(MEASURE_EASY_BUTTON_INTERRUPT_TIMING) || defined (LED_FEEDBACK_TEST)
#if defined(MEASURE_EASY_BUTTON_INTERRUPT_TIMING) || defined(LED_FEEDBACK_TEST)
#include "digitalWriteFast.h"
#endif

#if defined(USE_BUTTON_0)
EasyButton * EasyButton::sPointerToButton0ForISR;
EasyButton *EasyButton::sPointerToButton0ForISR;
#endif
#if defined(USE_BUTTON_1)
EasyButton * EasyButton::sPointerToButton1ForISR;
EasyButton *EasyButton::sPointerToButton1ForISR;
#endif

// @formatter:off // the eclipse formatter has problems with // comments in undefined code blocks
Expand Down
70 changes: 36 additions & 34 deletions examples/LightToTone/EasyButtonAtInt01.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,29 +37,7 @@
#define VERSION_EASY_BUTTON "3.1.0"
#define VERSION_EASY_BUTTON_MAJOR 3
#define VERSION_EASY_BUTTON_MINOR 1

/*
* Version 3.1.0 - 6/2020
* - 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.
*
* Version 3.0.0 - 5/2020
* - Added button release handler and adapted examples.
* - Revoke change for "only one true result per press for checkForLongPressBlocking()". It is superseded by button release handler.
* - Support buttons which are active high by defining BUTTON_IS_ACTIVE_HIGH.
* - Improved detection of maximum bouncing period used in DebounceTest.
*
* Version 2.1.0 - 5/2020
* - Avoid 1 ms delay for checkForLongPressBlocking() if button is not pressed.
* - Only one true result per press for checkForLongPressBlocking().
*
* Version 2.0.0 - 1/2020
* - Ported to ATtinyX5 and ATiny167.
* - Support also PinChangeInterrupt for button 1 on Pin PA0 to PA7 for ATtiniy87/167.
* - Long press detection support.
* - Double press detection support.
* - Renamed to EasyButtonAtInt01.cpp.h
*/
// The change log is at the bottom of the file

#if defined(__AVR__)
#include <Arduino.h>
Expand All @@ -83,7 +61,7 @@
//#define BUTTON_IS_ACTIVE_HIGH
/*
* Define USE_ATTACH_INTERRUPT to force use of the arduino function attachInterrupt().
* Needed if you get the error " multiple definition of `__vector_1'" (or `__vector_2'), because another library uses the attachInterrupt() function.
* Required if you get the error " multiple definition of `__vector_1'" (or `__vector_2'), because another library uses the attachInterrupt() function.
* For one button it needs additional 160 bytes FLASH, for 2 buttons it needs additional 88 bytes.
*/
//#define USE_ATTACH_INTERRUPT
Expand Down Expand Up @@ -124,9 +102,9 @@
* Activate LED_BUILTIN as long as button is pressed
*/
//#define LED_FEEDBACK_TEST
#if defined (LED_FEEDBACK_TEST)
#if defined(LED_FEEDBACK_TEST)
# if ! defined(BUTTON_TEST_FEEDBACK_LED_PIN)
# if defined (LED_BUILTIN)
# if defined(LED_BUILTIN)
# define BUTTON_TEST_FEEDBACK_LED_PIN LED_BUILTIN // if not specified, use built in led - pin 13 on Uno board
# else
# error "LED_FEEDBACK_TEST defined but no BUTTON_TEST_FEEDBACK_LED_PIN or LED_BUILTIN defined"
Expand All @@ -146,7 +124,7 @@

//#define TRACE
#ifdef TRACE
#warning "If using TRACE, the timing of the interrupt service routine changes, e.g. you will see more spikes, than expected!"
#warning If using TRACE, the timing of the interrupt service routine changes, e.g. you will see more spikes, than expected!
#endif

/*
Expand All @@ -171,7 +149,7 @@
# if ! defined(INT1_PIN)
#define INT1_PIN 3
# elif (INT1_PIN != 2) && (INT1_PIN > 5)
#error "INT1_PIN (for PCINT0 interrupt) can only be 0,1,3,4,5"
#error INT1_PIN (for PCINT0 interrupt) can only be 0,1,3,4,5
# endif
#define INT1_DDR_PORT (DDRB)
#define INT1_IN_PORT (PINB)
Expand Down Expand Up @@ -218,11 +196,11 @@
#undef INT1_PIN
#define INT1_PIN 6 // PA6
# else
#error "INT1_PIN (for PCINT0 interrupt) can only be 5 to 12"
#error INT1_PIN (for PCINT0 interrupt) can only be 5 to 12
# endif
# else // defined(ARDUINO_AVR_DIGISPARKPRO)
# if (INT1_PIN > 7)
#error "INT1_PIN (for PCINT0 interrupt) can only be 0 to 7"
#error INT1_PIN (for PCINT0 interrupt) can only be 0 to 7
# endif
# endif // defined(ARDUINO_AVR_DIGISPARKPRO)
#define INT1_DDR_PORT (DDRA)
Expand All @@ -241,7 +219,7 @@
# if ! defined(INT1_PIN)
#define INT1_PIN 3
# elif (INT1_PIN > 7)
#error "INT1_PIN (for PCINT2 interrupt) can only be Arduino pins 0 to 7 (PD0 to PD7)"
#error INT1_PIN (for PCINT2 interrupt) can only be Arduino pins 0 to 7 (PD0 to PD7)
# endif
#define INT1_DDR_PORT (DDRD)
#define INT1_IN_PORT (PIND)
Expand All @@ -255,7 +233,7 @@

#if defined(USE_BUTTON_1) && ((! defined(ISC10)) || ((defined(__AVR_ATtiny87__) || defined(__AVR_ATtiny167__)) && INT1_PIN != 3)) \
&& ! defined(INTENTIONALLY_USE_PCI0_FOR_BUTTON1) && !(defined(__AVR_ATtiny25__) || defined(__AVR_ATtiny45__) || defined(__AVR_ATtiny85__))
#warning "Using PCINT0 interrupt for button 1"
#warning Using PCINT0 interrupt for button 1
#endif

#if defined(__AVR_ATtiny25__) || defined(__AVR_ATtiny45__) || defined(__AVR_ATtiny85__)
Expand Down Expand Up @@ -357,10 +335,10 @@ class EasyButton {
#endif

#if defined(USE_BUTTON_0)
static EasyButton * sPointerToButton0ForISR;
static EasyButton *sPointerToButton0ForISR;
#endif
#if defined(USE_BUTTON_1)
static EasyButton * sPointerToButton1ForISR;
static EasyButton *sPointerToButton1ForISR;
#endif
};
// end of class definition
Expand All @@ -380,6 +358,30 @@ void __attribute__ ((weak)) handleINT1Interrupt();
#endif

#endif // defined(__AVR__)

/*
* Version 3.1.0 - 6/2020
* - 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.
*
* Version 3.0.0 - 5/2020
* - Added button release handler and adapted examples.
* - Revoke change for "only one true result per press for checkForLongPressBlocking()". It is superseded by button release handler.
* - Support buttons which are active high by defining BUTTON_IS_ACTIVE_HIGH.
* - Improved detection of maximum bouncing period used in DebounceTest.
*
* Version 2.1.0 - 5/2020
* - Avoid 1 ms delay for checkForLongPressBlocking() if button is not pressed.
* - Only one true result per press for checkForLongPressBlocking().
*
* Version 2.0.0 - 1/2020
* - Ported to ATtinyX5 and ATiny167.
* - Support also PinChangeInterrupt for button 1 on Pin PA0 to PA7 for ATtiniy87/167.
* - Long press detection support.
* - Double press detection support.
* - Renamed to EasyButtonAtInt01.cpp.h
*/

#endif /* EASY_BUTTON_AT_INT01_H_ */

#pragma once
4 changes: 2 additions & 2 deletions examples/LightToTone/LightToTone.ino
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
* Copyright (C) 2018 Armin Joachimsmeyer
* [email protected]
*
* This file is part of PlayRttl https://github.com/ArminJo/PlayRttl.
* This file is part of PlayRttl https://github.com/ArminJo/PlayRtttl.
*
* PlayRttl is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -152,7 +152,7 @@ void loop() {
if (tThresholdCount > 10) {
// stop playing melody
stopPlayRtttl();
break; // not really needed here, since the while condition will also change because of stopPlayRtttl.
break; // not really required here, since the while condition will also change because of stopPlayRtttl.
}
} else {
tThresholdCount = 0;
Expand Down
30 changes: 14 additions & 16 deletions examples/OneMelody/ATtinySerialOut.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@
*
*/

#if defined(__AVR_ATtiny25__) || defined(__AVR_ATtiny45__) || defined(__AVR_ATtiny85__) || defined(__AVR_ATtiny87__) || defined(__AVR_ATtiny167__)
#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__)
#include "ATtinySerialOut.h"
#include <avr/eeprom.h> // for eeprom_read_byte() in writeString_E()

Expand Down Expand Up @@ -62,10 +64,6 @@
#define TX_DDR DDRB
#endif // defined(__AVR_ATtiny87__) || defined(__AVR_ATtiny167__)

#if defined(Serial)
#undef Serial
#endif

void write1Start8Data1StopNoParity(uint8_t aValue);

bool sUseCliSeiForWrite = true;
Expand Down Expand Up @@ -98,7 +96,7 @@ void useCliSeiForStrings(bool aUseCliSeiForWrite) {
/*
* Write String residing in RAM
*/
void writeString(const char * aStringPtr) {
void writeString(const char *aStringPtr) {
#ifndef USE_ALWAYS_CLI_SEI_GUARD_FOR_OUTPUT
if (sUseCliSeiForWrite) {
#endif
Expand All @@ -117,7 +115,7 @@ void writeString(const char * aStringPtr) {
/*
* Write string residing in program space (FLASH)
*/
void writeString_P(const char * aStringPtr) {
void writeString_P(const char *aStringPtr) {
uint8_t tChar = pgm_read_byte((const uint8_t * ) aStringPtr);
// Comparing with 0xFF is safety net for wrong string pointer
while (tChar != 0 && tChar != 0xFF) {
Expand All @@ -137,7 +135,7 @@ void writeString_P(const char * aStringPtr) {
/*
* Write string residing in program space (FLASH)
*/
void writeString(const __FlashStringHelper * aStringPtr) {
void writeString(const __FlashStringHelper *aStringPtr) {
PGM_P tPGMStringPtr = reinterpret_cast<PGM_P>(aStringPtr);
uint8_t tChar = pgm_read_byte((const uint8_t * ) aStringPtr);
// Comparing with 0xFF is safety net for wrong string pointer
Expand All @@ -158,7 +156,7 @@ void writeString(const __FlashStringHelper * aStringPtr) {
/*
* Write string residing in EEPROM space
*/
void writeString_E(const char * aStringPtr) {
void writeString_E(const char *aStringPtr) {
uint8_t tChar = eeprom_read_byte((const uint8_t *) aStringPtr);
// Comparing with 0xFF is safety net for wrong string pointer
while (tChar != 0 && tChar != 0xFF) {
Expand All @@ -175,19 +173,19 @@ void writeString_E(const char * aStringPtr) {
}
}

void writeStringWithoutCliSei(const char * aStringPtr) {
void writeStringWithoutCliSei(const char *aStringPtr) {
while (*aStringPtr != 0) {
write1Start8Data1StopNoParity(*aStringPtr++);
}
}

void writeStringWithCliSei(const char * aStringPtr) {
void writeStringWithCliSei(const char *aStringPtr) {
while (*aStringPtr != 0) {
write1Start8Data1StopNoParityWithCliSei(*aStringPtr++);
}
}

void writeStringSkipLeadingSpaces(const char * aStringPtr) {
void writeStringSkipLeadingSpaces(const char *aStringPtr) {
// skip leading spaces
while (*aStringPtr == ' ' && *aStringPtr != 0) {
aStringPtr++;
Expand Down Expand Up @@ -373,11 +371,11 @@ size_t TinySerialOut::write(uint8_t aByte) {
return 1;
}

void TinySerialOut::print(const char* aStringPtr) {
void TinySerialOut::print(const char *aStringPtr) {
writeString(aStringPtr);
}

void TinySerialOut::print(const __FlashStringHelper * aStringPtr) {
void TinySerialOut::print(const __FlashStringHelper *aStringPtr) {
writeString(aStringPtr);
}

Expand Down Expand Up @@ -433,12 +431,12 @@ void TinySerialOut::println(char aChar) {
println();
}

void TinySerialOut::println(const char* aStringPtr) {
void TinySerialOut::println(const char *aStringPtr) {
print(aStringPtr);
println();
}

void TinySerialOut::println(const __FlashStringHelper * aStringPtr) {
void TinySerialOut::println(const __FlashStringHelper *aStringPtr) {
print(aStringPtr);
println();
}
Expand Down
Loading

0 comments on commit de0f579

Please sign in to comment.