/** * \brief Read the value an analog channel * * A normal conversion takes 13 ADC clock cycles. With a clock frequency * of for example 200 kHz a conversion therefore needs 65 microseconds. * This time increases with a lower frequency. * * Available on all ATmegas. */ static inline uint16_t readChannel(uint8_t channel) { if (!startConversion(channel)) return 0; while (!isInterruptFlagSet()) { // wait until the conversion is finished } return getDataRegister(); }
///@description Perform a complete conversion. Should only be used when waiting isn't a problem. uint16_t ANALOG::read(){ //start conversion start(); //wait for conversion to finish (interrupt flag is set) while( isReading() && !isInterruptFlagSet()); clearFlag(); return (ADC); }
/** * \brief Check if the conversion is finished * * Available on all ATmegas. */ static inline bool isFinished() { return isInterruptFlagSet(); }