Created
September 18, 2022 07:25
-
-
Save cho0h5/4dc7bf90530eff030a2bb5644707645c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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