Symbol I = b1 'generic loop variable for announcing tones
Symbol J = b2 'another generic variable used for announcing tones
Symbol N = b3 'yet another generic variable to use in announcing tones
Symbol V = b4 'whole volts measured
Symbol D = b5 'decimal (1/10s) volts measured
Symbol P = b6 'pitch of tone
Symbol AD = w4 'WORD analog voltage value measured
;666666666666666666666666666666666666666666666666666666666666666666666666
; We don't always have to make Morse Code noises.....
; In this program, the voltage read in vrom the voltage divider input
; is measured by the Picaxe which sets up two variables:
; V = Volts
; D = tenths of Volts
;
; Audio output takes the form of:
; VOLTS:
; high pitch long 'dahs' count for 5
; high pitch short 'dits' count 1
; TENTHS OF VOLTS:
; low pitch long 'dahs' count for 5
; low pitch short 'dits' count 1
;
; So 12.6 volts would sound like this:
; HIGH PITCH dah dah dit dit (12)
; LOW PITCH dah dit (6)
; FAR shorter than listening for the full Morse Code for 12.6
'Define the Input & Output lines
Output 0 'OPTO #1
Output 1 'OPTO #2 *OR* PIEZO/SPEAKER
Input 2 'MUX SWITCHES *OR* VOLTAGE INPUT
Input 3 'IR INPUT
Input 4 'SWITCH *OR* ONE-WIRE TEMP SENSOR
'Define come constants used in generating Morse Code
Symbol Time1=3000 'time between chirping and sending call sign = 3 sec. or 3000 msec.
Symbol Time2=5000 'time between becon transmissions = 30 sec. or 30000 msec.
Symbol Keypin=0 'Keying through Opto1
Symbol PZOpin=1 'Piezo sounder here
Symbol HI=122 'high pitch value for volts
Symbol Lo=60 'low pitch value for tenths
Symbol Long=35 'long tone length
Symbol Short=10 'short tone length
'Define some variables to hold variable data
VOLTS:
Gosub V15 'Go read the V15 analog input voltage
P=HI 'set high pitch
N=V 'set number to announce
Gosub DIDA 'announce whole volts
Pause 1000 'an inter-note pause
P=LO 'set low pitch
N=D
Gosub DIDA 'announce tenths of volts
Pause 60000 'wait 60 seconds
Goto Volts 'announce the voltage again...
DIDA: J=N/5 'calculate number of long tones needed
If J=0 then NO5S 'NO whole volts?
For I=1 to J 'sound N long tones
Sound 1,(P,LONG,0,SHORT) 'make a long tone & a little silence
Next I
NO5S: J=N//5 'calculate remainder (=# of short tones)
If J=0 then NO10S 'any tenths of a volt?
For I=1 to J 'sound N short tones
Sound 1,(P,SHORT,0,SHORT)
Next I
NO10S:Return
;15 VOLT MONITOR
; This subroutine reads an analog voltage on logical pin 2
; Resistors RG & RO comprise a 1/3 voltage divider...so 15
; volts at the input side of resistor RG yields 5 volts
; on the A/D input at pin2. This will place the number 1023 (10 bits)
; in the variable AD. Applying a little math, we can convert
; 1023 into 15 by dividing it by 68.2. Only problem is that
; the Picaxe doesn't have decimal numbers! We can perform
; the same math by first multiplying both numbers by 10.
; So
' (1023 * 10) / (68.2 * 10) = 10230/682 = 15
V15: ReadADC10 2,AD 'MAX reading = 1023 (10 bits)
AD =AD * 10 'normalize...
V = AD/682 'yields a whole number from 0 to 15
D = AD//682 'calculate the remainder (or in-between number)
D = D * 10/682 'do the same thing with the remainder to get
' the decimal digit
Return ' returning with 0-15 in V and 0-9 in D
;8 VOLT MONITOR
; This subroutine works the same way as the 15 Volt routine. The scaling
; values are changed to convert the range from 15 to 8 volts.
; By changing the voltage divider resistor RH and the scaling factor
; (1278), you could change this routine to any custom MAX voltage.
; Resistor 5V=(50k)/(50k+RG) Scaling factor=(10240)/V full scale
V8: ReadADC10 2,AD 'MAX reading = 1023 = 5 volts
AD = AD * 10 'normalize...
V = AD/1278 'yields a whole number from 0 to 8
D = AD//1278 'calculate the remainder (or in-between number)
D = D * 10/1278 'do the same thing with the remainder to get
' the decimal digit
Return ' returning with 0-18 in V and 0-9 in D