sasha
23 Nov 09, 03:21 PM
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:
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!
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:
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!