Created
June 21, 2024 05:17
-
-
Save winhtut/dba225713c706b91dcfa860cfa534e53 to your computer and use it in GitHub Desktop.
volt
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
int adc_max = 0; // Variable to store the maximum sensor value | |
int adc_min = 1023; // Variable to store the minimum sensor value | |
long tiempo_init; // Variable to store the initial time | |
void setup() { | |
Serial.begin(115200); // Initialize the serial communication | |
tiempo_init = millis(); // Get the current time in milliseconds | |
} | |
void loop() { | |
if ((millis() - tiempo_init) > 500) { // Check if 500 milliseconds have passed | |
adc_max = 0; // Reset the maximum sensor value | |
adc_min = 1023; // Reset the minimum sensor value | |
tiempo_init = millis(); // Update the initial time | |
} | |
int sensorValue = analogRead(A0); // Read the analog input from pin A0 | |
if (sensorValue > adc_max) { | |
adc_max = sensorValue; // Update the maximum value if a new maximum is found | |
} else if (sensorValue < adc_min) { | |
adc_min = sensorValue; // Update the minimum value if a new minimum is found | |
} | |
// Print the maximum and minimum values to the serial monitor | |
Serial.print("adc_max: "); | |
Serial.print(adc_max); | |
Serial.print(" adc_min: "); | |
Serial.println(adc_min); | |
delay(1); // Small delay for stability between each iteration | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment