-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMorseEncoderSine.h
97 lines (84 loc) · 2.29 KB
/
MorseEncoderSine.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
/*
Morse Encoder for Teensy Audio Sine
Based on Morse_Encoder_tone sample code from MorseEnDecoder (credits/license are below)
Hacked by Jonathan Hunsberger ([email protected]) to use a Teeny AudioSynthWaveForm object
to play the actual tone.
-- Morse_Encoder_tone license/credits/etc.
Original implementation:
Copyright (C) 2010, 2012 raron
GNU GPLv3 license (http://www.gnu.org/licenses)
Contact: [email protected] (not checked too often..)
Details: http://raronoff.wordpress.com/2010/12/16/morse-endecoder/
pluggable output refactoring:
Contact: [email protected] (not checked too often..)
*/
#include <MorseEnDecoder.h>
#include <Audio.h>
/** provide an alternate implementation to the default digitalWrite with tone and text instead
*/
class morseEncoderSine: public morseEncoder
{
public:
morseEncoderSine(AudioSynthWaveform *sineP);
protected:
void setup_signal();
void start_signal(bool startOfChar, char signalType);
void stop_signal(bool endOfChar, char signalType);
private:
void toneOn();
void toneOff();
float sineAmp;
int sineFreq;
AudioSynthWaveform *sinePointer;
};
morseEncoderSine::morseEncoderSine(AudioSynthWaveform *sineP)
: morseEncoder(-1) // constructor requires an "encodePin". overriding all methods that use it so passing a nonsense value
{
sinePointer = sineP;
sineAmp = 0.7;
sineFreq = 880;
(*sinePointer).begin(0,0,WAVEFORM_SINE);
}
void morseEncoderSine::toneOn()
{
//Serial.println("toneOn");
(*sinePointer).frequency(sineFreq);
(*sinePointer).amplitude(sineAmp);
}
void morseEncoderSine::toneOff()
{
//Serial.println("toneOff");
(*sinePointer).amplitude(0);
(*sinePointer).frequency(0);
}
void morseEncoderSine::setup_signal()
{
morseEncoderSine::toneOff();
}
void morseEncoderSine::start_signal(bool startOfChar, char signalType)
{
morseEncoderSine::toneOff();
if(startOfChar)
//Serial.print('!');
switch (signalType) {
case '.':
Serial.print("dit");
break;
case '-':
Serial.print("dah");
break;
default:
Serial.print(signalType);
break;
}
morseEncoderSine::toneOn();
}
void morseEncoderSine::stop_signal(bool endOfChar, char signalType)
{
morseEncoderSine::toneOff();
if (endOfChar) {
Serial.println(' ');
} else {
Serial.print(' ');
}
}