diff --git a/cimdithal.cpp b/cimdithal.cpp index ce94d00..c890eeb 100644 --- a/cimdithal.cpp +++ b/cimdithal.cpp @@ -11,7 +11,6 @@ // library includes #include - // own includes #include "cimdithal.h" @@ -109,6 +108,9 @@ void CimditHAL::readFromHardware(bool interrupt) { int16_t lastAnalogValue = m_currentAnalogValues[m_analogNum]; // scan analog value m_currentAnalogValues[m_analogNum] = analogRead(ANALOG_IN); +#ifdef ANALOG_LOW_PASS_FACTOR + m_currentAnalogValues[m_analogNum] = lastAnalogValue - (ANALOG_LOW_PASS_FACTOR * (lastAnalogValue - m_currentAnalogValues[m_analogNum])); +#endif // set changed bits if (lastAnalogValue != m_currentAnalogValues[m_analogNum]) { //if (abs(lastAnalogValue - m_currentAnalogValues[m_analogNum]) > 1) { diff --git a/defines.h b/defines.h index 06bd3b2..267337c 100644 --- a/defines.h +++ b/defines.h @@ -36,6 +36,9 @@ /// dead zone (noise) around the center of the joystick Y axcs #define JOYSTICK_DEAD_ZONE_Y 20 +/// optional analog filtering higher values mean faster changer, but more noise +#define ANALOG_LOW_PASS_FACTOR 0.95 + /// i2c address of the external EEPROM #define EXTERNAL_EEPROM 0x50