Just the audio playing to go!

This commit is contained in:
Paul Warren 2017-02-11 14:32:01 +11:00
parent 16106dbc87
commit c45113986a
2 changed files with 213 additions and 197 deletions

192
morse.py Normal file
View File

@ -0,0 +1,192 @@
import time
class Morse:
def __init__(self, drv):
self.drv = drv
def play_letter(self, alphanum):
self.play_sound(alphanum)
getattr(self, 'morse_' + alphanum)()
self.wait_letter()
def play_string(self, letters):
for letter in letters:
if letter == ' ':
self.wait_word()
else:
self.play_letter(letter)
def play_sound(self, alphanum):
pass
##################################################
# Dahs and Dits arrived at by trial and error
# Feel free to find one that works for you!
# see http://www.ti.com/lit/ds/symlink/drv2605.pdf for more info!
##################################################
def dah(self):
self.drv.setWaveform(0, 14)
self.drv.setWaveform(1, 0)
self.drv.go()
time.sleep(0.32)
def dit(self):
self.drv.setWaveform(0, 1)
self.drv.setWaveform(1, 0)
self.drv.go()
time.sleep(0.18)
def wait_letter(self):
time.sleep(0.33)
def wait_word(self):
time.sleep(0.45)
def morse_a(self):
self.dit(); self.dah();
def morse_b(self):
self.dah(); self.dit(); self.dit(); self.dit();
def morse_c(self):
self.dah(); self.dit(); self.dah(); self.dit()
def morse_d(self):
self.dah(); self.dit(); self.dit();
def morse_e(self):
self.dit();
def morse_f(self):
self.dit(); self.dit(); self.dah(); self.dit();
def morse_g(self):
self.dah(); self.dah(); self.dit();
def morse_h(self):
self.dit(); self.dit(); self.dit(); self.dit();
def morse_i(self):
self.dit(); self.dit();
def morse_j(self):
self.dit(); self.dah(); self.dah(); self.dah();
def morse_k(self):
self.dah(); self.dit(); self.dah();
def morse_l(self):
self.dit(); self.dah(); self.dit(); self.dit();
def morse_m(self):
self.dah(); self.dah();
def morse_n(self):
self.dah(); self.dit();
def morse_o(self):
self.dah(); self.dah(); self.dah();
def morse_p(self):
self.dit(); self.dah(); self.dah(); self.dit();
def morse_q(self):
self.dah(); self.dah(); self.dit(); self.dah();
def morse_r(self):
self.dit(); self.dah(); self.dit();
def morse_s(self):
self.dit(); self.dit(); self.dit();
def morse_t(self):
self.dah();
def morse_u(self):
self.dit(); self.dit(); self.dah();
def morse_v(self):
self.dit(); self.dit(); self.dit(); self.dah();
def morse_w(self):
self.dit(); self.dah(); self.dah();
def morse_x(self):
self.dah(); self.dit(); self.dit(); self.dah();
def morse_y(self):
self.dah(); self.dit(); self.dah(); self.dah();
def morse_z(self):
self.dah(); self.dah(); self.dit(); self.dit();
def morse_1(self):
self.dit(); self.dah(); self.dah(); self.dah(); self.dah();
def morse_2(self):
self.dit(); self.dit(); self.dah(); self.dah(); self.dah();
def morse_3(self):
self.dit(); self.dit(); self.dit(); self.dah(); self.dah();
def morse_4(self):
self.dit(); self.dit(); self.dit(); self.dit(); self.dah();
def morse_5(self):
self.dit(); self.dit(); self.dit(); self.dit(); self.dit();
def morse_6(self):
self.dah(); self.dit(); self.dit(); self.dit(); self.dit();
def morse_7(self):
self.dah(); self.dah(); self.dit(); self.dit(); self.dit();
def morse_8(self):
self.dah(); self.dah(); self.dah(); self.dit(); self.dit();
def morse_9(self):
self.dah(); self.dah(); self.dah(); self.dah(); self.dit();
def morse_0(self):
self.dah(); self.dah(); self.dah(); self.dah(); self.dah();

View File

@ -10,208 +10,32 @@
import time
import string
import random
from morse import Morse
from Adafruit_DRV2605 import *
drv = Adafruit_DRV2605(busnum=0)
### setup ###
drv.begin()
# I2C trigger by sending 'go' command
drv.setMode(DRV2605_MODE_INTTRIG)
drv.selectLibrary(1)
##################################################
# Dahs and Dits arrived at by trial and error
# Feel free to find one that works for you!
# see http://www.ti.com/lit/ds/symlink/drv2605.pdf for more info!
##################################################
def dah():
drv.setWaveform(0, 14)
drv.setWaveform(1, 0)
drv.go()
time.sleep(0.32)
def dit():
drv.setWaveform(0, 1)
drv.setWaveform(1, 0)
drv.go()
time.sleep(0.18)
def wait_letter():
time.sleep(0.33)
def wait_word():
time.sleep(0.45)
def a():
dit(); dah();
def b():
dah(); dit(); dit(); dit();
def c():
dah(); dit(); dah(); dit()
def d():
dah(); dit(); dit();
def e():
dit();
def f():
dit(); dit(); dah(); dit();
def g():
dah(); dah(); dit();
def h():
dit(); dit(); dit(); dit();
def i():
dit(); dit();
def j():
dit(); dah(); dah(); dah();
def k():
dah(); dit(); dah();
def l():
dit(); dah(); dit(); dit();
def m():
dah(); dah();
def n():
dah(); dit();
def O():
dah(); dah(); dah();
def p():
dit(); dah(); dah(); dit();
def q():
dah(); dah(); dit(); dah();
def r():
dit(); dah(); dit();
def s():
dit(); dit(); dit();
def t():
dah();
def u():
dit(); dit(); dah();
def v():
dit(); dit(); dit(); dah();
def w():
dit(); dah(); dah();
def x():
dah(); dit(); dit(); dah();
def y():
dah(); dit(); dah(); dah();
def z():
dah(); dah(); dit(); dit();
def m1():
dit(); dah(); dah(); dah(); dah();
def m2():
dit(); dit(); dah(); dah(); dah();
def m3():
dit(); dit(); dit(); dah(); dah();
def m4():
dit(); dit(); dit(); dit(); dah();
def m5():
dit(); dit(); dit(); dit(); dit();
def m6():
dah(); dit(); dit(); dit(); dit();
def m7():
dah(); dah(); dit(); dit(); dit();
def m8():
dah(); dah(); dah(); dit(); dit();
def m9():
dah(); dah(); dah(); dah(); dit();
def m0():
dah(); dah(); dah(); dah(); dah();
def play_morse(alphanum):
gettatr(self, alphanum)()
wait_letter()
def generateSequence(size, chars=string.ascii_lowercase + string.digits):
return random.sample(chars, size)
retval = []
for i in range(size):
retval.append(random.choice(chars))
return retval
def main(args, kwargs):
def main():
drv = Adafruit_DRV2605(busnum=0)
drv.begin()
drv.setMode(DRV2605_MODE_INTTRIG)
drv.selectLibrary(1)
morse_player = Morse(drv)
while(1):
# generate sequence
sequence = generateSequence(64)
# play sequence!
for item in sequence:
print item
morse_player.play_letter(item)
time.sleep(0.5)
if __name__ == '__main__':
main()