Update Overview authored by Reid Schneyer's avatar Reid Schneyer
......@@ -15,6 +15,8 @@ See here: https://git.ece.iastate.edu/danc/MicroCART/-/wikis/Test-Stand/Electron
# The Firmware
``` cpp
#include <movingAvg.h>
const int DATA_PIN = A7;
const int BUTTON_PIN = 2;
int buttonState = 0;
......@@ -43,7 +45,7 @@ const long LONG_PRESS_MILLIS = 250;
boolean buttonActive = false;
boolean longPressActive = false;
boolean isInPositionMode = true;
movingAvg mySensor(10);
void serialFlush() {
while (Serial.available() > 0) {
......@@ -60,6 +62,8 @@ void setup() {
homePosition += 512;
lastTime = millis();
lastReading = analogRead(DATA_PIN);
mySensor.begin();
}
void loop() {
......@@ -105,11 +109,13 @@ void loop() {
deltaTime = currTime - lastTime;
deltaReading = currReading - lastReading;
rate = 1000 * ((TEN_BIT_SCALAR * deltaReading) / (deltaTime));
// Thanks josh for the fix
if(abs(rate - prevRate) > 360) {
}else{
Serial.println((rate * -1.0));
mySensor.reading(rate);
Serial.println(mySensor.getAvg()*-1);
delay(50);
}
prevRate = rate;
......
......