Here is the basic stamp code for the system so far. It does not include calibration code but should get you started. You can type it in or take the easy way out. Cut it into a notepad document and save it as
LEDHUD1.bas
============================
'LED Heads Up Display code for Basic Stamp
'By Tom Rose www.atlimp.com
'Warning Diving is a Dangerous activity
'USE OF this code in life support equipment could be fatal
'Liability limited to cost of the code which is given without cost
'Code may not be distributed without this header and warnings
'===========================
SYMBOL CS = 0 ' Chip select; 0 = active.
SYMBOL CLK = 1 ' Clock to ADC; out on rising, in on falling edge.
SYMBOL DIO_n = 2 ' Pin _number_ of data input/output.
SYMBOL DIO_p = pin2 ' Variable_name_ of data input/output.
SYMBOL ADbits = b1 ' Counter variable for serial bit reception.
SYMBOL AD = w1 ' 12-bit ADC conversion result.
SYMBOL LOOP =W2
SYMBOL sglDif = 1 ' Single-ended, two-channel mode.
SYMBOL msbf = 1 ' Output 0s after data transfer is complete.
SYMBOL oddSign = bit0 ' Program writes channel # to this bit.
high CS ' Deactivate the ADC to begin.
Again: ' Main loop.
gosub Convert ' Get data from ADC.
debug "ch ",#oddSign,":",#AD,cr ' Show the data on PC screen.
IF AD <180 THEN ANOXIA 'Flashes Red Led Slowly
IF AD <690 THEN SUCKING 'Flashes Green Led Slowly
IF AD <1050 THEN CRUISING 'Flashes Green Led Steady with short off
IF AD <1390 THEN RICHMIX 'Flashes Green Led Fast
GOTO QUIVERING 'Flashes Red Led Fast
pause 500 ' Wait a half second.
goto Again ' Endless loop.
Convert:
low CLK ' Low clock--output on rising edge.
high DIO_n ' Switch DIO to output high (start bit).
low CS ' Activate the 1298.
pulsout CLK,5 ' Send start bit.
let DIO_p = sglDif ' First setup bit.
pulsout CLK,5 ' Send bit.
let DIO_p = oddSign ' Second setup bit.
pulsout CLK,5 ' Send bit.
let DIO_p = msbf ' Final setup bit.
pulsout CLK,5 ' Send bit.
input DIO_n ' Get ready for input from DIO.
let AD = 0 ' Clear old ADC result.
for ADbits = 1 to 13 ' Get null bit + 12 data bits.
let AD = AD*2+DIO_p ' Shift AD left, add new data bit.
pulsout CLK,5 ' Clock next data bit in.
next ' Get next data bit.
high CS ' Turn off the ADC
return ' Return to program.
ANOXIA:
LOW 7
HIGH 6
PAUSE 1000
LOW 6
PAUSE 1000
GOTO AGAIN
SUCKING:
HIGH 7
PAUSE 1000
LOW 7
PAUSE 1000
GOTO AGAIN
CRUISING:
LOW 6
HIGH 7
PAUSE 1000
LOW 7
PAUSE 100
HIGH 7
GOTO AGAIN
RICHMIX:
LOW 6
HIGH 7
PAUSE 100
LOW 7
PAUSE 100
GOTO AGAIN
QUIVERING:
LOW 7
HIGH 6
PAUSE 200
LOW 6
GOTO AGAIN
'============================
Pretty simple, huh
You can download the basic stamp manual and the programming program free from the following website:
Parallax Basic Stamp Web Site
Happy Stamping
Tom