morse_code.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 
3 import pigpio
4 
5 morse={
6 'a':'.-' , 'b':'-...' , 'c':'-.-.' , 'd':'-..' , 'e':'.' ,
7 'f':'..-.' , 'g':'--.' , 'h':'....' , 'i':'..' , 'j':'.---' ,
8 'k':'-.-' , 'l':'.-..' , 'm':'--' , 'n':'-.' , 'o':'---' ,
9 'p':'.--.' , 'q':'--.-' , 'r':'.-.' , 's':'...' , 't':'-' ,
10 'u':'..-' , 'v':'...-' , 'w':'.--' , 'x':'-..-' , 'y':'-.--' ,
11 'z':'--..' , '1':'.----', '2':'..---', '3':'...--', '4':'....-',
12 '5':'.....', '6':'-....', '7':'--...', '8':'---..', '9':'----.',
13 '0':'-----'}
14 
15 GPIO=22
16 
17 MICROS=100000
18 
19 NONE=0
20 
21 DASH=3
22 DOT=1
23 
24 GAP=1
25 LETTER_GAP=3-GAP
26 WORD_GAP=7-LETTER_GAP
27 
28 def transmit_string(pi, gpio, str):
29 
30  pi.wave_clear() # start a new waveform
31 
32  wf=[]
33 
34  for C in str:
35  c=C.lower()
36  print(c)
37  if c in morse:
38  k = morse[c]
39  for x in k:
40 
41  if x == '.':
42  wf.append(pigpio.pulse(1<<gpio, NONE, DOT * MICROS))
43  else:
44  wf.append(pigpio.pulse(1<<gpio, NONE, DASH * MICROS))
45 
46  wf.append(pigpio.pulse(NONE, 1<<gpio, GAP * MICROS))
47 
48  wf.append(pigpio.pulse(NONE, 1<<gpio, LETTER_GAP * MICROS))
49 
50  elif c == ' ':
51  wf.append(pigpio.pulse(NONE, 1<<gpio, WORD_GAP * MICROS))
52 
53  pi.wave_add_generic(wf)
54 
55  pi.wave_tx_start()
56 
57 pi = pigpio.pi()
58 
59 pi.set_mode(GPIO, pigpio.OUTPUT)
60 
61 transmit_string(pi, GPIO, "Now is the winter of our discontent")
62 
63 while pi.wave_tx_busy():
64  pass
65 
66 transmit_string(pi, GPIO, "made glorious summer by this sun of York")
67 
68 while pi.wave_tx_busy():
69  pass
70 
71 pi.stop()
72 
def transmit_string(pi, gpio, str)
Definition: morse_code.py:28


cob_hand_bridge
Author(s): Mathias Lüdtke
autogenerated on Tue Oct 20 2020 03:35:57