Last active
September 2, 2019 17:15
-
-
Save aallan/d0f957da94bccdbf120473ed4a190059 to your computer and use it in GitHub Desktop.
Testing the analogRead() function on the SAMD21 micro-controller
This file contains 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
#define Debug Serial | |
float average = 0.0; | |
float total = 0.0; | |
int count = 0; | |
void setup() { | |
analogReadResolution(12); | |
pinMode(A0, INPUT); | |
Debug.begin(9600); | |
while (!Debug); | |
} | |
void loop() { | |
int a = analogRead(A0); | |
float v = 3.3*((float)a)/4095; | |
count = count + 1; | |
total = total + v; | |
average = total/count; | |
Debug.print(count); | |
Debug.print(" "); | |
Debug.print(a); | |
Debug.print(" "); | |
Debug.print(v,3); | |
Debug.print(" "); | |
Debug.print(average,3); | |
Debug.println( ); | |
delay(1000); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment