MorseBorg - Display Morse code messages with your Raspberry Pi (Mk II)

This is an old driver based LedBorg script
We recommend using the new driver free based scripts for LedBorg.
The new driver free examples can be found here, the installation can be found here.

The following is code for a python based morse code indicator for the LedBorg
Download python as text here
Save as morseBorg.py
To make the script executable enter the following in the terminal:
chmod +x morseBorg.py

Usage:
./morseBorg.py [-s speed] "Read text in morse 4 me"
where speed is the dot time in seconds, for example:
./morseBorg.py "My name is Peter"
will use the default speed (0.5 seconds), where as
./morseBorg.py -s 0.1 "Red cars go faster"
will display five times as fast.

This will display in morse code the above text - in red for capitals, white for lower case, blue for numbers and green for symbols.

#!/usr/bin/env python
# coding: Latin-1

# Load library functions
import optparse
import time

def dot(colour,speed):
    LedBorg=open('/dev/ledborg','w')
    LedBorg.write(colour)
    LedBorg.close()
    print '. '
    time.sleep(speed)
    LedBorg=open('/dev/ledborg','w')
    LedBorg.write("000")
    LedBorg.close()
    time.sleep(speed)

def dash(colour,speed):
    LedBorg=open('/dev/ledborg','w')
    LedBorg.write(colour)
    LedBorg.close()
    print'- '
    time.sleep(3*speed)
    LedBorg=open('/dev/ledborg','w')
    LedBorg.write("000")
    LedBorg.close()
    time.sleep(speed)

def space(speed):
    print ' '
    time.sleep(7*speed)

parser = optparse.OptionParser()
parser.add_option("-s", "--speed", action="store", type = "float", dest="speed", default = 0.5, help="speed of the morse code dot in seconds")

(options,args) = parser.parse_args()

print args

speed = options.speed

j=0
string = ''
while j<len(args):
    string = string + args[j] + ' '
    j=j+1

toMorse2 = string
toMorse = toMorse2.lower()

i=0

