# How to display morse letters

**URL:** <https://forum.arduino.cc/t/how-to-display-morse-letters/1172856>\
**Category:** Programming\
**Created:** [September 27, 2023, 8:08pm UTC](https://forum.arduino.cc/t/how-to-display-morse-letters/1172856 "2023-09-27T20:08:39Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![antopiaaw](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/antopiaaw/32/990672_2.png) [@antopiaaw](https://forum.arduino.cc/u/antopiaaw)\
**Post date:** [September 27, 2023, 8:08pm UTC](https://forum.arduino.cc/t/how-to-display-morse-letters/1172856/1 "2023-09-27T20:08:39Z")

</div>

i have a program which generates morse code using 2 capacitance plates with a nano ,now this works  
i have added a binary tree to hold the letters, left insert a dit right insert a dah this works  
but i cannot figure out how to display the morse letters that I key how to program the morse sent to display on a lcd screen i am using i2c.

```arduino

struct TreeNode* findLeft(struct TreeNode* root, char &Letter){
    struct TreeNode *current = root;
            current = current->left;
            if (&current->data != "\0") {
                Letter = current->data;  
             return current;
            }
}

in my loop

   uint8_t dahCycles=readCapacitivePin(DAHPADDLE);
   
    if(dahCycles > CAPACITANCEVALUE) {
    if(!testMillis)
     testMillis=millis();  
      doDah();
      counter++;
      tempNode=findRight(tempNode,Letter[counter]);   
    }

  uint8_t ditCycles = readCapacitivePin(DITPADDLE);
      if(ditCycles > CAPACITANCEVALUE) {
       if(!testMillis)
        testMillis=millis();   
        doDit();
        counter++;  
        tempNode=findLeft(tempNode,Letter[counter]);
  
    }

```

some opinion on how to handle the display would be helpful i get the keydown time  
but how to get the keyup time for each letter obvious there could be up to 5 combinations of morse code to a letter.  
steve

---

<div class="post-metadata">

**Author:** ![gilshultz](https://avatars.discourse-cdn.com/v4/letter/g/67e7ee/32.png) [@gilshultz](https://forum.arduino.cc/u/gilshultz)\
**Post date:** [September 27, 2023, 8:58pm UTC](https://forum.arduino.cc/t/how-to-display-morse-letters/1172856/2 "2023-09-27T20:58:36Z")

</div>

Try putting them in a table, then when you find the pattern add an offset to to the index to get your letter or use a two dimensional table.

---

<div class="post-metadata">

**Author:** ![DrDiettrich](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/drdiettrich/32/219048_2.png) [@DrDiettrich](https://forum.arduino.cc/u/DrDiettrich)\
**Post date:** [September 28, 2023, 1:19am UTC](https://forum.arduino.cc/t/how-to-display-morse-letters/1172856/3 "2023-09-28T01:19:27Z")

</div>

> [@antopiaaw](#):
>
> how to get the keyup time for each letter

You have to detect dot, dash, letter-pause, word-pause.  
For dot and dash you can preset a tree in which you can track the currently received character:  
root+dot -\> E; root+dash -\> T;  
E+dot -\> I; E+dash -\> A; E+pause -\> return('E');  
...

---

<div class="post-metadata">

**Author:** ![xfpd](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/xfpd/32/1120236_2.png) [@xfpd](https://forum.arduino.cc/u/xfpd)\
**Post date:** [September 28, 2023, 4:38am UTC](https://forum.arduino.cc/t/how-to-display-morse-letters/1172856/4 "2023-09-28T04:38:43Z")

</div>

> [@DrDiettrich](#):
>
> letter-pause, word-pause.

, element-pause

- Intra-element gap
- Intra-character gap
- Intra-word gap (unless you cw military)

---

<div class="post-metadata">

**Author:** ![DrDiettrich](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/drdiettrich/32/219048_2.png) [@DrDiettrich](https://forum.arduino.cc/u/DrDiettrich)\
**Post date:** [September 28, 2023, 6:06am UTC](https://forum.arduino.cc/t/how-to-display-morse-letters/1172856/5 "2023-09-28T06:06:47Z")

</div>

> [@xfpd](#):
>
> Intra-element gap

For what purpose? The length of the dots and dashes is important, but not the minimum gap time between them.

---

<div class="post-metadata">

**Author:** ![xfpd](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/xfpd/32/1120236_2.png) [@xfpd](https://forum.arduino.cc/u/xfpd)\
**Post date:** [September 28, 2023, 6:34am UTC](https://forum.arduino.cc/t/how-to-display-morse-letters/1172856/6 "2023-09-28T06:34:47Z")

</div>

The standard for morse timing.

> **[Morse Code Timing](https://morsecode.world/international/timing.html)**
>
> Explanation of how Morse code timings work including words-per-minute and Farnsworth timings.

---

<div class="post-metadata">

**Author:** ![DrDiettrich](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/drdiettrich/32/219048_2.png) [@DrDiettrich](https://forum.arduino.cc/u/DrDiettrich)\
**Post date:** [September 28, 2023, 7:20am UTC](https://forum.arduino.cc/t/how-to-display-morse-letters/1172856/7 "2023-09-28T07:20:23Z")

</div>

> [@xfpd](#):
>
> The standard for morse timing.

Nice try but the intra-element gap is important only for the **sender**. See also: UART stop bits.

---

<div class="post-metadata">

**Author:** ![xfpd](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/xfpd/32/1120236_2.png) [@xfpd](https://forum.arduino.cc/u/xfpd)\
**Post date:** [September 28, 2023, 2:26pm UTC](https://forum.arduino.cc/t/how-to-display-morse-letters/1172856/8 "2023-09-28T14:26:25Z")

</div>

@DrDiettrich

Foremost; I trust your knowledge and expertise, so I am asking more than stating. I thought I was only filling a small gap in your information, but it seems I have not heard your spacing ?requirements?.

If the sender's intra-element gap and intra-character gap are the same, what mechanism will allow the receiver separate characters?

Stop bits. My comm circuits relied on them. I do not understand the correlation.

---

<div class="post-metadata">

**Author:** ![DrDiettrich](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/drdiettrich/32/219048_2.png) [@DrDiettrich](https://forum.arduino.cc/u/DrDiettrich)\
**Post date:** [September 28, 2023, 5:09pm UTC](https://forum.arduino.cc/t/how-to-display-morse-letters/1172856/9 "2023-09-28T17:09:33Z")

</div>

> [@xfpd](#):
>
> If the sender's intra-element gap and intra-character gap are the same

Then that's an error, the **sender** has to establish a meaningful timing.

> [@xfpd](#):
>
> The standard for morse timing.

explains how the **sender** should establish its timing.

---

<div class="post-metadata">

**Author:** ![antopiaaw](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/antopiaaw/32/990672_2.png) [@antopiaaw](https://forum.arduino.cc/u/antopiaaw)\
**Post date:** [September 28, 2023, 5:28pm UTC](https://forum.arduino.cc/t/how-to-display-morse-letters/1172856/10 "2023-09-28T17:28:18Z")

</div>

well done after a whole weekend and a few nights of frantic programming i never thought of the gap i was more interested in time taken rather than delay time  
to shed some light on usage of morse the spacing is not set in stone as hand morse can be anything or worse but the important bit is its a musical note rather than dots and dashes so its easy to read badly sent morse. but for this i am using defined standards  
so dit is 1200 / words per minute so i am looking for a delay of 3 dits and a spacing of  
5 dits for a word  
test for a 3 dit space if true check for word spaces.if not display letter sounds simple now, oh dear i'll get my coat  
steve

---

<div class="post-metadata">

**Author:** ![antopiaaw](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/antopiaaw/32/990672_2.png) [@antopiaaw](https://forum.arduino.cc/u/antopiaaw)\
**Post date:** [September 28, 2023, 5:57pm UTC](https://forum.arduino.cc/t/how-to-display-morse-letters/1172856/11 "2023-09-28T17:57:12Z")

</div>

logic now but that is how i used my btree i was getting every char when i sent the perfect morse but could not figure out beyond that.

steve

---

<div class="post-metadata">

**Author:** ![antopiaaw](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/antopiaaw/32/990672_2.png) [@antopiaaw](https://forum.arduino.cc/u/antopiaaw)\
**Post date:** [September 30, 2023, 8:29am UTC](https://forum.arduino.cc/t/how-to-display-morse-letters/1172856/12 "2023-09-30T08:29:08Z")

</div>

well i tried to figure a gap.i found that my morse code has no gaps that i can trap  
so i am stuck

```arduino
void doDit() {
    tone(buzzerPin,750);
    delay(dit);
    noTone(buzzerPin);
    delay(dit);

 }

```

the only option is to use a counter but how i have not figured it out yet

steve

---

<div class="post-metadata">

**Author:** ![DrDiettrich](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/drdiettrich/32/219048_2.png) [@DrDiettrich](https://forum.arduino.cc/u/DrDiettrich)\
**Post date:** [September 30, 2023, 8:35am UTC](https://forum.arduino.cc/t/how-to-display-morse-letters/1172856/13 "2023-09-30T08:35:18Z")

</div>

> [@antopiaaw](#):
>
> so i am stuck

Me 2 ☹

What do you want to do:

- send morse code?
- receive morse code?

---

<div class="post-metadata">

**Author:** ![antopiaaw](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/antopiaaw/32/990672_2.png) [@antopiaaw](https://forum.arduino.cc/u/antopiaaw)\
**Post date:** [September 30, 2023, 9:34am UTC](https://forum.arduino.cc/t/how-to-display-morse-letters/1172856/14 "2023-09-30T09:34:13Z")

</div>

what i have is an 16x2 display to display the morse speed this works fine  
i just wanted to display the morse being sent i am using capacitance to send the morse instead of a very expensive paddle key .  
i am trying to figue out a counter to count morse?

steve

---

<div class="post-metadata">

**Author:** ![DrDiettrich](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/drdiettrich/32/219048_2.png) [@DrDiettrich](https://forum.arduino.cc/u/DrDiettrich)\
**Post date:** [September 30, 2023, 9:40am UTC](https://forum.arduino.cc/t/how-to-display-morse-letters/1172856/15 "2023-09-30T09:40:45Z")

</div>

We have problems to understand each other. Which languages do you speak?

---

<div class="post-metadata">

**Author:** ![6v6gt](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/6v6gt/32/225488_2.png) [@6v6gt](https://forum.arduino.cc/u/6v6gt)\
**Post date:** [September 30, 2023, 9:50am UTC](https://forum.arduino.cc/t/how-to-display-morse-letters/1172856/16 "2023-09-30T09:50:56Z")

</div>

Maybe only start interpreting a group of symbols when you have a gap long enough to indicate that a complete letter e.g. "--.-" (Q) has been received.  
This is some rough pseudocode which indicates a possible way to do it.

```arduino
uint32_t lastDotOrDashAtMs = 0 ;
char charBuf[30] = {0} ; // holds alphaNumweric word e.g. abc012 etc.
char symbolBuf[6] = {0} ; // holds '.' | '-' // may 5 symbols
uint32_t wordGap = 3000UL ; // 3 sec
uint32_t symbolGap = 1000UL ; // 1 sec

loop() {

   symbol = getNewDotOrDash() ; // returns '.' | '-' | 0 (0 is no new symbol)
   if ( symbol ) {
      // we have a dot or dash
      gapMs = millis() - lastDotOrDashAtMs ;
      lastDotOrDashAtMs = millis() ;
      if ( gapMs > wordGap ) {
         print( charBuf ) ;
         clear( charBuf ) ;
         clear( symbolBuf ) ;
      {
      else if ( gapMs > symbolGap ) {
         interpret symbolBuf // your BTree analyser here
         add interpreted alphNum character to charBuf
         clear( symbolBuf ) ;
      }
      // normal case 
      add symbol to symbolBuf
    }

    if ( millis() - lastDotOrDashAtMs > 5000UL && charBuf not Empty ) { // 5 seconds
    // we've had no symbol for 5 secs so flush out all buffers and clean
         print( charBuf ) ;
         clear( charBuf ) ;
         clear( symbolBuf ) ;
    }
  
}

```

---

<div class="post-metadata">

**Author:** ![antopiaaw](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/antopiaaw/32/990672_2.png) [@antopiaaw](https://forum.arduino.cc/u/antopiaaw)\
**Post date:** [September 30, 2023, 2:51pm UTC](https://forum.arduino.cc/t/how-to-display-morse-letters/1172856/17 "2023-09-30T14:51:33Z")

</div>

English, i want to do both but from the capacitance key i have not installed the actual  
keying circuit i intend to use the buzzer routine to key the ic, which is a 4N26 ic

I have the b tree working and the keying circuit  
problem is i dont know how to join the two together to get an output if that makes sense.

i am not a programmer just a hobby and not very good with c although i can justabout  
use it.  
in 1 routine i get keydownMillis then in the bottom of the loop get the lastmillis the difference between lastMillis and the keydownMillis is 603 milliseconds so its a dah  
with a dah spacing at 12wpm so i am not sure how to detect a spacing other than adding a figure to one of the two does any of this help sorry for not figuring out how to edit a post.

---

<div class="post-metadata">

**Author:** ![antopiaaw](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/antopiaaw/32/990672_2.png) [@antopiaaw](https://forum.arduino.cc/u/antopiaaw)\
**Post date:** [September 30, 2023, 2:53pm UTC](https://forum.arduino.cc/t/how-to-display-morse-letters/1172856/18 "2023-09-30T14:53:24Z")

</div>

```arduino
tyvoid loop()
{ 
  
  

     
   uint8_t dahCycles=readCapacitivePin(DAHPADDLE);
   
    if(dahCycles > CAPACITANCEVALUE) {
    if(!initalMillis)
     initalMillis=millis();
      counter++;
      doDah();
 
     tempNode=findRight(tempNode,Letter[counter]); 
       // lcd.print(Letter); 
    }

  uint8_t ditCycles = readCapacitivePin(DITPADDLE);
      if(ditCycles > CAPACITANCEVALUE) {
       if(!initalMillis)
        initalMillis=millis();
        counter++;
        doDit(); 
        tempNode=findLeft(tempNode,Letter[counter]);
   lcd.print(Letter[counter]);
    }    

int result= digitalRead(BUTTON_PIN);
  if(result == LOW && lastState == HIGH){ //button pressed and released
     toggleWPM ++;
     dit=MAXWORD / toggleWPM;//SET NEW VALUE
     lcd.setCursor(0,1);
     lcd.print(" ");//erase current value
     lcd.setCursor(0,1);
     lcd.print(toggleWPM);//print new value
 }
         if (toggleWPM == 25) toggleWPM =1;//bounds of wpm 25 - 2 wpm

 
lastState=result;
if(counter!=0){
  for (int i=10; i>1;i--){
    if (Letter[i]!="\0")
     lcd.print(Letter[i]);
     counter=0;
     break;
  }
  
  counter=0;
 }pe or paste code here

```

---

<div class="post-metadata">

**Author:** ![antopiaaw](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/antopiaaw/32/990672_2.png) [@antopiaaw](https://forum.arduino.cc/u/antopiaaw)\
**Post date:** [September 30, 2023, 10:44pm UTC](https://forum.arduino.cc/t/how-to-display-morse-letters/1172856/19 "2023-09-30T22:44:47Z")

</div>

i figured it out, took a while, but testing the time taken in each of the functions i got a small figure ie 1 -5  
it was just a matter using if statements of these values to plot the movement of the btree. my head hurts don't do enough c but i should get better with time  
steve

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [March 28, 2024, 10:44pm UTC](https://forum.arduino.cc/t/how-to-display-morse-letters/1172856/20 "2024-03-28T22:44:55Z")

</div>

Closed on March 28, 2024, 10:44pm UTC

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.
