aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFranklin Wei <franklin@rockbox.org>2019-11-03 00:36:24 -0400
committerFranklin Wei <franklin@rockbox.org>2019-11-03 00:36:24 -0400
commitc265e81aa18d33a2d2a9427733b93d07d1a8b3c2 (patch)
tree8957f75e953015b90ea312a4a218100748a07f49
downloadregentester-c265e81aa18d33a2d2a9427733b93d07d1a8b3c2.zip
regentester-c265e81aa18d33a2d2a9427733b93d07d1a8b3c2.tar.gz
regentester-c265e81aa18d33a2d2a9427733b93d07d1a8b3c2.tar.bz2
regentester-c265e81aa18d33a2d2a9427733b93d07d1a8b3c2.tar.xz
Initial commit
-rw-r--r--main.ino60
1 files changed, 60 insertions, 0 deletions
diff --git a/main.ino b/main.ino
new file mode 100644
index 0000000..f9cde91
--- /dev/null
+++ b/main.ino
@@ -0,0 +1,60 @@
+// Regen circuit driver
+
+void setup() {
+ // put your setup code here, to run once:
+ Serial.begin(9600);
+
+ pinMode(2, OUTPUT);
+ digitalWrite(2, LOW);
+ pinMode(3, OUTPUT);
+ digitalWrite(3, LOW);
+
+ Serial.println("I_in I_out");
+}
+
+#define ACCEL 0
+#define COAST1 1
+#define BRAKE 2
+#define COAST2 3
+#define LAST_STATE 4
+
+int state = LAST_STATE - 1; // begin with acceleration
+int state_times[] = { 4000, 100, 2000, 500 };
+unsigned long next_state_time = 0;
+
+const int CURRENT_OUT_SENSOR = A0;
+const double mVPerAmp = 66;
+const int OFFSET=2500;
+
+void loop() {
+ unsigned long time = millis();
+
+ int raw = analogRead(CURRENT_OUT_SENSOR);
+ float mV = raw * 5000.0 / 1024.0;
+ float current = (mV - OFFSET) / mVPerAmp;
+ Serial.println(current, 3);
+
+ if(time > next_state_time)
+ {
+ // advance state
+ state++;
+ state %= LAST_STATE;
+ switch(state) {
+ case ACCEL:
+ digitalWrite(2, HIGH);
+ break;
+ case COAST1:
+ digitalWrite(2, LOW);
+ break;
+ case BRAKE:
+ digitalWrite(3, HIGH);
+ break;
+ case COAST2:
+ digitalWrite(3, LOW);
+ break;
+ }
+ //Serial.println("State advance");
+
+ next_state_time = time + state_times[state];
+ }
+}