#define MORSE_PIN 21 // any digital pin or output capable analogue pin
void setup() {
pinMode(MORSE_PIN, OUTPUT);
}
void dot() {
digitalWrite(MORSE_PIN, HIGH);
delay(250); // duration of a dot
digitalWrite(MORSE_PIN, LOW);
delay(250); // time between parts of the same letter
}
void dash() {
digitalWrite(MORSE_PIN, HIGH);
delay(750); // duration of a dash
digitalWrite(MORSE_PIN, LOW);
delay(250); // time between parts of the same letter
}
void loop() {
// Example: Morse code for "SOS"
dot(); dot(); dot(); // S: · · ·
delay(1000); // time between letters
dash(); dash(); dash(); // O: — — —
delay(1000); // Time between letters
dot(); dot(); dot(); // S: · · ·
delay(1500); // time between repetitions
}