const byte PotiSignalPin = A0;
// easy to use helper-function for non-blocking timing
boolean TimePeriodIsOver (unsigned long &startOfPeriod, unsigned long TimePeriod) {
unsigned long currentMillis = millis();
if ( currentMillis - startOfPeriod >= TimePeriod ) {
// more time than TimePeriod has elapsed since last time if-condition was true
startOfPeriod = currentMillis; // a new period starts right here so set new starttime
return true;
}
else return false; // actual TimePeriod is NOT yet over
}
unsigned long myTimer;
int ADC_Value;
void setup() {
Serial.begin(115200); // adjust baudrate in the serial-monitor to 115200 too
Serial.println("Setup-Start");
//pinMode(PotiSignalPin, INPUT); // defining an analoginput-pin is not nescessary
myTimer = millis(); // store actual timestamp of function millis()
}
void loop() {
ADC_Value = analogRead(PotiSignalPin);
// non-blocking timing: compare how much time has passed by
if ( TimePeriodIsOver (myTimer,500) ) { // check if 500 milliseconds have passed by
// if 500 milliseconds HAVE passed by
Serial.print("Value from ADC-input is:");
Serial.println(ADC_Value);
}
}