Skip to content

Instantly share code, notes, and snippets.

@aallan
Last active September 2, 2019 17:15
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 aallan/d0f957da94bccdbf120473ed4a190059 to your computer and use it in GitHub Desktop.
Save aallan/d0f957da94bccdbf120473ed4a190059 to your computer and use it in GitHub Desktop.
Testing the analogRead() function on the SAMD21 micro-controller
#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