(* Test small reflection sensor GP2S700HCP & TCND5000 for usable distance

The TCND5000 has a usable range to 30 mm or so.
The GP2S700 may be extended to about 15 mm but is hard to adjust than.

*)

hex
\ ADC on and sample & hold time at 8 ADC10 clocks
: SETUP-ADC ( -- )
    12 1B0 **bic                \ ADC10CTL0  Deactivate ADC & clear ENC
    10 1B0 **bis                \ ADC10CTL0  Activate ADC
    A0 04A c!                   \ ADC10AE0   P1.5 & P1.7 are ADC in
    0010 1B0 ! ;                \ ADC10CTL0  T-sample 8 ADC10 clocks,
                                \            ADC on & Vref = VCC & VSS

\ We need to clear the ENC bit before setting a new input channel
: ADC       ( +n -- u )
    F000 and                    \ Mask ADC input channel selector
    02 1B0 **bic                \ ADC10CTL0  Clear ENC
    40 or 1B2 !                 \ ADC10CTL1  Select input, MCLK/3
    03 1B0 **bis                \ ADC10CTL0  Set ENC & ADC10SC
    begin 4 1B0 bit** until     \ ADC10CTL0  ADC10 ready?
    1B4 @ ;                     \ ADC10MEM   Read result

: SENSOR        7000 adc ;      \ Read level at P1.7

: TEST      ( -- )              \ For both sensors
    setup-adc  decimal
    begin
        sensor .
    key? until  hex ;

: DEMO      ( -- )              \ For TCND5000
    setup-adc  decimal
    begin
        sensor dup dm 600 u> if
                1 21 *bis
        else
                1 21 *bic
        then    .
    key? until  hex ;


shield sensor\  freeze

\ End
