Created
May 6, 2014 04:05
-
-
Save ukscone/b0b28d6d0cece3961f56 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
import pibrella, sys, time | |
morse_table = { | |
'.-': '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', | |
'-----': '0', | |
'.----': '1', | |
'..---': '2', | |
'...--': '3', | |
'....-': '4', | |
'.....': '5', | |
'-....': '6', | |
'--...': '7', | |
'---..': '8', | |
'----.': '9', | |
'--..--': ',', | |
'.-.-.-': '.', | |
'..--..': '?', | |
'-.-.-.': ';', | |
'---...': ':', | |
'.----.': "'", | |
'-....-': '-', | |
'-..-.': '/', | |
'-.--.-': '(', | |
'-.--.-': ')', | |
'..--.-': '_' | |
} | |
def input_message_string(pin): | |
global pressed | |
global message_string | |
global released | |
global character | |
if pin.read() == 1: | |
if character == ".......": | |
exit() | |
pressed = time.time() | |
if released != 0: | |
if (pressed - released) > 1.0: | |
message_string+=" ("+morse_table[character]+") " | |
character="" | |
pibrella.light.on() | |
#pibrella.buzzer.buzz(440) | |
else: | |
pibrella.light.off() | |
#pibrella.buzzer.stop() | |
released=time.time() | |
if (released - pressed) < 0.3: | |
message_string+="." | |
character+="." | |
else: | |
message_string+="-" | |
character+="-" | |
pibrella.button.changed(input_message_string) | |
pressed=0 | |
released=0 | |
message_string="" | |
character="" | |
while True: | |
print '\r', message_string, | |
sys.stdout.flush() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
At pibrella.button.changed(input_message_string) I get a syntax error, could you be of any help?