Skip to content

Instantly share code, notes, and snippets.

@aallan

aallan/analog.ino

Last active Sep 2, 2019
Embed
What would you like to do?
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