optional low pass filter for analog values

master
Sascha Nitsch 2022-07-22 12:22:16 +02:00
parent 9793d4e57b
commit 3a234b1969
2 changed files with 6 additions and 1 deletions

View File

@ -11,7 +11,6 @@
// library includes // library includes
#include <Adafruit_MCP23X17.h> #include <Adafruit_MCP23X17.h>
// own includes // own includes
#include "cimdithal.h" #include "cimdithal.h"
@ -109,6 +108,9 @@ void CimditHAL::readFromHardware(bool interrupt) {
int16_t lastAnalogValue = m_currentAnalogValues[m_analogNum]; int16_t lastAnalogValue = m_currentAnalogValues[m_analogNum];
// scan analog value // scan analog value
m_currentAnalogValues[m_analogNum] = analogRead(ANALOG_IN); 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 // set changed bits
if (lastAnalogValue != m_currentAnalogValues[m_analogNum]) { if (lastAnalogValue != m_currentAnalogValues[m_analogNum]) {
//if (abs(lastAnalogValue - m_currentAnalogValues[m_analogNum]) > 1) { //if (abs(lastAnalogValue - m_currentAnalogValues[m_analogNum]) > 1) {

View File

@ -36,6 +36,9 @@
/// dead zone (noise) around the center of the joystick Y axcs /// dead zone (noise) around the center of the joystick Y axcs
#define JOYSTICK_DEAD_ZONE_Y 20 #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 /// i2c address of the external EEPROM
#define EXTERNAL_EEPROM 0x50 #define EXTERNAL_EEPROM 0x50