Untitled
unknown
plain_text
a year ago
1.5 kB
7
Indexable
#include <Servo.h> //Q = question, C= tell me if i understood the concept yes or no ? Servo servo1; float N= 1000; float max_sense; float min_sense; float delta; float delta_ave = 0.5*delta/sqrt(N); float time = micros(); // returns the value of 1ms float noise_lvl; void setup() { // put your setup code here, to run once: Serial.begin(115200); //Q: why not at 9600; } void loop() { int N, i; //UNDERSTOOD float min,max,ave,sum,delta; //UNDERSTOOD int analog_input0; //UNDERSTOOD int voltage; //UNDERSTOOD min = 1.0e6; //Q: why this value specifically and why bad value max = -1.0e6;//Q:idem sum = 0.0; //UNDERSTOOD for(i=1;i<=N;i++){ //C:we need a loop here because we need to repeatedly measure the noise level of sensor until we arrive to the 1000th measurement analog_input0 = analogRead(A0); voltage0 = analog_input0/1023.0*5; sum += voltage0; //UNDERSTOOD if(voltage0 > max) max = voltage0; //C:we need this part to make sure the voltage stays between the max and min, if not, the voltage is the max or min if(voltage0 > max) max = voltage0; //idem delay(1); //UNDERSTOOD } ave = sum/N //UNDERSTOOD delta = max = min; //UNDERSTOOD Serial.print("\nave_voltage ="); Serial.print(ave,5); // Q: why do we need to bring the answer to 5 decimal places Serial.print("\nestimate of noise level ="); Serial.print(delta/2.5) // Q: idem delay(1000); //UNDERSTOOD exit(0); //UNDERSTOOD }
Editor is loading...
Leave a Comment