| @@ -10,18 +10,23 @@ | |||
| #define MIN_SPEED 900 | |||
| #define MAX_SPEED 1700 | |||
| #define ZERO_SPEED 900 | |||
| #define POT_MIN 183 | |||
| #define POT_MAX 717 | |||
| #define POT_MIN 220 | |||
| #define POT_MAX 1023 | |||
| #define STEP 10 | |||
| #define DISPLAY_I2C 0x3C | |||
| #define DISPLAY_CHARS 11 | |||
| #define BAT_MAX 4.2 | |||
| #define BAT_MIN 3.6 | |||
| #define BAT_CELLS 6 | |||
| #define BAT_MULT 5 | |||
| #define THERM_RESISTOR 10000 | |||
| #define STATS_TIMER 3 | |||
| #define THRESHOLD 5 | |||
| #define DELAY 50 | |||
| //#define USE_DISPLAY | |||
| #define USE_DISPLAY | |||
| Servo esc; | |||
| #ifdef USE_DISPLAY | |||
| @@ -38,7 +43,8 @@ void setup() { | |||
| display.setFont(Adafruit5x7); | |||
| display.clear(); | |||
| display.set2X(); | |||
| display.print("Hello"); | |||
| display.println("SuperSkuter"); | |||
| display.println("3000"); | |||
| #endif | |||
| pinMode(PIN_POT, INPUT); | |||
| @@ -66,8 +72,18 @@ float measureTemp() { | |||
| int measureBat() { | |||
| int val = analogRead(PIN_BAT); | |||
| float volt = val * (5.0 / 1023.0); | |||
| Serial.println(volt); | |||
| return 50; | |||
| float currV = volt * BAT_MULT; | |||
| float minV = BAT_MIN * BAT_CELLS; | |||
| float maxV = BAT_MAX * BAT_CELLS; | |||
| if (currV < minV) | |||
| currV = minV; | |||
| if (currV > maxV) | |||
| currV = maxV; | |||
| currV -= minV; | |||
| maxV -= minV; | |||
| return (currV / maxV) * 100; | |||
| } | |||
| void printTwo(String s1, String s2) { | |||
| @@ -80,7 +96,13 @@ void printTwo(String s1, String s2) { | |||
| #endif | |||
| } | |||
| int statsCount = 1; | |||
| void showStats(int actualSpeed, int potmeterVal) { | |||
| statsCount -= 1; | |||
| if (statsCount != 0) | |||
| return; | |||
| statsCount = STATS_TIMER + 1; | |||
| int throttle = ((double)(actualSpeed - MIN_SPEED) / (double)(MAX_SPEED - MIN_SPEED)) * 100; | |||
| #ifdef USE_DISPLAY | |||