Replaced BLE if statment to a switch statment.

This commit is contained in:
2018-11-05 20:13:50 +00:00
parent 75fe7048fe
commit 19bbe242c3
2 changed files with 32 additions and 22 deletions

View File

@@ -4,12 +4,12 @@ BOARD_TAG = pro
BOARD_SUB = 8MHzatmega328 BOARD_SUB = 8MHzatmega328
USER_LIB_PATH += /home/ricardo/Arduino/libraries USER_LIB_PATH += /home/ricardo/Arduino/libraries
ARDUINO_LIBS += LiquidCrystal \ ARDUINO_LIBS += LiquidCrystal \
SPI \ SPI \
SD \ SD \
SoftwareSerial SoftwareSerial
ARDUINO_DIR = /home/ricardo/arduino-1.8.5 # ARDUINO_DIR = /home/ricardo/arduino-1.8.5
# ARDUINO_DIR = /home/ricardo/Installs/arduino-1.8.7 ARDUINO_DIR = /home/ricardo/Installs/arduino-1.8.7
MONITOR_PORT = /dev/ttyUSB0 MONITOR_PORT = /dev/ttyUSB0
-include /usr/share/arduino/Arduino.mk -include /usr/share/arduino/Arduino.mk
-include /home/ricardo/Installs/Arduino-Makefile-1.6.0/Arduino.mk -include /home/ricardo/Installs/Arduino-Makefile-1.6.0/Arduino.mk

View File

@@ -27,6 +27,7 @@ Tue Jun 12 14:56:12 GMT 2018
#define ACT 19 // Button 3 will be function Action #define ACT 19 // Button 3 will be function Action
#define BLUE_RX 8 // Arduino rx serial line to bluetooth #define BLUE_RX 8 // Arduino rx serial line to bluetooth
#define BLUE_TX 9 // Arduino tx serial line to bluetooth #define BLUE_TX 9 // Arduino tx serial line to bluetooth
const int chipSelect = 10; // Chip Select pin for controlling SD card
LiquidCrystal lcd(7, 6, 2, 3, 4, 5); // LCD screen pins, LiquidCrystal(rs, enable, d4, d5, d6, d7) LiquidCrystal lcd(7, 6, 2, 3, 4, 5); // LCD screen pins, LiquidCrystal(rs, enable, d4, d5, d6, d7)
//----------------------------------------------------------------------------------------------------- //-----------------------------------------------------------------------------------------------------
@@ -75,8 +76,8 @@ String screens[numOfScreens][2] = {{"Voltage 1","Volts"}, {"Voltage 2","Volts"},
String parameters_sd[2] = {"No","Yes"}; // String to display the sd card logging String parameters_sd[2] = {"No","Yes"}; // String to display the sd card logging
String parameters_load[2] = {"Off","On"}; // String to display the load state String parameters_load[2] = {"Off","On"}; // String to display the load state
String sd_card[4] = {"Card missing","Card inserted","File Write fail","Writing..."}; // String to display the sd card state String sd_card[4] = {"Card missing","Card inserted","File Write fail","Writing..."}; // String to display the sd card state
String file_name = "measures"; // Initial file name only 8 characters allowed String file_name = "measures"; // Initial file name only 8 characters allowed
float parameters[4]; // Parameters of the several voltages and current float parameters[4]; // Parameters of the several voltages and current
float denominator; // Denominator to calculate the voltage divider float denominator; // Denominator to calculate the voltage divider
int resistor1 = 22000; // Resistor one of voltage divider int resistor1 = 22000; // Resistor one of voltage divider
@@ -125,7 +126,7 @@ void setup()
interrupts(); // enable all interrupts interrupts(); // enable all interrupts
// ---------------------------------------------------------- // ----------------------------------------------------------
if (SD.begin()) // Initiate SD card if (SD.begin(chipSelect)) // Initiate SD card
{ {
sd_status = sd_in; // If sd card is initiated successfully change variable sd_in sd_status = sd_in; // If sd card is initiated successfully change variable sd_in
sd_inserted = yes; // and change variable sd_inserted to yes sd_inserted = yes; // and change variable sd_inserted to yes
@@ -147,30 +148,41 @@ ISR(TIMER1_COMPA_vect)
} }
digitalWrite(load_line, load_status); // Turn load on or off depending on the load_status digitalWrite(load_line, load_status); // Turn load on or off depending on the load_status
if (mySerial.available()) { if (mySerial.available()) {
ble_data = mySerial.read(); ble_data = mySerial.read();
Serial.write(mySerial.read()); // Serial.write(mySerial.read()); // For debug only
if (ble_data == 'A') { switch(ble_data)
{
case 'a':
dtostrf(parameters[battery_volt], 5, 2, outstr); dtostrf(parameters[battery_volt], 5, 2, outstr);
mySerial.write(outstr); mySerial.write(outstr);
} break;
if (ble_data == 'B') {
case 'b':
dtostrf(parameters[voltage_1], 5, 2, outstr); dtostrf(parameters[voltage_1], 5, 2, outstr);
mySerial.write(outstr); mySerial.write(outstr);
} break;
if (ble_data == 'C') {
case 'c':
dtostrf(parameters[voltage_2], 5, 2, outstr); dtostrf(parameters[voltage_2], 5, 2, outstr);
mySerial.write(outstr); mySerial.write(outstr);
} break;
if (ble_data == 'D') {
case 'd':
dtostrf(parameters[curr], 5, 2, outstr); dtostrf(parameters[curr], 5, 2, outstr);
mySerial.write(outstr); mySerial.write(outstr);
} break;
if (ble_data == 'E') {
case 'e':
load_status = on; load_status = on;
} break;
if (ble_data == 'F') {
case 'f':
load_status = off; load_status = off;
break;
} }
} }
} }
@@ -187,8 +199,6 @@ void loop()
Serial.write(ble_data); // For debug only
if (sd_inserted == no) // If SD card is not inserted if (sd_inserted == no) // If SD card is not inserted
{ {
sd_status = sd_not_in; // change card status to sd card not inserted sd_status = sd_not_in; // change card status to sd card not inserted