#include <LiquidCrystal_I2C.h>
static uint32_t maxBoostDuration; // Maximum time of boost availability
static uint32_t coolDownTime ; // Milliseconds till next boost is possible
#define I2C_ADDR 0x27
#define LCD_COLUMNS 20
#define LCD_LINES 2
LiquidCrystal_I2C lcd(I2C_ADDR, LCD_COLUMNS, LCD_LINES);
void setup() {
Serial.begin(115200);
// Init
lcd.init();
lcd.backlight();
pinMode(12, INPUT);
pinMode(5, INPUT);
// Print something
lcd.setCursor(0, 0);
lcd.print("Boost_Time: ");
lcd.setCursor(0, 1);
lcd.print("Cooldown_time:");
}
void loop()
{
// Convert SoC to range for switch case
int socRange = (100*analogRead(12))/81900;
int test = (100*analogRead(12))/4095;
int tempRange = (int)(analogRead(5)/ 20);
switch(socRange) {
case 5: // 100-80
case 4: // 80-100
maxBoostDuration = 30;
break;
case 3: // 60-80
maxBoostDuration = 15;
break;
case 2: // 40-60
maxBoostDuration = 10;
break;
default: // < 40
maxBoostDuration = 0;
break;
}
/* This set the cooldown time based on Motor temp */
switch(tempRange) {
case 6: // 120-100
case 5: // 100-120
coolDownTime = 30;
break;
case 4: // 80-100
coolDownTime = 15;
break;
default: // < 80
coolDownTime = 10;
break;
}
lcd.setCursor(12, 0);
lcd.print(maxBoostDuration);
lcd.setCursor(14, 1);
lcd.print(coolDownTime);
Serial.println(test);
}