| #define MIN_SPEED 900 | #define MIN_SPEED 900 | ||||
| #define MAX_SPEED 1700 | #define MAX_SPEED 1700 | ||||
| #define ZERO_SPEED 900 | #define ZERO_SPEED 900 | ||||
| #define POT_MIN 183 | |||||
| #define POT_MAX 717 | |||||
| #define POT_MIN 220 | |||||
| #define POT_MAX 1023 | |||||
| #define STEP 10 | #define STEP 10 | ||||
| #define DISPLAY_I2C 0x3C | #define DISPLAY_I2C 0x3C | ||||
| #define DISPLAY_CHARS 11 | #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 THERM_RESISTOR 10000 | ||||
| #define STATS_TIMER 3 | |||||
| #define THRESHOLD 5 | #define THRESHOLD 5 | ||||
| #define DELAY 50 | #define DELAY 50 | ||||
| //#define USE_DISPLAY | |||||
| #define USE_DISPLAY | |||||
| Servo esc; | Servo esc; | ||||
| #ifdef USE_DISPLAY | #ifdef USE_DISPLAY | ||||
| display.setFont(Adafruit5x7); | display.setFont(Adafruit5x7); | ||||
| display.clear(); | display.clear(); | ||||
| display.set2X(); | display.set2X(); | ||||
| display.print("Hello"); | |||||
| display.println("SuperSkuter"); | |||||
| display.println("3000"); | |||||
| #endif | #endif | ||||
| pinMode(PIN_POT, INPUT); | pinMode(PIN_POT, INPUT); | ||||
| int measureBat() { | int measureBat() { | ||||
| int val = analogRead(PIN_BAT); | int val = analogRead(PIN_BAT); | ||||
| float volt = val * (5.0 / 1023.0); | 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) { | void printTwo(String s1, String s2) { | ||||
| #endif | #endif | ||||
| } | } | ||||
| int statsCount = 1; | |||||
| void showStats(int actualSpeed, int potmeterVal) { | 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; | int throttle = ((double)(actualSpeed - MIN_SPEED) / (double)(MAX_SPEED - MIN_SPEED)) * 100; | ||||
| #ifdef USE_DISPLAY | #ifdef USE_DISPLAY |