while i<len(toMorse):
    print toMorse[i]

    if(toMorse2[i].isupper()):
        colour = "200"
    elif(toMorse2[i].islower()):
        colour = "222"
    elif(toMorse2[i].isdigit()):
        colour = "002"
    else :
        colour = "020"

    if(toMorse[i]=='a'):
       dot(colour,speed)
       dash(colour,speed)
    if(toMorse[i]=='b'):
       dash(colour,speed)
       dot(colour,speed)
       dot(colour,speed)
       dot(colour,speed)
    if(toMorse[i]=='c'):
       dash(colour,speed)
       dot(colour,speed)
       dash(colour,speed)
       dot(colour,speed)
    if(toMorse[i]=='d'):
       dash(colour,speed)
       dot(colour,speed)
       dot(colour,speed)
    if(toMorse[i]=='e'):
       dot(colour,speed)
    if(toMorse[i]=='f'):
       dot(colour,speed)
       dot(colour,speed)
       dash(colour,speed)
       dot(colour,speed)
    if(toMorse[i]=='g'):
       dash(colour,speed)
       dash(colour,speed)
       dot(colour,speed)
    if(toMorse[i]=='h'):
       dot(colour,speed)
       dot(colour,speed)
       dot(colour,speed)
       dot(colour,speed)
    if(toMorse[i]=='i'):
       dot(colour,speed)
       dot(colour,speed)
    if(toMorse[i]=='j'):
       dot(colour,speed)
       dash(colour,speed)
       dash(colour,speed)
       dash(colour,speed)
    if(toMorse[i]=='k'):
       dash(colour,speed)
       dot(colour,speed)
       dash(colour,speed)
    if(toMorse[i]=='l'):
       dot(colour,speed)
       dash(colour,speed)
       dot(colour,speed)
       dot(colour,speed)
    if(toMorse[i]=='m'):
       dash(colour,speed)
       dash(colour,speed)
    if(toMorse[i]=='n'):
       dash(colour,speed)
       dot(colour,speed)
    if(toMorse[i]=='o'):
       dash(colour,speed)
       dash(colour,speed)
       dash(colour,speed)
    if(toMorse[i]=='p'):   
       dot(colour,speed)
       dash(colour,speed)
       dash(colour,speed)
       dot(colour,speed)
    if(toMorse[i]=='q'):
       dash(colour,speed)
       dash(colour,speed)
       dash(colour,speed)
    if(toMorse[i]=='r'):
       dot(colour,speed)
       dash(colour,speed)
       dot(colour,speed)
    if(toMorse[i]=='s'):
       dot(colour,speed)
       dot(colour,speed)
       dot(colour,speed)
    if(toMorse[i]=='t'):
       dash(colour,speed)
    if(toMorse[i]=='u'):
       dot(colour,speed)
       dot(colour,speed)
       dash(colour,speed)
    if(toMorse[i]=='v'):
       dot(colour,speed)
       dot(colour,speed)
       dot(colour,speed)
       dash(colour,speed)
    if(toMorse[i]=='w'):
       dot(colour,speed)
       dash(colour,speed)
       dash(colour,speed)
    if(toMorse[i]=='x'):
       dash(colour,speed)
       dot(colour,speed)
       dot(colour,speed)
       dash(colour,speed)
    if(toMorse[i]=='y'):
       dash(colour,speed)
       dot(colour,speed)
       dash(colour,speed)
       dash(colour,speed)
    if(toMorse[i]=='z'):
       dash(colour,speed)
       dash(colour,speed)
       dot(colour,speed)
       dot(colour,speed)
    if(toMorse[i]==' '):
       space(speed)
    if(toMorse[i]=='1'):
       dot(colour,speed)
       dash(colour,speed)
       dash(colour,speed)
       dash(colour,speed)
       dash(colour,speed)
    if(toMorse[i]=='2'):
       dot(colour,speed)
       dot(colour,speed)
       dash(colour,speed)
       dash(colour,speed)
       dash(colour,speed)
    if(toMorse[i]=='3'):
       dot(colour,speed)
       dot(colour,speed)
       dot(colour,speed)
       dash(colour,speed)
       dash(colour,speed)
    if(toMorse[i]=='4'):
       dot(colour,speed)
       dot(colour,speed)
       dot(colour,speed)
       dot(colour,speed)
       dash(colour,speed)
       dash(colour,speed)
    if(toMorse[i]=='5'):
       dot(colour,speed)
       dot(colour,speed)
       dot(colour,speed)
       dot(colour,speed)
       dot(colour,speed)
    if(toMorse[i]=='6'):
       dash(colour,speed)
       dot(colour,speed)
       dot(colour,speed)
       dot(colour,speed)
       dot(colour,speed)
    if(toMorse[i]=='7'):
       dash(colour,speed)
       dash(colour,speed)
       dot(colour,speed)
       dot(colour,speed)
       dot(colour,speed)
    if(toMorse[i]=='8'):
       dash(colour,speed)
       dash(colour,speed)
       dash(colour,speed)
       dot(colour,speed)
       dot(colour,speed)
    if(toMorse[i]=='9'):
       dash(colour,speed)
       dash(colour,speed)
       dash(colour,speed)
       dash(colour,speed)
       dot(colour,speed)
    if(toMorse[i]=='0'):
       dash(colour,speed)
       dash(colour,speed)
       dash(colour,speed)
       dash(colour,speed)
       dash(colour,speed)
    if(toMorse[i]=='.'):
       dot(colour,speed)
       dash(colour,speed)
       dot(colour,speed)
       dash(colour,speed)
       dot(colour,speed)
       dash(colour,speed)
    if(toMorse[i]==','):
       dash(colour,speed)
       dash(colour,speed)
       dot(colour,speed)
       dot(colour,speed)
       dash(colour,speed)
       dash(colour,speed)
    if(toMorse[i]=='?'):
       dot(colour,speed)
       dot(colour,speed)
       dash(colour,speed)
       dash(colour,speed)
       dot(colour,speed) 
       dot(colour,speed)
    if(toMorse[i]=='\''):
       dot(colour,speed)
       dash(colour,speed)
       dash(colour,speed)
       dash(colour,speed)
       dash(colour,speed)
       dot(colour,speed)
    if(toMorse[i]=='!'):
       dash(colour,speed)
       dot(colour,speed)
       dash(colour,speed)
       dot(colour,speed)
       dash(colour,speed)
       dash(colour,speed)
    if(toMorse[i]=='/'):
       dash(colour,speed)
       dot(colour,speed)
       dot(colour,speed)
       dash(colour,speed)
       dot(colour,speed)
    if(toMorse[i]=='(' or toMorse[i]==')'):
       dash(colour,speed)
       dot(colour,speed)
       dash(colour,speed)
       dash(colour,speed)
       dot(colour,speed)
       if(toMorse[i]==')'):
           dash(colour,speed)
    if(toMorse[i]=='&'):
       dot(colour,speed)
       dash(colour,speed)
       dot(colour,speed)
       dot(colour,speed)
       dot(colour,speed)
    if(toMorse[i]==':'):
       dash(colour,speed)
       dash(colour,speed)
       dash(colour,speed)
       dot(colour,speed)
       dot(colour,speed)
       dot(colour,speed)
    if(toMorse[i]==';'):
       dash(colour,speed)
       dot(colour,speed)
       dash(colour,speed)
       dot(colour,speed)
       dash(colour,speed)
       dot(colour,speed)
    if(toMorse[i]=='='):
       dash(colour,speed)
       dot(colour,speed)
       dot(colour,speed)
       dot(colour,speed)
       dash(colour,speed)
    if(toMorse[i]=='+'):
       dot(colour,speed)
       dash(colour,speed)
       dot(colour,speed)
       dash(colour,speed)
       dot(colour,speed)
    if(toMorse[i]=='-'):
       dash(colour,speed)
       dot(colour,speed)
       dot(colour,speed)
       dot(colour,speed)
       dot(colour,speed)
       dash(colour,speed)
    if(toMorse[i]=='_'):
       dot(colour,speed)
       dot(colour,speed)
       dash(colour,speed)
       dash(colour,speed)
       dot(colour,speed)
       dash(colour,speed)
    if(toMorse[i]=='\"'):
       dot(colour,speed)
       dash(colour,speed)
       dot(colour,speed)
       dot(colour,speed)
       dash(colour,speed)
       dot(colour,speed)
    if(toMorse[i]=='$'):
       dot(colour,speed)
       dot(colour,speed)
       dot(colour,speed)
       dash(colour,speed)
       dot(colour,speed)
       dot(colour,speed)
       dash(colour,speed)
    if(toMorse[i]=='@'):
       dot(colour,speed)
       dash(colour,speed)
       dash(colour,speed)
       dot(colour,speed)
       dash(colour,speed)
       dot(colour,speed)
    time.sleep(3*speed)
    i=i+1
Subscribe to Comments for &quot;MorseBorg - Display Morse code messages with your Raspberry Pi (Mk II)&quot;