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

I needed a simple standard Python analogue and digital display along with an overload beep when used as a basic voltmeter.

Analogue readout, for quick glance. Digital readout, for better accuracy. Beep, to warn me of impending doom... ;o)

This was my starter code and works from Python 1.4.x to 2.7.x on MINIMUM platforms, AMIGA A1200, MS Windows ME and Knoppix 5.1.1. It is a stand alone program and the easiest way to start it is to import it as though it is a module.

(I DO have a Python 3.x.x version too and WILL be uploaded here in the future.)

Although this is a DEMO it did access, (home built), HW from various ports on differing platforms.

This module IS needed for it to work:-

http://code.activestate.com/recipes/577588-clear-screen-and-beep-for-various-platforms/?in=lang-python

These simple HW access modes using standard Python code WILL be released in the future.

This DEMO is released as Public Domain and you may modify it as you please...

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

73...

Bazza, G0LCU...

Team AMIGA...

Python, 87 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
# DO NOT TAKE THIS EXAMPLE TO SERIOUSLY... :)
#
# A demo analogue and digital readout using standard Python Version 1.4.x
# for a classic AMIGA A1200, Version 2.4.x for Windows ME to Vista+ and
# Version 2.5.2 for Linux. Used in CLI/Command-Prompt/Terminal mode.
# I do have a Python 3.x.x version and will upload that later... :o)
#
# This uses an experimental module that clears the screen and generates a
# beep on platforms AMIGA, MS-DOS window or screen using MS Windows ME to
# Vista and Linux using Kernel 2.4+...
# It can be found here:-
# http://code.activestate.com/recipes/577588-clear-screen-and-beep-for-various-platforms/?in=lang-python
#
# (Original copyright, (C)2006, B.Walker, G0LCU.)
# Now issued as Public Domain, you may do with it as you please.

# Import necessary modules for this demo.
import random
import time

# This is the experimental module.
import clsbeep

# Use this experimental clear screen module to clear the screen.
clsbeep.cls()

# The main working code.
def main():
	# Set up variables as global... ;o)
	global mybyte
	global digital
	global analogue
	global n

	# Allocate definite values.
	mybyte = 0
	digital = 0
	analogue = 0
	n = 0

	while 1:
		# Generate a byte number as though taken from _a_ serial, parallel or USB port.
		# I will upload simple standard Python code to access HW in the near future... :)
		mybyte = int(random.random() * 256)

		# Convert to a value to look like a 5.10V "FS" on the digital readout.
		digital = mybyte * 0.02

		# Set up a working display.
		print
		print '          Analogue and digital demo readout for simple animation test.'
		print
		print '                                   +--------+'
		print '                                     ',digital
		print '                                   +--------+'
		print

		# Convert to some sort of analogue look, 6 bit depth.
		analogue = (mybyte/5)

		print
		print '    Scale.    0   0.5  1.0  1.5  2.0  2.5  3.0  3.5  4.0  4.5  5.0'
		print '              ++++++++++++++++++++++++++++++++++++++++++++++++++++'
		print '              ',
		# Do the simple animation for the analogue look.
		n = 0
		while n <= analogue:
			print '\b|',
			n = n + 1
		print
		print '              +----+----+----+----+----+----+----+----+----+----+-'

		# Generate an "OVERLOAD" beep when above a preselected value...
		# In this case anything above "4.02" will generate an error beep.
		if digital >= 4.02:
			clsbeep.beep()

		# Hold for about 1 second.
		# Not needed when proper HW is connected, but IS needed for this demo.
		time.sleep(1)

		# Clear the screen for a re-run.
		clsbeep.cls()
main()

# End of demo.
# Enjoy finding simple solutions to often very difficult problems.