-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmorse_beacon.ino
148 lines (82 loc) · 2.51 KB
/
morse_beacon.ino
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
/*
***********************************************
EA1NK Morse Beacon
2012 - Juan J. Lamas - EA1NK
***********************************************
*/
// Arduino pin configuration
int led=13; // Pin13 as led
int pwm=11; //Pin11 as tone output
// Beacon configuration.
char text[]="vvv vvv vvv the brown fox jumps over the lazy dog k "; // Beacon message.
int interval = 10 ; // Beacon interval is sec.
// Morse code speed & tone configuration WPM.
int speed=32; // Beacon speed
int freq=550; // Tone in Hz
// Dot, dash and space timings using PARIS standard, dot = 60 milliseconds at 20 WPM.
float dot=(1200/speed);
float dash=3*dot;
float fig_space=dot;
float char_space=3*dot;
float word_space=7*dot;
void send_code(String encoded_ltr){
Serial.println("");
Serial.println(encoded_ltr);
for(int i=0;i < encoded_ltr.length();i++){
if(encoded_ltr[i] == '.'){
tone(pwm,freq,dot);
digitalWrite(led,HIGH);
delay(dot);
digitalWrite(led,LOW);
Serial.write("dit ");
}
if(encoded_ltr[i] == '-'){
tone(pwm,freq,dash);
digitalWrite(led,HIGH);
delay(dash);
digitalWrite(led,LOW);
Serial.write("dah ");
}
if(encoded_ltr[i] == '|'){
digitalWrite(led,LOW);
delay(word_space);
digitalWrite(led,LOW);
Serial.write(" ");
}
else {
//Do nothing
}
digitalWrite(led,LOW);
delay(fig_space);
Serial.write(i);
}
}
void ltr_to_code(char ltr){
char letters[]={
'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z','1','2','3','4','5','6','7','8','9','0',' ','.',',','?','/' };
String code[]={
".-","-...","-.-.","-..",".","..-.","--.","....","..",".---","-.-",".-..","--","-.","---",".--.","--.-",".-.","...","-","..-","...-",".--","-..-","-.--",
"--..",".----","..---","...--","....-",".....","-....","--...","---..","----.","-----","|",".-.-.-","--..--","..--..","-..-." };
for (int i=0;i<sizeof(letters);i++){
if (ltr == letters[i]){
send_code(code[i]);
digitalWrite(led,LOW);
delay(char_space);
}
}
}
void setup(){
// Initialize digital pin as output.
pinMode(pwm,OUTPUT);
pinMode(led,OUTPUT);
Serial.begin(9600);
}
void loop() {
// We loop trough the array items and play the message.
for (int a=0;a<sizeof(text);a++){
Serial.write(text[a]);
Serial.write(" ");
ltr_to_code(text[a]);
}
delay(interval * 1000);
}