How to display morse letters

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.


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

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.

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');
...

, element-pause

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

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

The standard for morse timing.

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

@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.

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

explains how the sender should establish its timing.

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

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

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

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

Me 2 :frowning:

What do you want to do:

  • send morse code?
  • receive morse code?

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

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

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.

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 ) ;
    }
  
}

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.

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

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

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