Created
March 30, 2024 14:36
-
-
Save delasign/0082c620887a09d84c25091e297db46c to your computer and use it in GitHub Desktop.
Sample Low Pass Filter Code
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
float alpha = 0.95; // Filter constant, higher value means more filtering | |
float prevValue = 0.0; // Previous filtered value | |
float filteredValue; | |
void setup() { | |
Serial.begin(9600); | |
} | |
void loop() { | |
float rawValue = analogRead(A0); // Read the raw analog input | |
// Apply the low-pass filter | |
filteredValue = rawValue * (1 - alpha) + prevValue * alpha; | |
prevValue = filteredValue; | |
// Print the filtered value | |
Serial.println(filteredValue); | |
delay(10); // Delay to control the sampling rate | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment