Skip to content

Commit 9d0dac7

Browse files
committed
Add support for no output pin toggling
1 parent 2c1aac3 commit 9d0dac7

File tree

3 files changed

+25
-9
lines changed

3 files changed

+25
-9
lines changed

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ If you need to check to see if the Morse library is currently sending the conten
4444

4545
The sending speed can be changed on-the-fly by using the _setWPM()_ method. The parameter is typed using a _float_ so that fractional words per minute can be specified. Why would you want to do this? In case you need to send Morse code using a very long integration time such as with the QRSS operating mode. For example, a setting of 0.2 WPM sets a Morse code "dit" length of 6 seconds.
4646

47-
If you don't want to have the library directly control a digital I/O pin, you may have your sketch poll the boolean _tx_ member variable and act on it accordingly within their periodic 1 ms function.
47+
If you don't want to have the library directly control a digital I/O pin, you may have your sketch poll the boolean _tx_ member variable and act on it accordingly within their periodic 1 ms function. Set the output pin parameter in the constructor to 0.
4848

4949
Startup Conditions and Constraints
5050
----------------------------------
@@ -61,7 +61,8 @@ Public Methods
6161
*
6262
* Create an instance of the Morse class.
6363
*
64-
* tx_pin - Arduino pin used as the output by this library.
64+
* tx_pin - Arduino pin used as the output by this library. Will not toggle an
65+
* output pin if set to 0.
6566
* init_wpm - Sending speed in words per minute.
6667
*
6768
*/

src/Morse.cpp

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@
3636
*
3737
* Create an instance of the Morse class.
3838
*
39-
* tx_pin - Arduino pin used as the output by this library.
39+
* tx_pin - Arduino pin used as the output by this library. Will not toggle an
40+
* output pin if set to 0.
4041
* init_wpm - Sending speed in words per minute.
4142
*
4243
*/
@@ -48,7 +49,10 @@ Morse::Morse(uint8_t tx_pin, float init_wpm) : output_pin(tx_pin)
4849

4950
setWPM(init_wpm);
5051

51-
pinMode(output_pin, OUTPUT);
52+
if(output_pin)
53+
{
54+
pinMode(output_pin, OUTPUT);
55+
}
5256

5357
cur_state = State::IDLE;
5458
next_state = State::IDLE;
@@ -223,7 +227,10 @@ void Morse::update()
223227
case State::PREAMBLE:
224228
// Transmitter on
225229
tx = true;
226-
digitalWrite(output_pin, HIGH);
230+
if(output_pin)
231+
{
232+
digitalWrite(output_pin, HIGH);
233+
}
227234

228235
// When done waiting, go back to IDLE state to start the message
229236
if(cur_timer > cur_state_end)
@@ -235,12 +242,18 @@ void Morse::update()
235242
case State::DIT:
236243
case State::DAH:
237244
tx = true;
238-
digitalWrite(output_pin, HIGH);
245+
if(output_pin)
246+
{
247+
digitalWrite(output_pin, HIGH);
248+
}
239249

240250
if(cur_timer > cur_state_end)
241251
{
242252
tx = false;
243-
digitalWrite(output_pin, LOW);
253+
if(output_pin)
254+
{
255+
digitalWrite(output_pin, LOW);
256+
}
244257

245258
cur_state_end = cur_timer + dit_length;
246259
cur_state = State::DITDELAY;
@@ -252,7 +265,10 @@ void Morse::update()
252265
case State::MSGDELAY:
253266
case State::EOMDELAY:
254267
tx = false;
255-
digitalWrite(output_pin, LOW);
268+
if(output_pin)
269+
{
270+
digitalWrite(output_pin, LOW);
271+
}
256272

257273
if(cur_timer > cur_state_end)
258274
{

src/Morse.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828

2929
#include "Arduino.h"
3030

31-
3231
// Constants
3332
constexpr uint8_t DEFAULT_OUTPUT_PIN = LED_BUILTIN;
3433
constexpr float DEFAULT_WPM = 25;

0 commit comments

Comments
 (0)