Skip to content

Instantly share code, notes, and snippets.

@ryo1kato
Created March 31, 2017 08:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ryo1kato/e644f316af0301490fb79494189fe394 to your computer and use it in GitHub Desktop.
Save ryo1kato/e644f316af0301490fb79494189fe394 to your computer and use it in GitHub Desktop.
int analogReadPS(uint8_t pin) {
ACSR &= ~ _BV(ACD); // Enablethe analog comparator
bitClear(PRR, PRADC); // power up ADC
ADCSRA |= _BV(ADEN);
unsigned int reading = analogRead(pin);
ADCSRA &= ~_BV(ADEN);
bitSet(PRR, PRADC); // power down ADC
ACSR |= _BV(ACD); //Disable the analog comparator
return reading;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment