Update Overview authored by Reid Schneyer's avatar Reid Schneyer
......@@ -31,7 +31,7 @@ long lastTime = 0;
long currTime = 0;
long lastReading = 0;
long currReading = 0;
int prevRate = 0;
long deltaTime = 0;
long deltaReading = 0;
......@@ -57,6 +57,7 @@ void setup() {
pinMode(BUTTON_PIN, INPUT);
pinMode(LED_BUILTIN, OUTPUT);
homePosition = analogRead(DATA_PIN);
homePosition += 512;
lastTime = millis();
lastReading = analogRead(DATA_PIN);
}
......@@ -82,6 +83,7 @@ void loop() {
}
else { // Short press occured, grab current position regardless of mode
homePosition = analogRead(DATA_PIN);
homePosition += 512;
}
buttonActive = false;
}
......@@ -95,27 +97,26 @@ void loop() {
double relativeDegrees = TEN_BIT_SCALAR * (double) homePosition;
double displayPosition = absoluteDegrees - relativeDegrees;
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);
Serial.println((displayPosition-180));
delay(100);
}
else { // We're in rate mode
deltaTime = currTime - lastTime;
deltaReading = currReading - lastReading;
rate = 1000 * ((TEN_BIT_SCALAR * deltaReading) / (deltaTime));
Serial.println(rate);
delay(100);
// Thanks josh for the fix
if(abs(rate - prevRate) > 360) {
}else{
Serial.println((rate * -1.0));
delay(50);
}
prevRate = rate;
}
// Reset vars for next cycle
lastTime = currTime;
lastReading = currReading;
}
```
\ No newline at end of file