Advertisement
Guest User

LOLA

a guest
Oct 18th, 2017
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.81 KB | None | 0 0
  1. import RPi.GPIO as GPIO
  2. import time
  3.  
  4. CODE = {' ': ' ',
  5. "'": '.----.',
  6. '(': '-.--.-',
  7. ')': '-.--.-',
  8. ',': '--..--',
  9. '-': '-....-',
  10. '.': '.-.-.-',
  11. '/': '-..-.',
  12. '0': '-----',
  13. '1': '.----',
  14. '2': '..---',
  15. '3': '...--',
  16. '4': '....-',
  17. '5': '.....',
  18. '6': '-....',
  19. '7': '--...',
  20. '8': '---..',
  21. '9': '----.',
  22. ':': '---...',
  23. ';': '-.-.-.',
  24. '?': '..--..',
  25. 'A': '.-',
  26. 'B': '-...',
  27. 'C': '-.-.',
  28. 'D': '-..',
  29. 'E': '.',
  30. 'F': '..-.',
  31. 'G': '--.',
  32. 'H': '....',
  33. 'I': '..',
  34. 'J': '.---',
  35. 'K': '-.-',
  36. 'L': '.-..',
  37. 'M': '--',
  38. 'N': '-.',
  39. 'O': '---',
  40. 'P': '.--.',
  41. 'Q': '--.-',
  42. 'R': '.-.',
  43. 'S': '...',
  44. 'T': '-',
  45. 'U': '..-',
  46. 'V': '...-',
  47. 'W': '.--',
  48. 'X': '-..-',
  49. 'Y': '-.--',
  50. 'Z': '--..',
  51. '_': '..--.-'}
  52.  
  53. ledPin=17
  54. boton=12
  55. buzzer=6
  56.  
  57. GPIO.setmode(GPIO.BCM)
  58. GPIO.setup(ledPin,GPIO.OUT)
  59. GPIO.setup(buzzer,GPIO.OUT)
  60. GPIO.setup(boton, GPIO.IN)
  61. prevPress = 0
  62.  
  63. def RCtime (RCpin):
  64. reading = 0
  65. GPIO.setup(RCpin, GPIO.OUT)
  66. GPIO.output(RCpin, GPIO.LOW)
  67. time.sleep(0.1)
  68. GPIO.setup(RCpin, GPIO.IN)
  69.  
  70. while (GPIO.input(RCpin) == GPIO.LOW):
  71. reading += 1
  72. return reading
  73.  
  74. def dot(pina):
  75. try:
  76. while True:
  77. GPIO.output(pina,1)
  78. time.sleep(0.2)
  79. GPIO.output(pina,0)
  80. time.sleep(0.2)
  81. break
  82. except KeyboardInterrupt:
  83. GPIO.cleanup()
  84. exit
  85.  
  86.  
  87. def dash(pina):
  88. try:
  89. while True:
  90. GPIO.output(pina,1)
  91. time.sleep(0.5)
  92. GPIO.output(pina,0)
  93. time.sleep(0.2)
  94. break
  95. except KeyboardInterrupt:
  96. GPIO.cleanup()
  97. exit
  98. while True:
  99. input = raw_input('What would you like to send? ')
  100. for letter in input:
  101.  
  102. for symbol in CODE[letter.upper()]:
  103. press = RCtime(12)
  104. print(press)
  105. if symbol == '-':
  106. if(press<3000):
  107. dash(17)
  108. else:
  109. dash(6)
  110.  
  111. elif symbol == '.':
  112. if(press<3000):
  113. dot(17)
  114. else:
  115. dot(6)
  116. else:
  117. time.sleep(0.5)
  118. time.sleep(0.5)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement