Morse Code

Discussion in 'Pascal Logic Code Examples' started by sasha, Nov 23, 2009.

  1. sasha

    sasha

    Joined:
    Apr 10, 2006
    Messages:
    11
    Likes Received:
    0
    I was surprised to find that colour c-touch doesn't support morse code ;)

    I was trying out tcp/ip sockets and came up with this to take a message from a socket and flash out the morse code:

    Code:
    ReadServerSocket(ReceivedString, #13#10);
    
    if ReceivedString <> '' then
    begin
      for CharIndex := 1 to length(ReceivedString) do
      begin
        c := ReceivedString[CharIndex];
        if (c >= 'a') and (c <= 'z') then
          c := chr(ord(c) - ord('a') + ord('A'));
        if (c >= 'A') and (c <= 'Z') or (c >= '0') and (c <= '9') or (c = '.')  or (c = ',') or (c = '?')  then
        begin
          case c of
            'A' : s := '.-';
            'B' : s := '-...';
            'C' : s := '-.-.';
            'D' : s := '-..';
            'E' : s := '.';
            'F' : s := '..-.';
            'G' : s := '--.';
            'H' : s := '....';
            'I' : s := '..';
            'J' : s := '.---';
            'K' : s := '-.-';
            'L' : s := '.-..';
            'M' : s := '--';
            'N' : s := '-.';
            'O' : s := '---';
            'P' : s := '.--.';
            'Q' : s := '--.-';
            'R' : s := '.-.';
            'S' : s := '...';
            'T' : s := '-';
            'U' : s := '..-';
            'V' : s := '...-';
            'W' : s := '.--';
            'X' : s := '-..-';
            'Y' : s := '-.--';
            'Z' : s := '--..';
            '0' : s := '-----';
            '1' : s := '.----';
            '2' : s := '..---';
            '3' : s := '...--';
            '4' : s := '....-';
            '5' : s := '.....';
            '6' : s := '-....';
            '7' : s := '--...';
            '8' : s := '---..';
            '9' : s := '----.';
            '.' : s := '.-.-.-';
            ',' : s := '--..--';
            '?' : s := '..--..';
          end;
          for DotDashIndex := 1 to length(s) do
          begin
            SetLightingState("Light", ON);
            if s[DotDashIndex] = '.' then
              delay(0.4)
            else
              delay(1.2);
            SetLightingState("Light", OFF);
            delay(0.6);
          end;
          delay(2);
        end;
      end;
    end;
    If I was feeling adventurous i would see if i could use a light sensor to read the light level and turn it back into text!
     
    sasha, Nov 23, 2009
    #1
  2. sasha

    Duncan

    Joined:
    Jul 23, 2004
    Messages:
    925
    Likes Received:
    0
    Location:
    Salinas de Garci Mendoza, Bolivia
    Thats awesome :) Uncle Don will be pleased with your creativity!

    Duncan.
     
    Duncan, Nov 23, 2009
    #2
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.