Skip to content

Instantly share code, notes, and snippets.

@cho0h5
Created September 18, 2022 07:25
Show Gist options
  • Save cho0h5/4dc7bf90530eff030a2bb5644707645c to your computer and use it in GitHub Desktop.
Save cho0h5/4dc7bf90530eff030a2bb5644707645c to your computer and use it in GitHub Desktop.
void setup() {
Serial.begin(9600);
initADC();
}
void loop() {
Serial.println(readADC());
}
void initADC() {
ADMUX |= (1 << REFS0) | (1 << ADLAR); // ADLAR -> ADCH, ADCL 왼쪽 정렬
}
byte readADC() {
ADCSRA |= (1 << ADSC); // start conversion
while(ADCSRA & (1 << ADIF)); // interrupt flag <- when conversion completed
uint8_t high;
high = ADCH; // read only 1 byte
return high;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment