Update Overview authored by Reid Schneyer's avatar Reid Schneyer
...@@ -18,6 +18,9 @@ See here: https://git.ece.iastate.edu/danc/MicroCART/-/wikis/Test-Stand/Electron ...@@ -18,6 +18,9 @@ See here: https://git.ece.iastate.edu/danc/MicroCART/-/wikis/Test-Stand/Electron
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;
const boolean NO_HANDSHAKE = false;
const int SEND_CODE = 65;
int incomingByte = 0;
int val = 0; int val = 0;
const double TEN_BIT_SCALAR = 0.3516; // 360/1024 const double TEN_BIT_SCALAR = 0.3516; // 360/1024
...@@ -41,6 +44,13 @@ boolean buttonActive = false; ...@@ -41,6 +44,13 @@ boolean buttonActive = false;
boolean longPressActive = false; boolean longPressActive = false;
boolean isInPositionMode = true; boolean isInPositionMode = true;
void serialFlush() {
while (Serial.available() > 0) {
char t = Serial.read();
}
}
void setup() { void setup() {
// put your setup code here, to run once: // put your setup code here, to run once:
Serial.begin(9600); Serial.begin(9600);
...@@ -85,18 +95,28 @@ void loop() { ...@@ -85,18 +95,28 @@ void loop() {
double relativeDegrees = TEN_BIT_SCALAR * (double) homePosition; double relativeDegrees = TEN_BIT_SCALAR * (double) homePosition;
double displayPosition = absoluteDegrees - relativeDegrees; double displayPosition = absoluteDegrees - relativeDegrees;
displayPosition += (displayPosition < 0) ? (360) : (0); displayPosition += (displayPosition < 0) ? (360) : (0);
if (NO_HANDSHAKE) {
Serial.println(displayPosition);
}
else if (Serial.available() > 0 && Serial.read() == SEND_CODE) {
Serial.println("DEBUG");
Serial.println(displayPosition); Serial.println(displayPosition);
} }
}
else { // We're in rate mode else { // We're in rate mode
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));
Serial.println(rate); Serial.println(rate);
} delay(100);
}
// Reset vars for next cycle // Reset vars for next cycle
lastTime = currTime; lastTime = currTime;
lastReading = currReading; lastReading = currReading;
} }
``` ```
\ No newline at end of file