Welcome, guest | Sign In | My Account | Store | Cart

This is not for the big guns, but for the Amateur coder AND radio enthusiast.

It is a DEMO Morse Code Practice Oscillator that will allow the user to practice sending Morse code using the "o" and "p" keys as a PSEUDO-paddle key. It is set to around 8 WPM, (Words Per Minute). The code allows "O" and "P" to be used at around 12 WPM, when "Caps Lock" is turned on. Read the code for more informtion.

It is for at least standard text mode Python 2.5.2 to 2.7.2 using PCLinuxOS 2009 and Debian 6.0.0. It may well work at a much earlier version. I do have a version for Python 3.x.x but that will be uploaded elsewhere.

It is written in such a way that youngsters can understand what is going on.

Enjoy finding simple solutions to often very difficult problems... ;o)

Bazza, G0LCU...

Python, 92 lines
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# MPO2x.py
#
# A DEMO, very crude, Morse Code Practice Oscillator...
# Tested on Debian 6.0.0 using Python 2.6.6 and 2.7.2 and PCLinuxOS 2009 using Python 2.5.2.
# It may well work on earlier Python versions but is untested.
#
# (C)2011-2012, B.Walker, G0LCU. Now issued as Public Domain...
#
# The device, "/dev/audio" is required for this to work. Install "oss-compat" from your
# distro's repository if you haven't got "/dev/audio". Ensure the sound system is NOT
# in use by other programs and use the OS's mixing facilities to set the levels.
#
# Copy the file to the Lib folder(/drawer/directory) or where the modules
# reside as "MPO2x.py"...
#
# For a quick way to run just use at the ">>>" prompt:-
#
# >>> import MPO2x<RETURN/ENTER>
#
# And away we go...
#
# Written in such a way that youngsters can understand what is going on.
#
# Enjoy finding simple solutiuons to often very difficult problems... ;o)

def main():
	# Just three imports required for this DEMO.
	import sys
	import termios
	import tty

	# Set as globals, my choice... ;o)
	global character
	global delay
	global n

	character="(C)2011-2012, B.Walker, G0LCU."
	delay=75
	n=0

	# This is a working function; something akin to the BASIC INKEY$ function...
	# Reference:- http://code.activestate.com/recipes/134892-getch-like-unbuffered-character-reading-from-stdin/
	# Many thanks to Danny Yoo for the above code, modified to suit this program...
	# In THIS FUNCTION some special keys do a "break" similar to the "Esc" key inside the program.
	# Be aware of this...
	def inkey():
		fd=sys.stdin.fileno()
		remember_attributes=termios.tcgetattr(fd)
		tty.setraw(sys.stdin.fileno())
		character=sys.stdin.read(1)
		termios.tcsetattr(fd, termios.TCSADRAIN, remember_attributes)
		return character

	while 1:
		# A simple clear screen and user display...
		for n in range(0,32,1):
			print "\n"
		print "A simple crude Morse Code Practice Oscillator...\n"
		print "Press the 'o', 'p' or 'Esc' keys...\n"
		print "Pseudo-paddle simulation, 'o' is the 'dah' and 'p' is the 'dit'...\n"
		print "(C)2011-2012, B.Walker, G0LCU. Issued as Public Domain...\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"

		# Open "/dev/audio" in write mode...
		audio=open("/dev/audio", "wb")

		# Use the "inkey()" function to get a key character.
		character=inkey()

		# Get out ensuring that the audio device is closed.
		if character==chr(27):
			audio.close()
			break

		# This is a VERY crude simulation of a paddle key to send your Morse Code.
		# It IS quirky, but, is there a better way using standard Text Mode Python?
		# It uses only the keys "o", "O", "p", "P" and "Esc"...
		# Lower case is the slowest speed, upper case the fastest speed.
		delay=0
		if character=="p": delay=75
		if character=="P": delay=50
		if character=="o": delay=225
		if character=="O": delay=150

		# Play a crude sine-wave note at 1KHz of length "delay"...
		for n in range(0,delay,1):
			audio.write(chr(15)+chr(45)+chr(63)+chr(45)+chr(15)+chr(3)+chr(0)+chr(3))
		# Ensure that the audio device is closed after each beep!
		audio.close()
main()

# End of MPO2x.py DEMO...
# Enjoy finding simple solutiuons to often very difficult problems... ;o)

You don't need a Maths or Physics Doctorate to do these things for yourselves, just someone to lay down the ideas so that you can expand and make them much better...

Good luck guys and gals, and......

Enjoy finding simple solutions to often VERY difficult problems...

Bazza, G0LCU...