Koduino
Functions
Analog input

Detailed Description

Usage

  1. Call pinMode() with INPUT_ANALOG
  2. Optionally call analogReadSampleTime()
  3. Call analogRead() to get a new sample (should take ~5us)

Example

#include <Arduino.h>
void setup() {
Serial1.begin(115200);
pinMode(PA5, INPUT_ANALOG);
}
void loop() {
Serial1 << "PA5=" << analogRead(PA5) << "\n";
delay(50);
}

Functions

void analogReadSampleTime (uint8_t sampleTime)
 Set ADC sample time. More...
 
uint16_t analogRead (uint8_t pin)
 Read a single pin. More...
 

Function Documentation

uint16_t analogRead ( uint8_t  pin)

Read a single pin.

Should take ~5us for (see analogReadSampleTime())

Parameters
pinPin name to read
Returns
The 12-bit (0-4096) value of the converted signal, with 0 = 0V, 4096 = 3.3V
void analogReadSampleTime ( uint8_t  sampleTime)

Set ADC sample time.

This should be seen as a type of filtering. The default is 13.5 cycles, which is the minimum for 12-bit accuracy.

Parameters
sampleTimeOne of ADC_SampleTime_1Cycles5, ADC_SampleTime_7Cycles5, ADC_SampleTime_13Cycles5 (default), ADC_SampleTime_28Cycles5, ADC_SampleTime_41Cycles5, ADC_SampleTime_55Cycles5, ADC_SampleTime_71Cycles5, ADC_SampleTime_239Cycles5. (E.g. the default is 13.5 cycles sampling time)