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