Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import RPi.GPIO as GPIO
- from time import *
- GPIO.setmode(GPIO.BOARD)
- GPIO.setup(19,GPIO.IN)
- GPIO.setup(11, GPIO.OUT)
- def empfangeByte(bitzeit):
- while not GPIO.input(19):
- sleep(0.1*bitzeit)
- sleep(bitzeit * 1.5)
- bitfolge = ''
- for i in range(8):
- if GPIO.input(19):
- bitfolge = bitfolge + '1'
- else:
- bitfolge = bitfolge + '0'
- sleep(bitzeit)
- return bitfolge
- def empfangeText(bitzeit):
- while True:
- byte = empfangeByte(bitzeit)
- zeichen = chr(int(byte, 2))
- print(zeichen)
- def uebersetzenAusBinaer(binaercode):
- buchstabe = ""
- binaercode = int(binaercode,2)
- buchstabe = chr(binaercode)
- return buchstabe
- def sendeByte(bitzeit, bitfolge):
- GPIO.output(11, True)
- sleep(bitzeit)
- for i in bitfolge:
- if i == '1':
- GPIO.output(11, True)
- else:
- GPIO.output(11, False)
- sleep(bitzeit)
- GPIO.output(11, False)
- sleep(bitzeit)
- def sendeText(bitzeit, text):
- for zeichen in text:
- bitfolgeBuchstabe = bin(ord(zeichen))[2:].zfill(8)
- sendeByte(bitzeit, bitfolgeBuchstabe)
- while True:
- text=""
- Buchstabe=""
- while Buchstabe != "*":
- daten = empfangeByte(0.0005)
- Buchstabe=(uebersetzenAusBinaer(daten))
- text= text + Buchstabe
- print(text[:-1])
- GPIO.output(11,False)
- sendeText(0.0005, (input("Nachricht: ") + "*"))
- GPIO.cleanup()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement