Display Morse code messages with your Raspberry Pi

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 morse.py

Usage morse "Read text in morse 4 me"

This will display in morse code the above text - in Red for Capitals, white for lower case, green for numbers.

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

# Load library functions
import optparse
import time

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

def dash(colour):
    LedBorg=open('/dev/ledborg','w')
    LedBorg.write(colour)
    LedBorg.close()
    time.sleep(1.5)
    LedBorg=open('/dev/ledborg','w')
    LedBorg.write("000")
    LedBorg.close()
    time.sleep(0.5)

def space():
    time.sleep(3.5)

parser = optparse.OptionParser()

args = parser.parse_args()

string = str(args[1])
toMorse2 = string[2:len(string)-2]
toMorse = toMorse2.lower()

i=0

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

    if(toMorse2[i].isupper()):
        colour = "200"
    else:
        colour = "222"

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