Working on firmware, completly changed code and kept the old one inside ./firmware.
This commit is contained in:
@@ -1,21 +1,29 @@
|
||||
// include the library code:
|
||||
#include <LiquidCrystal.h>
|
||||
#define delay_1 800
|
||||
|
||||
|
||||
#define b_nav 16
|
||||
#define b_ok 18
|
||||
#define b_back 19
|
||||
#define l_charge 17
|
||||
#define a_charge A6
|
||||
#define a_batt A7
|
||||
|
||||
// initialize the library with the numbers of the interface pins
|
||||
LiquidCrystal lcd(7, 6, 2, 3, 4, 5);
|
||||
|
||||
|
||||
//Analog volt read pin
|
||||
//const int voltPin = A7;
|
||||
|
||||
|
||||
//Input & Button Logic
|
||||
const int numOfInputs = 4;
|
||||
const int inputPins[numOfInputs] = {16,18,19,11};
|
||||
int inputState[numOfInputs];
|
||||
int lastInputState[numOfInputs] = {LOW,LOW,LOW,LOW};
|
||||
bool inputFlags[numOfInputs] = {LOW,LOW,LOW,LOW};
|
||||
long lastDebounceTime[numOfInputs] = {0,0,0,0};
|
||||
long debounceDelay = 5;
|
||||
int v_batt = 7; // Voltage line from the battery
|
||||
int volt_1 = 0;
|
||||
int volt_2 = 1;
|
||||
|
||||
// Function declarations -----------------------------------------------------------------
|
||||
void setInputFlags (void);
|
||||
void resolveInputFlags (void);
|
||||
void printScreen (void);
|
||||
void parameterChange (int key);
|
||||
void inputAction (int input);
|
||||
float volt_pin (int pin); // Read and display voltage
|
||||
//-----------------------------------------------------------------------------------------
|
||||
|
||||
// Variables for voltage divider
|
||||
float denominator;
|
||||
@@ -23,97 +31,113 @@ int resistor1 = 22000; // Values measured in circuit
|
||||
int resistor2 = 2200; // for better accuracy
|
||||
// ----------------------------------------------------
|
||||
|
||||
|
||||
// Function declarations -----------------------------------------------------------------
|
||||
void volt_batt (void); // Read and display voltage
|
||||
//-----------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
//LCD Menu Logic
|
||||
const int numOfScreens = 5;
|
||||
int currentScreen = 0;
|
||||
String screens[numOfScreens][2] = {{"Voltage 1","Volts"}, {"Voltage 2","Volts"},
|
||||
{"Load current","Amps"},{"Batt Voltage","volts"}, {"SD Logging", ""}};
|
||||
float parameters[numOfScreens];
|
||||
String parameters_sd[2] = {"No","Yes"};
|
||||
|
||||
void setup() {
|
||||
|
||||
pinMode(b_nav, INPUT);
|
||||
pinMode(b_ok, INPUT);
|
||||
pinMode(b_back, INPUT);
|
||||
pinMode(l_charge, OUTPUT);
|
||||
for(int i = 0; i < numOfInputs; i++) {
|
||||
pinMode(inputPins[i], INPUT);
|
||||
// digitalWrite(inputPins[i], HIGH); // pull-up 20k
|
||||
}
|
||||
//Serial.begin(9600);
|
||||
lcd.begin(16, 2);
|
||||
// Print a message to the LCD.
|
||||
lcd.print("PowerTester v01");
|
||||
//Convert resistor values to division value
|
||||
// Equation is previously mentions voltage divider equation
|
||||
// R2 / (R1 + R2)
|
||||
// In this case returns 0.20 or 1/5
|
||||
|
||||
denominator = (float)resistor2 / (resistor1 + resistor2);
|
||||
}
|
||||
|
||||
digitalWrite(l_charge, LOW);
|
||||
|
||||
} // Void Setup Close
|
||||
|
||||
void loop() {
|
||||
|
||||
// lcd.setCursor(0, 1); // bottom left
|
||||
// lcd.print("");
|
||||
|
||||
if (!digitalRead(b_nav)) {
|
||||
volt_batt();
|
||||
setInputFlags();
|
||||
resolveInputFlags();
|
||||
parameters[3] = volt_pin(v_batt);
|
||||
parameters[0] = volt_pin(volt_1);
|
||||
parameters[1] = volt_pin(volt_2);
|
||||
// printScreen();
|
||||
// delay(1000);
|
||||
}
|
||||
|
||||
else if (!digitalRead(b_ok)) {
|
||||
digitalWrite(l_charge, !digitalRead(l_charge));
|
||||
lcd.setCursor(0, 1); // bottom left
|
||||
lcd.print("Charge is toggled");
|
||||
delay(500);
|
||||
void setInputFlags() {
|
||||
for(int i = 0; i < numOfInputs; i++) {
|
||||
int reading = digitalRead(inputPins[i]);
|
||||
if (reading != lastInputState[i]) {
|
||||
lastDebounceTime[i] = millis();
|
||||
}
|
||||
if ((millis() - lastDebounceTime[i]) > debounceDelay) {
|
||||
if (reading != inputState[i]) {
|
||||
inputState[i] = reading;
|
||||
if (inputState[i] == HIGH) {
|
||||
inputFlags[i] = HIGH;
|
||||
}
|
||||
}
|
||||
}
|
||||
lastInputState[i] = reading;
|
||||
}
|
||||
}
|
||||
|
||||
else if (!digitalRead(b_back)) {
|
||||
float voltage_c;
|
||||
float cur_c;
|
||||
//Obtain RAW voltage data
|
||||
voltage_c = analogRead(a_charge);
|
||||
|
||||
//Convert to actual voltage (Calibrated by hand)
|
||||
voltage_c = (voltage_c / 1024) * 3.3;
|
||||
|
||||
cur_c = voltage_c / 0.5;
|
||||
|
||||
//Output to LCD
|
||||
lcd.setCursor(0, 1); // bottom left
|
||||
lcd.print("cur C = ");
|
||||
lcd.setCursor(11,1);
|
||||
lcd.print(cur_c);
|
||||
|
||||
//Delay to make LCD readable
|
||||
delay(500);
|
||||
void resolveInputFlags() {
|
||||
for(int i = 0; i < numOfInputs; i++) {
|
||||
if(inputFlags[i] == HIGH) {
|
||||
inputAction(i);
|
||||
inputFlags[i] = LOW;
|
||||
printScreen();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
else {
|
||||
volt_batt();
|
||||
void inputAction(int input) {
|
||||
if(input == 0) {
|
||||
if (currentScreen == 0) {
|
||||
currentScreen = numOfScreens-1;
|
||||
}else{
|
||||
currentScreen--;
|
||||
}
|
||||
}else if(input == 1) {
|
||||
if (currentScreen == numOfScreens-1) {
|
||||
currentScreen = 0;
|
||||
}else{
|
||||
currentScreen++;
|
||||
}
|
||||
}else if(input == 2) {
|
||||
parameterChange(0);
|
||||
}else if(input == 3) {
|
||||
parameterChange(1);
|
||||
}
|
||||
}
|
||||
|
||||
void parameterChange(int key) {
|
||||
if(key == 0) {
|
||||
parameters[currentScreen]++;
|
||||
}else if(key == 1) {
|
||||
parameters[currentScreen]--;
|
||||
}
|
||||
}
|
||||
|
||||
void printScreen() {
|
||||
lcd.clear();
|
||||
lcd.print(screens[currentScreen][0]);
|
||||
lcd.setCursor(0,1);
|
||||
lcd.print(parameters[currentScreen]);
|
||||
lcd.print(" ");
|
||||
lcd.print(screens[currentScreen][1]);
|
||||
}
|
||||
|
||||
|
||||
} // void loop close
|
||||
|
||||
|
||||
void volt_batt(void) {
|
||||
float volt_pin(int pin) {
|
||||
|
||||
float voltage;
|
||||
//Obtain RAW voltage data
|
||||
voltage = analogRead(a_batt);
|
||||
voltage = analogRead(pin);
|
||||
|
||||
//Convert to actual voltage (Calibrated by hand)
|
||||
//Convert to actual voltage
|
||||
voltage = (voltage / 1024) * 3.3;
|
||||
|
||||
//Convert to voltage before divider
|
||||
// Divide by divider = multiply
|
||||
// Divide by 1/5 = multiply by 5
|
||||
//Convert to voltage after divider
|
||||
voltage = voltage / denominator;
|
||||
|
||||
//Output to LCD
|
||||
lcd.setCursor(0, 1); // bottom left
|
||||
lcd.print("Batt V = ");
|
||||
lcd.setCursor(10,1);
|
||||
lcd.print(voltage);
|
||||
|
||||
//Delay to make LCD readable
|
||||
delay(500);
|
||||
return voltage;
|
||||
}
|
||||
|
119
firmware/v01_orig.ino
Normal file
119
firmware/v01_orig.ino
Normal file
@@ -0,0 +1,119 @@
|
||||
// include the library code:
|
||||
#include <LiquidCrystal.h>
|
||||
#define delay_1 800
|
||||
|
||||
|
||||
#define b_nav 16
|
||||
#define b_ok 18
|
||||
#define b_back 19
|
||||
#define l_charge 17
|
||||
#define a_charge A6
|
||||
#define a_batt A7
|
||||
|
||||
// initialize the library with the numbers of the interface pins
|
||||
LiquidCrystal lcd(7, 6, 2, 3, 4, 5);
|
||||
|
||||
|
||||
//Analog volt read pin
|
||||
//const int voltPin = A7;
|
||||
|
||||
// Variables for voltage divider
|
||||
float denominator;
|
||||
int resistor1 = 22000; // Values measured in circuit
|
||||
int resistor2 = 2200; // for better accuracy
|
||||
// ----------------------------------------------------
|
||||
|
||||
|
||||
// Function declarations -----------------------------------------------------------------
|
||||
void volt_batt (void); // Read and display voltage
|
||||
//-----------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
|
||||
void setup() {
|
||||
|
||||
pinMode(b_nav, INPUT);
|
||||
pinMode(b_ok, INPUT);
|
||||
pinMode(b_back, INPUT);
|
||||
pinMode(l_charge, OUTPUT);
|
||||
lcd.begin(16, 2);
|
||||
// Print a message to the LCD.
|
||||
lcd.print("PowerTester v01");
|
||||
//Convert resistor values to division value
|
||||
// Equation is previously mentions voltage divider equation
|
||||
// R2 / (R1 + R2)
|
||||
// In this case returns 0.20 or 1/5
|
||||
denominator = (float)resistor2 / (resistor1 + resistor2);
|
||||
|
||||
digitalWrite(l_charge, LOW);
|
||||
|
||||
} // Void Setup Close
|
||||
|
||||
void loop() {
|
||||
|
||||
// lcd.setCursor(0, 1); // bottom left
|
||||
// lcd.print("");
|
||||
|
||||
if (!digitalRead(b_nav)) {
|
||||
volt_batt();
|
||||
}
|
||||
|
||||
else if (!digitalRead(b_ok)) {
|
||||
digitalWrite(l_charge, !digitalRead(l_charge));
|
||||
lcd.setCursor(0, 1); // bottom left
|
||||
lcd.print("Charge is toggled");
|
||||
delay(500);
|
||||
}
|
||||
|
||||
else if (!digitalRead(b_back)) {
|
||||
float voltage_c;
|
||||
float cur_c;
|
||||
//Obtain RAW voltage data
|
||||
voltage_c = analogRead(a_charge);
|
||||
|
||||
//Convert to actual voltage (Calibrated by hand)
|
||||
voltage_c = (voltage_c / 1024) * 3.3;
|
||||
|
||||
cur_c = voltage_c / 0.5;
|
||||
|
||||
//Output to LCD
|
||||
lcd.setCursor(0, 1); // bottom left
|
||||
lcd.print("cur C = ");
|
||||
lcd.setCursor(11,1);
|
||||
lcd.print(cur_c);
|
||||
|
||||
//Delay to make LCD readable
|
||||
delay(500);
|
||||
}
|
||||
|
||||
else {
|
||||
volt_batt();
|
||||
}
|
||||
|
||||
|
||||
} // void loop close
|
||||
|
||||
|
||||
void volt_batt(void) {
|
||||
|
||||
float voltage;
|
||||
//Obtain RAW voltage data
|
||||
voltage = analogRead(a_batt);
|
||||
|
||||
//Convert to actual voltage (Calibrated by hand)
|
||||
voltage = (voltage / 1024) * 3.3;
|
||||
|
||||
//Convert to voltage before divider
|
||||
// Divide by divider = multiply
|
||||
// Divide by 1/5 = multiply by 5
|
||||
voltage = voltage / denominator;
|
||||
|
||||
//Output to LCD
|
||||
lcd.setCursor(0, 1); // bottom left
|
||||
lcd.print("Batt V = ");
|
||||
lcd.setCursor(10,1);
|
||||
lcd.print(voltage);
|
||||
|
||||
//Delay to make LCD readable
|
||||
delay(500);
|
||||
}
|
Reference in New Issue
Block a user