Skip to content

Commit

Permalink
Fix faulty initialization of analog value at startup (additional fix …
Browse files Browse the repository at this point in the history
…for #199) (#212)
  • Loading branch information
GioCC authored Oct 13, 2022
1 parent 1fcea01 commit dbf212b
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/MF_Analog/MFAnalog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,13 @@ MFAnalog::MFAnalog(uint8_t pin, const char *name, uint8_t sensitivity)
_sensitivity = sensitivity;
_pin = pin;
_name = name;
_lastValue = 0;
pinMode(_pin, INPUT_PULLUP); // set pin to input. Could use OUTPUT for analog, but shows the intention :-)
// Fill averaging buffers with initial reading
for (uint8_t i = 0; i < ADC_MAX_AVERAGE; i++) {
readBuffer();
}
// and set initial value from buffers
_lastValue = ADC_Average_Total >> ADC_MAX_AVERAGE_LOG2;
}

bool MFAnalog::valueHasChanged(int16_t newValue)
Expand Down

0 comments on commit dbf212b

Please sign in to comment.