Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import RPi.GPIO as GPIO
- import time
- CODE = {' ': ' ',
- "'": '.----.',
- '(': '-.--.-',
- ')': '-.--.-',
- ',': '--..--',
- '-': '-....-',
- '.': '.-.-.-',
- '/': '-..-.',
- '0': '-----',
- '1': '.----',
- '2': '..---',
- '3': '...--',
- '4': '....-',
- '5': '.....',
- '6': '-....',
- '7': '--...',
- '8': '---..',
- '9': '----.',
- ':': '---...',
- ';': '-.-.-.',
- '?': '..--..',
- 'A': '.-',
- 'B': '-...',
- 'C': '-.-.',
- 'D': '-..',
- 'E': '.',
- 'F': '..-.',
- 'G': '--.',
- 'H': '....',
- 'I': '..',
- 'J': '.---',
- 'K': '-.-',
- 'L': '.-..',
- 'M': '--',
- 'N': '-.',
- 'O': '---',
- 'P': '.--.',
- 'Q': '--.-',
- 'R': '.-.',
- 'S': '...',
- 'T': '-',
- 'U': '..-',
- 'V': '...-',
- 'W': '.--',
- 'X': '-..-',
- 'Y': '-.--',
- 'Z': '--..',
- '_': '..--.-'}
- ledPin=17
- boton=12
- buzzer=6
- GPIO.setmode(GPIO.BCM)
- GPIO.setup(ledPin,GPIO.OUT)
- GPIO.setup(buzzer,GPIO.OUT)
- GPIO.setup(boton, GPIO.IN)
- prevPress = 0
- def RCtime (RCpin):
- reading = 0
- GPIO.setup(RCpin, GPIO.OUT)
- GPIO.output(RCpin, GPIO.LOW)
- time.sleep(0.1)
- GPIO.setup(RCpin, GPIO.IN)
- while (GPIO.input(RCpin) == GPIO.LOW):
- reading += 1
- return reading
- def dot(pina):
- try:
- while True:
- GPIO.output(pina,1)
- time.sleep(0.2)
- GPIO.output(pina,0)
- time.sleep(0.2)
- break
- except KeyboardInterrupt:
- GPIO.cleanup()
- exit
- def dash(pina):
- try:
- while True:
- GPIO.output(pina,1)
- time.sleep(0.5)
- GPIO.output(pina,0)
- time.sleep(0.2)
- break
- except KeyboardInterrupt:
- GPIO.cleanup()
- exit
- while True:
- input = raw_input('What would you like to send? ')
- for letter in input:
- for symbol in CODE[letter.upper()]:
- press = RCtime(12)
- print(press)
- if symbol == '-':
- if(press<3000):
- dash(17)
- else:
- dash(6)
- elif symbol == '.':
- if(press<3000):
- dot(17)
- else:
- dot(6)
- else:
- time.sleep(0.5)
- time.sleep(0.5)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement