Skip to content

Instantly share code, notes, and snippets.

@ukscone
Created May 6, 2014 04:05
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 ukscone/b0b28d6d0cece3961f56 to your computer and use it in GitHub Desktop.
Save ukscone/b0b28d6d0cece3961f56 to your computer and use it in GitHub Desktop.
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()
@Sekenx
Copy link

Sekenx commented Feb 1, 2016

At pibrella.button.changed(input_message_string) I get a syntax error, could you be of any help?

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