This example demonstrates how to configure a P2 I/O pin to sample and capture an analog input, and display the raw values using DEBUG.
The PINSTART method is used to configure the I/O pin, in this case for the ADC mode, which is described in the Propeller 2 Spin2 Documentation:
The arguments used in the method are:
The pipe symbol (|) is a logical OR operator and merges the low-level 1x magnification ADC pin configuration with the ADC smart pin mode. The 13 selects 14-bit sampling. The 0 is only a filler for the unused Yval parameter.
RDPIN command obtains the ADC sample value and puts it into the variable
which is output to a DEBUG display with a 100 ms delay between values:
The values are raw numbers which are proportional to the voltage. To display millivolts you need to record the I/O pin’s values using the ADC’s internal switches to GND and VIO to calculate a scale factor and offset.