So my cubs last night did a James Bond themed evening with various code breaking opportunities. Useing My raspberry pi tablet i used https://www.cl.cam.ac.uk/ Morse code program to flash an led. Some work after cubs made the following program that beeps a buzzer and writes out the dash and dots on the screen.
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=21
ledPin2=20
ledPin3=12
GPIO.setmode(GPIO.BCM)
GPIO.setup(ledPin,GPIO.OUT)
GPIO.setup(ledPin2,GPIO.OUT)
GPIO.setup(ledPin3,GPIO.OUT)
GPIO.setup(5, GPIO.OUT)
def dot():
print "Dot"
GPIO.output(ledPin,1)
GPIO.output(5, True)
time.sleep(0.2)
GPIO.output(ledPin,0)
GPIO.output(5, False)
time.sleep(0.2)
def dash():
print "Dash"
GPIO.output(ledPin2,2)
GPIO.output(5, True)
time.sleep(0.5)
GPIO.output(ledPin2,0)
GPIO.output(5, False)
time.sleep(0.2)
while True:
input = raw_input('What would you like to send? ')
for letter in input:
for symbol in CODE[letter.upper()]:
if symbol == '-':
dash()
elif symbol == '.':
dot()
else:
GPIO.output(ledPin3,1)
time.sleep(0.5)
GPIO.output(ledPin3,0)
print "Space"
time.sleep(0.5)
Posted later as i got distracted.
You must be logged in to post a comment.