Advertisement
Guest User

Chatportal Python ich trage ne Mütze 2

a guest
Sep 19th, 2019
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.62 KB | None | 0 0
  1. import RPi.GPIO as GPIO
  2. from time import *
  3. GPIO.setmode(GPIO.BOARD)
  4. GPIO.setup(19,GPIO.IN)
  5. GPIO.setup(11, GPIO.OUT)
  6.  
  7. def empfangeByte(bitzeit):
  8.  
  9. while not GPIO.input(19):
  10. sleep(0.1*bitzeit)
  11. sleep(bitzeit * 1.5)
  12.  
  13.  
  14.  
  15. bitfolge = ''
  16. for i in range(8):
  17. if GPIO.input(19):
  18. bitfolge = bitfolge + '1'
  19. else:
  20. bitfolge = bitfolge + '0'
  21. sleep(bitzeit)
  22.  
  23. return bitfolge
  24.  
  25. def empfangeText(bitzeit):
  26. while True:
  27. byte = empfangeByte(bitzeit)
  28. zeichen = chr(int(byte, 2))
  29. print(zeichen)
  30.  
  31. def uebersetzenAusBinaer(binaercode):
  32. buchstabe = ""
  33. binaercode = int(binaercode,2)
  34. buchstabe = chr(binaercode)
  35. return buchstabe
  36.  
  37.  
  38.  
  39. def sendeByte(bitzeit, bitfolge):
  40. GPIO.output(11, True)
  41. sleep(bitzeit)
  42.  
  43. for i in bitfolge:
  44. if i == '1':
  45. GPIO.output(11, True)
  46. else:
  47. GPIO.output(11, False)
  48. sleep(bitzeit)
  49.  
  50. GPIO.output(11, False)
  51. sleep(bitzeit)
  52.  
  53. def sendeText(bitzeit, text):
  54. for zeichen in text:
  55. bitfolgeBuchstabe = bin(ord(zeichen))[2:].zfill(8)
  56. sendeByte(bitzeit, bitfolgeBuchstabe)
  57.  
  58.  
  59.  
  60. while True:
  61.  
  62. text=""
  63. Buchstabe=""
  64. while Buchstabe != "*":
  65.  
  66.  
  67. daten = empfangeByte(0.0005)
  68. Buchstabe=(uebersetzenAusBinaer(daten))
  69. text= text + Buchstabe
  70.  
  71.  
  72. print(text[:-1])
  73.  
  74. GPIO.output(11,False)
  75. sendeText(0.0005, (input("Nachricht: ") + "*"))
  76.  
  77.  
  78. GPIO.cleanup()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement