Skip to content

Commit

Permalink
Add support for no output pin toggling
Browse files Browse the repository at this point in the history
  • Loading branch information
NT7S committed Jan 16, 2018
1 parent 2c1aac3 commit 9d0dac7
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 9 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ If you need to check to see if the Morse library is currently sending the conten

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.

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.
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.

Startup Conditions and Constraints
----------------------------------
Expand All @@ -61,7 +61,8 @@ Public Methods
*
* Create an instance of the Morse class.
*
* tx_pin - Arduino pin used as the output by this library.
* tx_pin - Arduino pin used as the output by this library. Will not toggle an
* output pin if set to 0.
* init_wpm - Sending speed in words per minute.
*
*/
Expand Down
28 changes: 22 additions & 6 deletions src/Morse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@
*
* Create an instance of the Morse class.
*
* tx_pin - Arduino pin used as the output by this library.
* tx_pin - Arduino pin used as the output by this library. Will not toggle an
* output pin if set to 0.
* init_wpm - Sending speed in words per minute.
*
*/
Expand All @@ -48,7 +49,10 @@ Morse::Morse(uint8_t tx_pin, float init_wpm) : output_pin(tx_pin)

setWPM(init_wpm);

pinMode(output_pin, OUTPUT);
if(output_pin)
{
pinMode(output_pin, OUTPUT);
}

cur_state = State::IDLE;
next_state = State::IDLE;
Expand Down Expand Up @@ -223,7 +227,10 @@ void Morse::update()
case State::PREAMBLE:
// Transmitter on
tx = true;
digitalWrite(output_pin, HIGH);
if(output_pin)
{
digitalWrite(output_pin, HIGH);
}

// When done waiting, go back to IDLE state to start the message
if(cur_timer > cur_state_end)
Expand All @@ -235,12 +242,18 @@ void Morse::update()
case State::DIT:
case State::DAH:
tx = true;
digitalWrite(output_pin, HIGH);
if(output_pin)
{
digitalWrite(output_pin, HIGH);
}

if(cur_timer > cur_state_end)
{
tx = false;
digitalWrite(output_pin, LOW);
if(output_pin)
{
digitalWrite(output_pin, LOW);
}

cur_state_end = cur_timer + dit_length;
cur_state = State::DITDELAY;
Expand All @@ -252,7 +265,10 @@ void Morse::update()
case State::MSGDELAY:
case State::EOMDELAY:
tx = false;
digitalWrite(output_pin, LOW);
if(output_pin)
{
digitalWrite(output_pin, LOW);
}

if(cur_timer > cur_state_end)
{
Expand Down
1 change: 0 additions & 1 deletion src/Morse.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@

#include "Arduino.h"


// Constants
constexpr uint8_t DEFAULT_OUTPUT_PIN = LED_BUILTIN;
constexpr float DEFAULT_WPM = 25;
Expand Down

0 comments on commit 9d0dac7

Please sign in to comment.