Skip to content

Instantly share code, notes, and snippets.

@rickymoorhouse
Last active December 29, 2015 20:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rickymoorhouse/7721360 to your computer and use it in GitHub Desktop.
Save rickymoorhouse/7721360 to your computer and use it in GitHub Desktop.
Morse code moustache...video to follow
#!/usr/bin/python
import time
from pyglow import PyGlow
def flash(char):
if char == '-': # Dashes... in yellow
print '-'
pyglow.color(4,255)
time.sleep(1)
pyglow.color(4,0)
time.sleep(.2)
else: # If it's not a dash then it's a dot - let's use blue
print '.'
pyglow.color(2,255)
time.sleep(.5)
pyglow.color(2,0)
time.sleep(.2)
# The morse alphabet
morse = {
'A': '.-', 'B': '-...', 'C': '-.-.', 'D': '-..',
'E': '.', 'F': '..-.', 'G': '--.', 'H': '....',
'I': '..', 'J': '.---', 'K': '-.-', 'L': '.-..',
'M': '--', 'N': '-.', 'O': '---', 'P': '.--.',
'Q': '--.-', 'R': '.-.', 'S': '...', 'T': '-',
'U': '..-', 'V': '...-', 'W': '.--', 'X': '-..-',
'Y': '-.--', 'Z': '--..'}
# Import PyGlow for my PiGlow (of course) and reset to all off
pyglow = PyGlow()
pyglow.all(0)
# Start with a nice moustache ~~
text = 'MOUSTACHE'
# split text into letters
for letter in text:
# Work out the morse code for this letter
coded = morse[letter]
# For each dot or dash do the flash
for char in coded:
flash(char)
time.sleep(.5) # Gap between letters
@rickymoorhouse
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment