00001
00002
00003 import pigpio
00004
00005 morse={
00006 'a':'.-' , 'b':'-...' , 'c':'-.-.' , 'd':'-..' , 'e':'.' ,
00007 'f':'..-.' , 'g':'--.' , 'h':'....' , 'i':'..' , 'j':'.---' ,
00008 'k':'-.-' , 'l':'.-..' , 'm':'--' , 'n':'-.' , 'o':'---' ,
00009 'p':'.--.' , 'q':'--.-' , 'r':'.-.' , 's':'...' , 't':'-' ,
00010 'u':'..-' , 'v':'...-' , 'w':'.--' , 'x':'-..-' , 'y':'-.--' ,
00011 'z':'--..' , '1':'.----', '2':'..---', '3':'...--', '4':'....-',
00012 '5':'.....', '6':'-....', '7':'--...', '8':'---..', '9':'----.',
00013 '0':'-----'}
00014
00015 GPIO=22
00016
00017 MICROS=100000
00018
00019 NONE=0
00020
00021 DASH=3
00022 DOT=1
00023
00024 GAP=1
00025 LETTER_GAP=3-GAP
00026 WORD_GAP=7-LETTER_GAP
00027
00028 def transmit_string(pi, gpio, str):
00029
00030 pi.wave_clear()
00031
00032 wf=[]
00033
00034 for C in str:
00035 c=C.lower()
00036 print(c)
00037 if c in morse:
00038 k = morse[c]
00039 for x in k:
00040
00041 if x == '.':
00042 wf.append(pigpio.pulse(1<<gpio, NONE, DOT * MICROS))
00043 else:
00044 wf.append(pigpio.pulse(1<<gpio, NONE, DASH * MICROS))
00045
00046 wf.append(pigpio.pulse(NONE, 1<<gpio, GAP * MICROS))
00047
00048 wf.append(pigpio.pulse(NONE, 1<<gpio, LETTER_GAP * MICROS))
00049
00050 elif c == ' ':
00051 wf.append(pigpio.pulse(NONE, 1<<gpio, WORD_GAP * MICROS))
00052
00053 pi.wave_add_generic(wf)
00054
00055 pi.wave_tx_start()
00056
00057 pi = pigpio.pi()
00058
00059 pi.set_mode(GPIO, pigpio.OUTPUT)
00060
00061 transmit_string(pi, GPIO, "Now is the winter of our discontent")
00062
00063 while pi.wave_tx_busy():
00064 pass
00065
00066 transmit_string(pi, GPIO, "made glorious summer by this sun of York")
00067
00068 while pi.wave_tx_busy():
00069 pass
00070
00071 pi.stop()
00072