#include "pitches.h"
// Define the pin where the buzzer is connected
const int LEDpin = 13;
// Define Morse code timing for 20 WPM
const int dotDuration = 60; // 60 ms for dot
const int dashDuration = 180; // 180 ms for dash
const int intraCharSpace = 60; // 60 ms between parts of the same letter
const int interCharSpace = 180; // 180 ms between letters
const int wordSpace = 420; // 420 ms between words
void setup() {
// Set the buzzer pin as an output
pinMode(LEDpin, OUTPUT);
Serial.begin(115200); // Any baud rate should work
Serial.println("Hello Arduino\n");
}
void loop() {
// Morse code for GW7HDX
sendMorse("G");
// Wait for 2 seconds before repeating the sequence
delay(2000);
}
void sendMorse(String message) {
for (int i = 0; i < message.length(); i++) {
char c = message.charAt(i);
Serial.println(c);
sendMorseChar(c);
// Space between letters
if (i < message.length() - 1) {
delay(interCharSpace);
}
}
}
void sendMorseChar(char c) {
switch (c) {
case 'G': sendDash(); sendDash(); sendDot(); break;
case 'W': sendDot(); sendDash(); sendDash(); break;
case '7': sendDash(); sendDash(); sendDot(); sendDot(); sendDot(); break;
case 'H': sendDot(); sendDot(); sendDot(); sendDot(); break;
case 'D': sendDash(); sendDot(); sendDot(); break;
case 'X': sendDash(); sendDot(); sendDot(); sendDash(); break;
}
}
void sendDot() {
Serial.println("Dot");
digitalWrite(LEDpin, HIGH);
tone(8,500,dotDuration);
digitalWrite(LEDpin, LOW);
delay(intraCharSpace);
}
void sendDash() {
Serial.println("Dash");
digitalWrite(LEDpin, HIGH);
tone(8,500,dashDuration);
digitalWrite(LEDpin, LOW);
delay(intraCharSpace);
}