Update LCD_Keypad_Shield_with_PH_Meter.ino

This commit is contained in:
vjclearscreen
2015-09-04 11:40:45 +02:00
parent e1f082c437
commit 044657da9f
+495 -274
View File
@@ -5,38 +5,71 @@
This program will show PH , Room Temperature and Water Temperature on the LCD panel. This program will show PH , Room Temperature and Water Temperature on the LCD panel.
Also support serial communication. Also support serial communication.
Connection: Connection:
1) Plug the LCD Keypad to the UNO 1) Plug the LCD Keypad to the UNO
2) Connect Arduino D2 to PH Meter Board T2 (DS18B20) 2) Connect Arduino D2 to PH Meter Board T2 (DS18B20)
3) Connect Arduino A1 to PH Meter Board T1 (LM35) 3) Connect Arduino A1 to PH Meter Board T1 (LM35)
4) Connect Arduino A2 to PH Meter Board P0 (PH) 4) Connect Arduino A2 to PH Meter Board P0 (PH)
5) Connect Arduino 5V to PH Meter Board Vcc 5) Connect Arduino 5V to PH Meter Board Vcc
6) Connect Arduino GND to PH Meter Board GND 6) Connect Arduino GND to PH Meter Board GND
Require Library : Require Library :
LiquidCrystal : http://arduino.cc/en/Reference/LiquidCrystal LiquidCrystal : http://arduino.cc/en/Reference/LiquidCrystal
OneWire : http://www.pjrc.com/teensy/td_libs_OneWire.html OneWire : http://www.pjrc.com/teensy/td_libs_OneWire.html
DallasTemperature : http://milesburton.com/Dallas_Temperature_Control_Library DallasTemperature : http://milesburton.com/Dallas_Temperature_Control_Library
Serial Communication : Serial Communication :
Send command in HEX format . Send command in HEX format .
AA 01 01 BB , Enquiry DS18B20 temperature AA 01 01 BB , Enquiry DS18B20 temperature
AA 01 02 BB , Enquiry LM35 temperature AA 01 02 BB , Enquiry LM35 temperature
AA 01 03 BB , Enquiry PH reading AA 01 03 BB , Enquiry PH reading
AA 01 04 BB , Enqyiry DS18B20 , LM35 and Ph AA 01 04 BB , Enqyiry DS18B20 , LM35 and Ph
Version : Version :
v0.1 5/3/2015 First Version v0.1 5/3/2015 First Version
**************************************************************************************/ **************************************************************************************/
/* PIN NRF Mysensor on a arduino Mega :
modifier fichier libriaire myconfig.h
/**********************************
* NRF24L01 Driver Defaults
***********************************
#define RF24_CE_PIN 48
#define RF24_CS_PIN 49
#define RF24_PA_LEVEL RF24_PA_MAX
#define RF24_PA_LEVEL_GW RF24_PA_LOW
48 CE orange
49 CSN/CS jaune
52 SCK vert
51 MOSI bleu
50 MISO violet
2 IRQ gris
*/
#include <LiquidCrystal.h> #include <LiquidCrystal.h>
#include <OneWire.h> #include <OneWire.h>
#include <DallasTemperature.h> #include <DallasTemperature.h>
#include <Wire.h>
#include <EEPROM.h>
// librairie pour My Sensor
#include <SPI.h>
#include <MySensor.h>
// configuration my sensor
MySensor gw;
MyMessage msgPH(0, V_VAR1);
MyMessage msgTempROOM(1, V_TEMP);
MyMessage msgTempWATER(2, V_TEMP);
double lastPhValue = 7;
LiquidCrystal lcd(8, 9, 4, 5, 6, 7); // select the pins used on the LCD panel LiquidCrystal lcd(8, 9, 4, 5, 6, 7); // select the pins used on the LCD panel
#define ONE_WIRE_BUS 2 // DS18B20 connect to Pin 2 #define ONE_WIRE_BUS 3 // DS18B20 connect to Pin 2
OneWire oneWire(ONE_WIRE_BUS); OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire); DallasTemperature sensors(&oneWire);
@@ -44,7 +77,7 @@ DallasTemperature sensors(&oneWire);
#define STX 0xAA // define STX for serial communication #define STX 0xAA // define STX for serial communication
#define ETX 0XBB // define ETX for serial communication #define ETX 0XBB // define ETX for serial communication
byte RxCmd [4] = {0,0,0,0}; byte RxCmd [4] = {0, 0, 0, 0};
// define some values used by the panel and buttons // define some values used by the panel and buttons
int lcd_key = -1; int lcd_key = -1;
@@ -59,16 +92,30 @@ int TempReadings[NumReadings]; // array for store LM35 readings
int TempTotal = 0; // LM35 running total int TempTotal = 0; // LM35 running total
int TempAverage = 0; // LM35 average reading int TempAverage = 0; // LM35 average reading
double TempValue = 0; // LM35 Temperature Data in Human Reading Format after calculation double TempValue = 0; // LM35 Temperature Data in Human Reading Format after calculation
float lastTempROOM = 0;
float lastTempWATER = 0;
int PhReadings[NumReadings]; // array for store PH readings int PhReadings[NumReadings]; // array for store PH readings
int PhTotal = 0; // PH running total int PhTotal = 0; // PH running total
int PhAverage = 0; // PH average reading int PhAverage = 0; // PH average reading
double Ph7Buffer = 6.86; // For PH7 buffer solution's PH value , 7 or 6.86
// the current address in the EEPROM (i.e. which byte
// we're going to write to next)
int addrph4 = 40;
int addrph7 = 70;
double Ph7Buffer = 7.00; // For PH7 buffer solution's PH value , 7 or 6.86
double Ph4Buffer = 4.01; // For PH4 buffer solution's PH value , 4 or 4.01 double Ph4Buffer = 4.01; // For PH4 buffer solution's PH value , 4 or 4.01
double Ph7Reading = 528; // PH7 Buffer Solution Reading. //double Ph7Reading = 528; // PH7 Buffer Solution Reading.
double Ph4Reading = 655; // PH4 Buffer Solution Reading. //double Ph4Reading = 655; // PH4 Buffer Solution Reading.
//double Ph7Reading = 628; // PH7 Buffer Solution Reading.
//double Ph4Reading = 732;
//double Ph7Reading = EEPROM.read(addrph4); // PH7 Buffer Solution Reading.
//double Ph4Reading = EEPROM.read(addrph7);
double Ph4Reading = EEreadFloat(addrph4);
double Ph7Reading = EEreadFloat(addrph7);
int calibrate = 0;
double PhRatio = 0; // PH Step double PhRatio = 0; // PH Step
double PhValue = 0; // Ph Value in Human Reading Format after calculation double PhValue = 0; // Ph Value in Human Reading Format after calculation
@@ -80,314 +127,488 @@ double PhValue = 0; // Ph Value in Human Reading Form
#define btnSELECT 4 #define btnSELECT 4
#define btnNONE 5 #define btnNONE 5
int read_LCD_buttons(){ // read the buttons int read_LCD_buttons() { // read the buttons
adc_key_in = analogRead(0); // read the value from the sensor adc_key_in = analogRead(0); // read the value from the sensor
delay(10); // switch debounce delay. Increase this delay if incorrect switch selections are returned. delay(10); // switch debounce delay. Increase this delay if incorrect switch selections are returned.
int k = (analogRead(0) - adc_key_in); // gives the button a slight range to allow for a little contact resistance noise int k = (analogRead(0) - adc_key_in); // gives the button a slight range to allow for a little contact resistance noise
if (5 < abs(k)) return btnNONE; // double checks the keypress. If the two readings are not equal +/-k value after debounce delay, it tries again. if (5 < abs(k)) return btnNONE; // double checks the keypress. If the two readings are not equal +/-k value after debounce delay, it tries again.
//lcd.print(adc_key_in); // read button value and print for calibrate //lcd.print(adc_key_in); // read button value and print for calibrate
// my buttons when read are centered at these valies: 0, 144, 329, 504, 741
// we add approx 50 to those values and check to see if we are close
// We make this the 1st option for speed reasons since it will be the most likely result
if (adc_key_in > 1000) return btnNONE; // my buttons when read are centered at these valies: 0, 144, 329, 504, 741
if (adc_key_in < 50) return btnRIGHT; // we add approx 50 to those values and check to see if we are close
if (adc_key_in < 150) return btnUP; // We make this the 1st option for speed reasons since it will be the most likely result
if (adc_key_in < 350) return btnDOWN;
if (adc_key_in < 550) return btnLEFT; if (adc_key_in > 1000) return btnNONE;
if (adc_key_in < 750) return btnSELECT; if (adc_key_in < 50) return btnRIGHT;
return btnNONE; // when all others fail, return this. if (adc_key_in < 150) return btnUP;
if (adc_key_in < 350) return btnDOWN;
if (adc_key_in < 550) return btnLEFT;
if (adc_key_in < 750) return btnSELECT;
return btnNONE; // when all others fail, return this.
} }
int reading(){ // Reading LM35 and PH Data int reading() {
// Samplin LM35 and PH Value double Ph4Reading = EEreadFloat(addrph4);
TempTotal= TempTotal - TempReadings[Index]; // subtract the last reading: double Ph7Reading = EEreadFloat(addrph7);
PhTotal= PhTotal - PhReadings[Index]; // subtract the last reading: // Reading LM35 and PH Data
TempReadings[Index] = analogRead(1); // read from the sensor : LM35 // Samplin LM35 and PH Value
PhReadings[Index] = analogRead(2); // read from the sensor : PH TempTotal = TempTotal - TempReadings[Index]; // subtract the last reading:
TempTotal= TempTotal + TempReadings[Index]; // add the reading to the temperature total: PhTotal = PhTotal - PhReadings[Index]; // subtract the last reading:
PhTotal= PhTotal + PhReadings[Index]; // add the reading to the ph total: TempReadings[Index] = analogRead(1); // read from the sensor : LM35
Index = Index + 1; // advance to the next position in the array: PhReadings[Index] = analogRead(2); // read from the sensor : PH
TempTotal = TempTotal + TempReadings[Index]; // add the reading to the temperature total:
PhTotal = PhTotal + PhReadings[Index]; // add the reading to the ph total:
Index = Index + 1; // advance to the next position in the array:
if (Index >= NumReadings){ // if we're at the end of the array... if (Index >= NumReadings) { // if we're at the end of the array...
Index = 0; // ...wrap around to the beginning: Index = 0; // ...wrap around to the beginning:
TempAverage = TempTotal / NumReadings; // calculate the average: TempAverage = TempTotal / NumReadings; // calculate the average:
PhAverage = PhTotal / NumReadings; // calculate the average: PhAverage = PhTotal / NumReadings; // calculate the average:
} }
TempValue = (double) TempAverage / 3.4 * (5/10.24); // LM35 connect to CA3140 for amplify 3 time TempValue = (double) TempAverage / 3.4 * (5 / 10.24); // LM35 connect to CA3140 for amplify 3 time
PhValue = (Ph7Reading - PhAverage) / PhRatio + Ph7Buffer; // Calculate PH PhValue = (Ph7Reading - PhAverage) / PhRatio + Ph7Buffer; // Calculate PH
if (PhValue > 6.5) {
digitalWrite(53, HIGH); // turn pompe on
}
if (PhValue < 6) {
digitalWrite(53, LOW); // turn pompe off
}
if (PhValue > lastPhValue + 0.3) {
//Serial.println(PhValue);
double PHsend = PhValue;
gw.send(msgPH.set(PHsend, 1)); // Send the inverse to gw as tripped should be when no water in soil
lastPhValue = PhValue;
}
if (PhValue < lastPhValue - 0.3) {
//Serial.println(PhValue);
double PHsend = PhValue;
gw.send(msgPH.set(PHsend, 1)); // Send the inverse to gw as tripped should be when no water in soil
lastPhValue = PhValue;
}
// Only send data if ROOM Temperature has changed and no error
if (lastTempROOM < TempValue - 0.5 && TempValue != -127.00 && TempValue != 85.00) {
if (TempValue != -127.00 && TempValue != 85.00) {
// Send in the new temperature
gw.send(msgTempROOM.set(TempValue, 1));
// Save new temperatures for next compare
lastTempROOM = TempValue;
}
}
// Only send data if ROOM Temperature has changed and no error
if (lastTempROOM > TempValue + 0.5 && TempValue != -127.00 && TempValue != 85.00) {
if (TempValue != -127.00 && TempValue != 85.00) {
// Send in the new temperature
gw.send(msgTempROOM.set(TempValue, 1));
// Save new temperatures for next compare
lastTempROOM = TempValue;
}
}
} }
void setup(){ void setup() {
lcd.begin(16, 2); // start LCD library
// pompe PH down
for (int TempThisReading = 0; TempThisReading < NumReadings; TempThisReading++) // initialize all the LM35 readings to 0: pinMode(53, OUTPUT);
TempReadings[TempThisReading] = 0; // start mysensor
gw.begin();
for (int PhThisReading = 0; PhThisReading < NumReadings; PhThisReading++) // initialize all the Ph readings to 0:
PhReadings[PhThisReading] = 0; // Send the sketch version information to the gateway and Controller
gw.sendSketchInfo("PH Temp Sensor", "1.0");
PhRatio = (Ph4Reading - Ph7Reading) / (Ph7Buffer - Ph4Buffer); // Calculate Ph Ratio delay(200);
// Register all sensors to gw (they will be created as child devices)
Serial.begin(9600); gw.present(0, S_TEMP);
while(Serial.available()) Serial.read(); // empty RX buffer delay(200);
Serial.println("Starting"); gw.present(1, S_TEMP);
delay(200);
gw.present(2, S_TEMP);
delay(200);
lcd.begin(16, 2); // start LCD library
for (int TempThisReading = 0; TempThisReading < NumReadings; TempThisReading++) // initialize all the LM35 readings to 0:
TempReadings[TempThisReading] = 0;
for (int PhThisReading = 0; PhThisReading < NumReadings; PhThisReading++) // initialize all the Ph readings to 0:
PhReadings[PhThisReading] = 0;
PhRatio = (Ph4Reading - Ph7Reading) / (Ph7Buffer - Ph4Buffer); // Calculate Ph Ratio
Serial.begin(115200);
while (Serial.available()) Serial.read(); // empty RX buffer
Serial.println("Starting");
} }
void loop(){ void loop() {
if (Serial.available()) { if (Serial.available()) {
delay(2); delay(2);
RxCmd[0] = Serial.read(); RxCmd[0] = Serial.read();
if (RxCmd[0] == STX) { if (RxCmd[0] == STX) {
int i =1; int i = 1;
while(Serial.available()) { while (Serial.available()) {
delay(1); delay(1);
RxCmd[i] = Serial.read(); RxCmd[i] = Serial.read();
//if (RxCmd[i]>127 || i>7) break; //Communication error //if (RxCmd[i]>127 || i>7) break; //Communication error
if (RxCmd[i]==ETX) { if (RxCmd[i] == ETX) {
break; //Read all data break; //Read all data
} }
i++; i++;
} }
} }
} }
if ( RxCmd[1] == 1 ){ if ( RxCmd[1] == 1 ) {
lcd.setCursor(9,1); lcd.setCursor(9, 1);
switch (RxCmd[2]) { switch (RxCmd[2]) {
case 1:{ case 1: {
//Serial.print("Command 1 Received "); // Enquiry Water Temperature (DS18B20) //Serial.print("Command 1 Received "); // Enquiry Water Temperature (DS18B20)
Serial.println(sensors.getTempCByIndex(0),2); // Return DS18B20 Data Serial.println(sensors.getTempCByIndex(0), 2); // Return DS18B20 Data
break; break;
} }
case 2:{ case 2: {
//Serial.print("Command 2 Received "); // Enquiry Room Temperature (LM35) //Serial.print("Command 2 Received "); // Enquiry Room Temperature (LM35)
Serial.println(TempValue,2); // Return LM35 Data Serial.println(TempValue, 2); // Return LM35 Data
break; break;
} }
case 3:{ case 3: {
//Serial.print("Command 3 Received "); // Enquiry PH Data //Serial.print("Command 3 Received "); // Enquiry PH Data
Serial.println(PhValue,2); // Return PH Data Serial.println(PhValue, 2); // Return PH Data
break; break;
} }
case 4:{ case 4: {
//Serial.println("Command 4 Received "); // Enquiry Water Temp. & Room Temp. & PH //Serial.println("Command 4 Received "); // Enquiry Water Temp. & Room Temp. & PH
Serial.println(sensors.getTempCByIndex(0),2); // Return DS18B20 Data Serial.println(sensors.getTempCByIndex(0), 2); // Return DS18B20 Data
Serial.println(TempValue,2); // Return LM35 Data Serial.println(TempValue, 2); // Return LM35 Data
Serial.println(PhValue,2); // Return PH Data Serial.println(PhValue, 2); // Return PH Data
break; break;
}
} }
} }
}
for (int i = 0 ; i < 5 ; i++) { for (int i = 0 ; i < 5 ; i++) {
RxCmd[i] = 0; RxCmd[i] = 0;
} }
if (CurrentMode == 0) // Nomral Display Mode
{
reading(); // Reading LM35 and PH Data for display
lcd.setCursor(13,0);
lcd.print("PH ");
lcd.setCursor(0,0); // set the LCD cursor position
lcd.print("Room");
lcd.setCursor(0,1);
lcd.print("Water");
lcd.setCursor(6,0);
lcd.print(TempValue); // display room temperature value (LM35)
delay(1); // delay in between reads for stability
// Display 18B20 Temperature
lcd.setCursor(6,1); // move cursor to second line "1" and 6 spaces over
sensors.requestTemperatures(); // Read DS18B20 data
lcd.print(sensors.getTempCByIndex(0)); // Display DS18B20 Data
// Display PH Data if (CurrentMode == 0) // Nomral Display Mode
lcd.setCursor(13,0); {
lcd.print("PH"); reading(); // Reading LM35 and PH Data for display
lcd.setCursor(12,1); lcd.setCursor(13, 0);
lcd.print(PhValue); // display PH value lcd.print("PH ");
delay(1); // delay in between reads for stability lcd.setCursor(0, 0); // set the LCD cursor position
lcd.print("Room");
lcd.setCursor(0, 1);
lcd.print("Water");
lcd.setCursor(6, 0);
lcd.print(TempValue); // display room temperature value (LM35)
delay(1); // delay in between reads for stability
} // Display 18B20 Temperature
lcd.setCursor(6, 1); // move cursor to second line "1" and 6 spaces over
sensors.requestTemperatures(); // Read DS18B20 data
lcd.print(sensors.getTempCByIndex(0)); // Display DS18B20 Data
int TempWATER = sensors.getTempCByIndex(0);
// Only send data if WATER temperature has changed and no error
if (lastTempWATER < TempWATER - 0.5 && TempWATER != -127.00 && TempWATER != 85.00) {
if (TempWATER != -127.00 && TempWATER != 85.00) {
// Send in the new temperature
gw.send(msgTempWATER.set(TempWATER, 1));
// Save new temperatures for next compare
lastTempWATER = TempWATER;
}
}
// Only send data if WATER temperature has changed and no error
if (lastTempWATER > TempWATER + 0.5 && TempWATER != -127.00 && TempWATER != 85.00) {
if (TempWATER != -127.00 && TempWATER != 85.00) {
// Send in the new temperature
gw.send(msgTempWATER.set(TempWATER, 1));
// Save new temperatures for next compare
lastTempWATER = TempWATER;
}
}
if (CurrentMode == 1){ // Display PH Data
reading(); lcd.setCursor(13, 0);
lcd.setCursor(0,0); lcd.print("PH");
lcd.print("LM35 R"); lcd.setCursor(12, 1);
lcd.setCursor(10,0); lcd.print(PhValue); // display PH value
lcd.print("T"); delay(1); // delay in between reads for stability
lcd.setCursor(0,1);
lcd.print("PH R");
lcd.setCursor(10,1);
lcd.print("P");
lcd.setCursor(6,0); }
lcd.print(TempAverage);
lcd.setCursor(12,0);
lcd.print(TempValue);
lcd.setCursor(6,1);
lcd.print(PhAverage);
lcd.setCursor(11,1);
lcd.print(PhValue);
}
if (CurrentMode == 2){ if (CurrentMode == 1) {
reading(); reading();
double PhVoltage; lcd.setCursor(0, 0);
PhVoltage = (double)PhAverage * (5/10.24); lcd.print("LM35 R");
lcd.setCursor(10, 0);
lcd.setCursor(0,0); lcd.print("T");
lcd.print("R:"); lcd.setCursor(0, 1);
lcd.setCursor(3,0); lcd.print("PH R");
lcd.print(PhAverage); lcd.setCursor(10, 1);
lcd.print("P");
lcd.setCursor(7,0); lcd.setCursor(6, 0);
lcd.print("Ratio:"); lcd.print(TempAverage);
lcd.setCursor(13,0); lcd.setCursor(12, 0);
lcd.print(PhRatio); lcd.print(TempValue);
lcd.setCursor(0,1); lcd.setCursor(6, 1);
lcd.print("PH:"); lcd.print(PhAverage);
lcd.setCursor(3,1); lcd.setCursor(11, 1);
lcd.print(PhValue); lcd.print(PhValue);
} }
if (CurrentMode == 3){ // Calibration Mode Selection Page if (CurrentMode == 2) {
lcd.setCursor(0,0); reading();
lcd.print("PH4 Cal "); double PhVoltage;
lcd.setCursor(0,1); PhVoltage = (double)PhAverage * (5 / 10.24);
lcd.print("PH7 Cal ");
if (CalSelect == 0) { lcd.setCursor(0, 0);
lcd.setCursor(8,0); lcd.print("R:");
lcd.setCursor(3, 0);
lcd.print(PhAverage);
lcd.setCursor(7, 0);
lcd.print("Ratio:");
lcd.setCursor(13, 0);
lcd.print(PhRatio);
lcd.setCursor(0, 1);
lcd.print("PH:");
lcd.setCursor(3, 1);
lcd.print(PhValue);
}
if (CurrentMode == 3) { // Calibration Mode Selection Page
lcd.setCursor(0, 0);
lcd.print("PH4 Cal ");
lcd.setCursor(0, 1);
lcd.print("PH7 Cal ");
if (CalSelect == 0) {
lcd.setCursor(8, 0);
lcd.print(">>"); lcd.print(">>");
} }
if (CalSelect == 1) { if (CalSelect == 1) {
lcd.setCursor(8,1); lcd.setCursor(8, 1);
lcd.print(">>"); lcd.print(">>");
} }
} }
if (CurrentMode == 4){ // PH4 Calibration Mode if (CurrentMode == 4) { // PH4 Calibration Mode
reading();
lcd.setCursor(0,0);
lcd.print("PH4 Cal. Mode");
lcd.setCursor(0,1);
lcd.print("C:");
lcd.setCursor(2,1);
lcd.print(Ph4Reading);
lcd.setCursor(9,1);
lcd.print("R:");
lcd.setCursor(11,1);
lcd.print(PhAverage);
}
if (CurrentMode == 5){ // PH7 Calibration Mode if (calibrate >= 3) {
reading(); reading();
lcd.setCursor(0,0); lcd.setCursor(0, 0);
lcd.print("PH7 Cal. Mode"); lcd.print("PH4 Calibrate");
lcd.setCursor(0,1); lcd.setCursor(0, 1);
lcd.print("C:"); lcd.print("C:");
lcd.setCursor(2,1); lcd.setCursor(2, 1);
lcd.print(Ph7Reading); lcd.print(Ph4Reading);
lcd.setCursor(9,1); lcd.setCursor(9, 1);
lcd.print("R:"); lcd.print("R:");
lcd.setCursor(11,1); lcd.setCursor(11, 1);
lcd.print(PhAverage); lcd.print(PhAverage);
} delay(2000);
reading();
double Ph4Reading = PhAverage;
lcd.setCursor(0, 0);
lcd.print("PH4 Saving ");
lcd.setCursor(0, 1);
lcd.print("C:");
lcd.setCursor(2, 1);
lcd.print(Ph4Reading);
lcd.setCursor(9, 1);
lcd.print("R:");
lcd.setCursor(11, 1);
lcd.print(PhAverage);
//EEPROM.write(addrph4, PhAverage);
EEwriteFloat(addrph4, PhAverage);
calibrate = 0;
delay(2000);
}
if (calibrate < 3) {
reading();
lcd.setCursor(0, 0);
lcd.print("PH4 loded ");
lcd.setCursor(0, 1);
lcd.print("C:");
lcd.setCursor(2, 1);
lcd.print(Ph4Reading);
lcd.setCursor(9, 1);
lcd.print("R:");
lcd.setCursor(11, 1);
lcd.print(PhAverage);
}
}
if (CurrentMode == 5) { // PH7 Calibration Mode
if (calibrate >= 3) {
reading();
lcd.setCursor(0, 0);
lcd.print("PH7 Calibrate");
lcd.setCursor(0, 1);
lcd.print("C:");
lcd.setCursor(2, 1);
lcd.print(Ph7Reading);
lcd.setCursor(9, 1);
lcd.print("R:");
lcd.setCursor(11, 1);
lcd.print(PhAverage);
delay(2000);
reading();
double Ph7Reading = PhAverage;
lcd.setCursor(0, 0);
lcd.print("PH7 Saving ");
lcd.setCursor(0, 1);
lcd.print("C:");
lcd.setCursor(2, 1);
lcd.print(Ph7Reading);
lcd.setCursor(9, 1);
lcd.print("R:");
lcd.setCursor(11, 1);
lcd.print(PhAverage);
//EEPROM.write(addrph7, PhAverage);
EEwriteFloat(addrph7, PhAverage);
//double Ph7Reading = PhAverage;
calibrate = 0;
delay(2000);
}
if (calibrate < 3) {
reading();
lcd.setCursor(0, 0);
lcd.print("PH7 loaded ");
lcd.setCursor(0, 1);
lcd.print("C:");
lcd.setCursor(2, 1);
lcd.print(Ph7Reading);
lcd.setCursor(9, 1);
lcd.print("R:");
lcd.setCursor(11, 1);
lcd.print(PhAverage);
}
}
lcd.setCursor(0,1); // move to the begining of the second line lcd.setCursor(0, 1); // move to the begining of the second line
adc_key_prev = lcd_key ; // Looking for changes adc_key_prev = lcd_key ; // Looking for changes
lcd_key = read_LCD_buttons(); // read the buttons lcd_key = read_LCD_buttons(); // read the buttons
if (adc_key_prev != lcd_key) if (adc_key_prev != lcd_key)
{ {
//Serial.println("Key Press Change Detected"); //Serial.println("Key Press Change Detected");
switch (lcd_key){ // depending on which button was pushed, we perform an action switch (lcd_key) { // depending on which button was pushed, we perform an action
case btnRIGHT:{ // push button "RIGHT" and show the word on the screen case btnRIGHT: { // push button "RIGHT" and show the word on the screen
//lcd.print("RIGHT"); //lcd.print("RIGHT");
if ( CurrentMode == 0 ){
lcd.clear(); calibrate ++;
CurrentMode = 2;
}
if ( CurrentMode == 3){ if ( CurrentMode == 0 ) {
lcd.clear(); lcd.clear();
if ( CalSelect == 0 ){ CurrentMode = 2;
CurrentMode = 4; }
} if ( CurrentMode == 3) {
if ( CalSelect == 1){ lcd.clear();
CurrentMode = 5; if ( CalSelect == 0 ) {
} CurrentMode = 4;
} }
if ( CalSelect == 1) {
CurrentMode = 5;
}
}
break;
}
case btnLEFT: {
//lcd.print("LEFT "); // push button "LEFT" and show the word on the screen
if ( CurrentMode == 2 ) {
lcd.clear();
CurrentMode = 0;
}
if ( CurrentMode == 3 ) {
lcd.clear();
CurrentMode = 0;
}
if ( CurrentMode == 4 || CurrentMode == 5 ) {
lcd.clear();
CurrentMode = 3;
}
break;
}
case btnUP: {
//lcd.print("UP "); // push button "UP" and show the word on the screen
if ( CurrentMode == 0 ) {
lcd.clear();
CurrentMode = 1;
}
if ( CurrentMode == 3 ) {
lcd.clear();
CalSelect = 0;
}
break;
}
case btnDOWN: {
//lcd.print("DOWN "); // push button "DOWN" and show the word on the screen
if ( CurrentMode == 1) {
lcd.clear();
CurrentMode = 0;
}
if ( CurrentMode == 3 ) {
lcd.clear();
CalSelect = 1;
}
break;
}
case btnSELECT: {
//lcd.print("SEL. "); // push button "SELECT" and show the word on the screen
if ( CurrentMode == 0 ) {
lcd.clear();
CurrentMode = 3;
break; break;
} }
case btnLEFT:{ if ( CurrentMode == 3 ) {
//lcd.print("LEFT "); // push button "LEFT" and show the word on the screen lcd.clear();
if ( CurrentMode == 2 ){ CurrentMode = 0;
lcd.clear(); break;
CurrentMode = 0; }
} break;
if ( CurrentMode == 3 ){
lcd.clear();
CurrentMode = 0;
}
if ( CurrentMode == 4 || CurrentMode == 5 ){
lcd.clear();
CurrentMode = 3;
}
break; }
} case btnNONE: {
case btnUP:{ //lcd.print("NONE "); // No action will show "None" on the screen
//lcd.print("UP "); // push button "UP" and show the word on the screen break;
if ( CurrentMode == 0 ){ }
lcd.clear(); }
CurrentMode = 1; }
} }
if ( CurrentMode == 3 ){
lcd.clear(); void EEwriteFloat(int addr, float f) {
CalSelect = 0; unsigned char *buf = (unsigned char*)(&f);
} for ( int i = 0 ; i < sizeof(f) ; i++ ) {
break; EEPROM.write(addr + i, buf[i]);
} }
case btnDOWN:{ }
//lcd.print("DOWN "); // push button "DOWN" and show the word on the screen
if ( CurrentMode == 1){ float EEreadFloat(int addr) {
lcd.clear(); float f;
CurrentMode = 0; unsigned char *buf = (unsigned char*)(&f);
} for ( int i = 0 ; i < sizeof(f) ; i++ ) {
if ( CurrentMode == 3 ){ buf[i] = EEPROM.read(addr + i);
lcd.clear(); }
CalSelect = 1; return f;
}
break;
}
case btnSELECT:{
//lcd.print("SEL. "); // push button "SELECT" and show the word on the screen
if ( CurrentMode == 0 ){
lcd.clear();
CurrentMode = 3;
break;
}
if ( CurrentMode == 3 ){
lcd.clear();
CurrentMode = 0;
break;
}
break;
}
case btnNONE:{
//lcd.print("NONE "); // No action will show "None" on the screen
break;
}
}
}
} }