Basic boilerplate for programming AVR (arduino) in C.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

33 lines
624 B

#pragma once
//
// Utilities for build-in A/D converter
//
#include <stdint.h>
enum ADC_Prescaller {
ADC_PRESC_2 = 1,
ADC_PRESC_4 = 2,
ADC_PRESC_8 = 3,
ADC_PRESC_16 = 4,
ADC_PRESC_32 = 5,
ADC_PRESC_64 = 6,
ADC_PRESC_128 = 7,
};
/** Initialize the ADC and enable it */
void adc_init(enum ADC_Prescaller presc);
/** Disable ADC (for power saving) */
void adc_disable(void);
/** Enable (already initialized) ADC */
void adc_enable(void);
/** Sample analog pin with 8-bit precision */
uint8_t adc_read_byte(uint8_t channel);
/** Sample analog pin with 10-bit precision */
uint16_t adc_read_word(uint8_t channel);