I have a strange issue with a sketch I've written to test some code I'm working on for a project, a HVAC control system.
This specific code is to pull some data from the onboard EEPROM and display it on a LCD screen.
The values were written to EEPROM in another sketch as follows:
EEPROM.write(41,0);
EEPROM.write(42,1);
EEPROM.write(43,9);
EEPROM.write(44,30);
When I read out the values in a sketch and send them to the serial monitor, they are correct, but when I run the sketch I'm working on, I only get the following on the serial monitor:
41
memstate is 0
memday is 0
memhour is 0
memmin is 0
My sketch is as follows:
// Switch Times Setting test
#include <EEPROM.h>
#include <OneWire.h>
#include <Wire.h>
#include <LCD.h>
#include <LiquidCrystal_I2C.h>
#define I2C_ADDR 0x27 // <<----- Add your address here. Find it from I2C Scanner
#define BACKLIGHT_PIN 3
#define En_pin 2
#define Rw_pin 1
#define Rs_pin 0
#define D4_pin 4
#define D5_pin 5
#define D6_pin 6
#define D7_pin 7
LiquidCrystal_I2C lcd(I2C_ADDR,En_pin,Rw_pin,Rs_pin,D4_pin,D5_pin,D6_pin,D7_pin);
int memPin = 1;
int dayPin = 2;
int hrPin = 3;
int minPin = 4;
int statePin = 5;
int backPin = 6;
int memSlot = 4;
int memstate;
int memday;
int memhour;
int memmin;
int i;
void setup ()
{
Serial.begin(9600);
pinMode(memPin,INPUT_PULLUP);
pinMode(dayPin,INPUT_PULLUP);
pinMode(hrPin,INPUT_PULLUP);
pinMode(minPin,INPUT_PULLUP);
pinMode(statePin,INPUT_PULLUP);
pinMode(backPin,INPUT_PULLUP);
lcd.begin (20,4);
lcd.setBacklightPin(BACKLIGHT_PIN,POSITIVE);
lcd.setBacklight(HIGH);
}
void loop ()
{
//code
lcd.clear();
if (digitalRead(memPin) == 0){
lcd.home();
lcd.print(F("Set Switch Times"));
delay(2000);
lcd.home();
lcd.print(" ");
while (digitalRead(backPin) == 1){
i = (memSlot * 10) + 1;
Serial.println(i);
memstate == EEPROM.read(i);
Serial.print("memstate is ");Serial.println(memstate);
i = i++;
memday == EEPROM.read(i);
Serial.print("memday is ");Serial.println(memday);
i = i++;
memhour == EEPROM.read(i);
Serial.print("memhour is ");Serial.println(memhour);
i = i++;
memmin == EEPROM.read(i);
Serial.print("memmin is ");Serial.println(memmin);
lcd.home();
lcd.print("Memory Slot ");lcd.print(memSlot);
lcd.setCursor(0,1);
lcd.print("Heating: ");
if (memstate == 0) {
lcd.print("Off");
}
else {
lcd.print("On");
}
lcd.setCursor(0,2);
lcd.print("Day: ");
switch (memday) {
case 0:
lcd.print("Every Day");
break;
case 1:
lcd.print("Sunday");
break;
case 2:
lcd.print("Monday");
break;
case 3:
lcd.print("Tuesday");
break;
case 4:
lcd.print("Wednesday");
break;
case 5:
lcd.print("Thursday");
break;
case 6:
lcd.print("Friday");
break;
case 7:
lcd.print("Saturday");
break;
case 8:
lcd.print("Weekdays");
break;
case 9:
lcd.print("Weekends");
break;
}
lcd.setCursor(0,3);
lcd.print("Time: ");
if (memhour < 10) lcd.print("0");
lcd.print(memhour); lcd.print(":");
if (memmin < 10) lcd.print("0");
lcd.print(memmin);
}
}
}
Can anyone point me where I should be looking to troubleshoot this?
Thanks and regards,
Stefan