117Views3Replies

Author Options:

how to save float value EEPROM Answered

Hi This is Eabul. i want to save data to eeprom from press button . when TemperatureUp button press. increase float data like as 0.01> 0.02--------30.10> 30.61 and this value save to eeprom. and when TemperatureDown button press . decrease float data like as 30.60>30.59-----29.10 and update minus value eeprom and increase and decrease valud view lcd display . but when press button save int number not float. and show me lcd display int value. please help how to write and read float value from eeprom. press button. hear my code. //For Display #include // 3wire display LiquidCrystal595 lcd(4, 3, 2); // DS, ST_CP, SH_CP //For time #include #include RTC_DS1307 RTC; //for humidity #include "DHT.h" DHT dht; //for stor tempereratur and humidity #include int SetHumidity; int HumidityUp = 10; // switch up is at pin 10 int HumidityDown = 11; // switch down is at pin 11 float fix = 0.01; float settemp; // make a variable called temp float TemperatureUp = 12; // switch up is at pin 12 float TemperatureDown = 13; // switch down is at pin 13 //result view int led = 0; // led is at pin 0 void setup() { //For timer Wire.begin(); RTC.begin(); //For welcome screen lcd.begin(16,4); lcd.setCursor(0,0); lcd.print("Welcome Elab"); delay(2000); lcd.clear(); //for dht-11 pin setup dht.setup(A1); // data pin 2 } void loop() { //For tempererature up / down float temp[3]; getTemp(temp); float tempererature = temp[1]; settemp = EEPROM.read(1); // read the settemp on the eeprom if(digitalRead(TemperatureUp) == 1 ) { settemp+=fix; settemp++; EEPROM.write (1, settemp); /* write the most recent settemp in eeprom data stoage*/ } else {} if(digitalRead (TemperatureDown) == 1) { settemp -= fix; settemp--; EEPROM.write (1, settemp); /* write the most recent settemp in eeprom data stoage*/ } if (tempererature >= settemp) { digitalWrite (led, 1); } else { digitalWrite (led, 0);} //else { }; lcd.setCursor(0,0); lcd.print("T:"); lcd.print(tempererature); lcd.setCursor(8,0); lcd.print ("ST"); lcd.print (settemp); lcd.print((char)223); //End tempererature controll //For humidity up / down SetHumidity = EEPROM.read(2); int humidity = dht.getHumidity(); if(digitalRead(HumidityUp ) == 0 ) {SetHumidity++ ; } // add one to the settemp else {} if(digitalRead (HumidityDown) == 0) { SetHumidity--; } // Reduse settemp else { }; lcd.setCursor (0, 1); lcd.print ("CH:"); lcd.print (humidity); lcd.print ("%"); lcd.setCursor (8, 1); lcd.print ("SH:"); lcd.print (SetHumidity); lcd.print ("%"); delay (1); // wait 100 milliseconds EEPROM.write (2, SetHumidity); /* write the most recent settemp in eeprom data stoage*/ //End tempererature controll controll } //analog temperature void getTemp(float * t) { const int analogPin = 0; // replace 0 with analog pin const float invBeta = 1.00 / 3380.00; // replace "Beta" with beta of thermistor const float adcMax = 1023.00; const float invT0 = 1.00 / 298.15; // room temp in Kelvin int adcVal, i, numSamples = 5; float K, C, F; adcVal = 0; for (i = 0; i < numSamples; i++) { adcVal = adcVal + analogRead(analogPin); delay(100); } adcVal = adcVal/5; K = 1.00 / (invT0 + invBeta*(log ( adcMax / (float) adcVal - 1.00))); C = K - 273.15; // convert to Celsius F = ((9.0*C)/5.00) + 32.00; // convert to Fahrenheit t[0] = K; t[1] = C; t[2] = F; return; }

Tags:EEPROM

3 Replies

user
steveastrouk (author)2017-12-17

If I were you, I'd format the code before posting it here.

As I am me, I won't bother reading this.

Select as Best AnswerUndo Best Answer

user

Thinking in the same direction here but have to confess that the standard editor loves to produce this mess if you paste from the wrong source.
One more reason why I prefer Notepad++

Select as Best AnswerUndo Best Answer

user

Yes, but you should watch what happens and try and to better. There are different snipping options in Arduino for just this sort of reason. Its a shame. This damned site used to support the code tag

Select as Best AnswerUndo Best Answer