optional low pass filter for analog values
This commit is contained in:
parent
9793d4e57b
commit
3a234b1969
2 changed files with 6 additions and 1 deletions
|
@ -11,7 +11,6 @@
|
|||
|
||||
// library includes
|
||||
#include <Adafruit_MCP23X17.h>
|
||||
|
||||
// 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) {
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
Loading…
Reference in a new issue