Last active
March 1, 2017 10:13
-
-
Save davelee212/b8e488b86dca499cbf7280707ccfa217 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# created as part of the Future Learn course on Physical Computing with Raspberry Pi | |
# takes a message entered and flashes it out in morse code to an LED on gpio pin 17 | |
# numbers are missing so only letters work | |
from gpiozero import LED | |
from time import sleep | |
import sys | |
red_led = LED(17) | |
def flashdot(): | |
print " .dot." | |
red_led.on() | |
# leave LED on for 0.3s before switching off | |
sleep(0.3) | |
red_led.off() | |
# pause of 0.3s before next letter (same as a dot length) | |
sleep(0.3) | |
def flashdash(): | |
print " -dash-" | |
red_led.on() | |
# leave LED on for 0.9s (3 times dot length) before switching off | |
sleep(0.9) | |
red_led.off() | |
# pause of 0.3s before next letter (same as a dot length) | |
sleep(0.3) | |
def flashchar(char): | |
if char == "a": | |
flashdot() | |
flashdash() | |
elif char == "b": | |
flashdash() | |
flashdot() | |
flashdot() | |
flashdot() | |
elif char == "c": | |
flashdash() | |
flashdot() | |
flashdash() | |
flashdot() | |
elif char == "d": | |
flashdash() | |
flashdot() | |
flashdot() | |
elif char == "e": | |
flashdot() | |
elif char == "f": | |
flashdot() | |
flashdot() | |
flashdash() | |
flashdot() | |
elif char == "g": | |
flashdash() | |
flashdash() | |
flashdot() | |
elif char == "h": | |
flashdot() | |
flashdot() | |
flashdot() | |
flashdot() | |
elif char == "i": | |
flashdot() | |
flashdot() | |
elif char == "j": | |
flashdot() | |
flashdash() | |
flashdash() | |
flashdash() | |
elif char == "k": | |
flashdash() | |
flashdot() | |
flashdash() | |
elif char == "l": | |
flashdot() | |
flashdash() | |
flashdot() | |
flashdot() | |
elif char == "m": | |
flashdash() | |
flashdash() | |
elif char == "n": | |
flashdash() | |
flashdot() | |
elif char == "o": | |
flashdash() | |
flashdash() | |
flashdash() | |
elif char == "p": | |
flashdot() | |
flashdash() | |
flashdash() | |
flashdot() | |
elif char == "q": | |
flashdash() | |
flashdash() | |
flashdot() | |
flashdash() | |
elif char == "r": | |
flashdot() | |
flashdash() | |
flashdot() | |
elif char == "s": | |
flashdot() | |
flashdot() | |
flashdot() | |
elif char == "t": | |
flashdash() | |
elif char == "u": | |
flashdot() | |
flashdot() | |
flashdash() | |
elif char == "v": | |
flashdot() | |
flashdot() | |
flashdot() | |
flashdash() | |
elif char == "w": | |
flashdot() | |
flashdash() | |
flashdash() | |
elif char == "x": | |
flashdash() | |
flashdot() | |
flashdot() | |
flashdash() | |
elif char == "y": | |
flashdash() | |
flashdot() | |
flashdash() | |
flashdash() | |
elif char == "z": | |
flashdash() | |
flashdash() | |
flashdot() | |
flashdot() | |
elif char == " ": | |
# space between words is represented as a silence the length of 3 dots | |
print " * pause - new word *" | |
sleep(0.9) | |
message = raw_input("Enter message: ") | |
for letter in message: | |
print 'Sending ' + letter | |
flashchar(letter)" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment