Skip to content

Instantly share code, notes, and snippets.

@urmil0071
Last active August 17, 2017 20:25
Show Gist options
  • Save urmil0071/86a5b0b58a6363362a64bca1c76eef76 to your computer and use it in GitHub Desktop.
Save urmil0071/86a5b0b58a6363362a64bca1c76eef76 to your computer and use it in GitHub Desktop.
Read ADC Value on interrupt basis
#include<Arduino.h>
volatile int analogVal;
void setup()
{
Serial.begin(9600);
ADMUX=0xC0; /// 1.1 V refrrence, Right adjust, channel 0
bitWrite(ADCSRA,7,1); /// ADC Enabled
bitWrite(ADCSRA,5,1); /// Auto Triggering Enabled
ADCSRA |= B00000111; /// Pre Scaler to 1/128
bitWrite(ADCSRA,3,1); ///Enabling ADC Interrupt
sei(); /// Enables Global Interrupt
bitWrite(ADCSRA,6,1); ///Start Convertion
}
void loop()
{
}
ISR(ADC_vect)
{
analogVal = ADCL + (ADCH << 8);
Serial.println(analogVal,DEC);
bitWrite(ADCSRA,6,1); ///Start Convertion
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment