Skip to content

Instantly share code, notes, and snippets.

@shirish47
Last active February 10, 2016 13:33
Show Gist options
  • Save shirish47/e246635fb4d7fe8429c3 to your computer and use it in GitHub Desktop.
Save shirish47/e246635fb4d7fe8429c3 to your computer and use it in GitHub Desktop.
Some how EEPROM reading was not working.
#include <EEPROM.h>
#include "EEPROM_store.h"
#define PERIODIC_PERIOD 11
#define PERIODIC_PERIOD2 12
#define CONFIG_PERIOD 13
#define CONFIG_PERIOD2 14
//state flags location
void setup() {
// put your setup code here, to run once:
Serial.begin(4800);
setPeriod(3);
uint8_t j=getPeriod();
Serial.print("j: ");Serial.println(j);
setConfigPeriod(3);
uint8_t g=getConfigPeriod();
Serial.print("g: ");Serial.println(g);
//SetPolicy(2,3);
//Serial.print("Policy :");Serial.println(getPolicy());
}
void loop() {
// put your main code here, to run repeatedly:
}
uint16_t getPeriod()
{
uint8_t p=0;
uint8_t p2=0;
EEPROM.get(PERIODIC_PERIOD,p);
EEPROM.get(PERIODIC_PERIOD,p2);
Serial.print("get Periodic : ");
Serial.print(p);
Serial.print(" get Periodic2 : ");
Serial.println(p2);
delay(1000);
return (((uint16_t)p<<8)|p2);
}
bool setPeriod( uint16_t q)
{
uint8_t p=(q>>8);
uint8_t p2=(q & 0xFF);
EEPROM.put(PERIODIC_PERIOD,p);
EEPROM.put(PERIODIC_PERIOD2,p2);
uint8_t qq=0,qq2=0;
EEPROM.get(PERIODIC_PERIOD,qq);
EEPROM.get(PERIODIC_PERIOD2,qq2);
Serial.print("Periodic : ");
Serial.print(qq);
Serial.print(" Periodic2 : ");
Serial.println(qq2);
if(qq==p && qq2==p2)
{ Serial.println(" Stored Successfully"); }
delay(1000);
}
uint16_t getConfigPeriod()
{
uint8_t p=0;
uint8_t p2=0;
EEPROM.get(CONFIG_PERIOD,p);
EEPROM.get(CONFIG_PERIOD2,p2);
Serial.print("get configPeriodic : ");
Serial.print(p);
Serial.print("get ConfigPeriodic2 : ");
Serial.println(p2);
return ((uint16_t)p<<8)|p2;
}
void setConfigPeriod( uint16_t q)
{
uint8_t p=(q>>8);
uint8_t p2=(q & 0xFF);
uint8_t qq=0,qq2=0;
EEPROM.put(CONFIG_PERIOD,p);
EEPROM.put(CONFIG_PERIOD2,p2);
EEPROM.get(CONFIG_PERIOD,qq);
EEPROM.get(CONFIG_PERIOD2,qq2);
Serial.print("Config Periodic : ");
Serial.print(qq);
Serial.print(" Config Periodic2 : ");
Serial.println(qq2);
if(qq==p && qq2==p2)
{ Serial.println(" Stored Successfully"); }
delay(1000);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment