I am building a project where I have to store the digital state which is Boolean (either HIGH or LOW) of each I/O port such that after power off the state of I/O ports store in EEPROM and I can retrieve this I/O port's state after power on.
This is my code..
#include <IRremote.h>
#include <EEPROM.h>
int EEPROMaddress = 0;
int EEPROMaddress1 = 1;
byte EEPROMbyte = EEPROM.read(EEPROMaddress);
byte EEPROMbyte1 = EEPROM.read(EEPROMaddress1);
int RECV_PIN = 11;
int led = 10;//1FE50AF
int led1 = 9;//1FED827
boolean previousState = bitRead(EEPROM.read(EEPROMaddress), led);
boolean previousState1 = bitRead(EEPROM.read(EEPROMaddress1), led1);
boolean state;
boolean state1;
IRrecv irrecv(RECV_PIN);
decode_results results;
void setup()
{
Serial.begin(9600);
pinMode(10,OUTPUT);
pinMode(9,OUTPUT);
irrecv.enableIRIn();
}
void loop() {
if (irrecv.decode(&results))
{
Serial.println(results.value, HEX);
switch(results.value)
{
case 0x1FE50AF:
if (previousState == LOW)
{state = HIGH;
digitalWrite(led,state);
previousState=state;
bitWrite(EEPROMbyte,led,state);
EEPROM.update(EEPROMaddress,EEPROMbyte);
delay(50);}
else
{state=LOW;
digitalWrite(led,state);
previousState=state;
bitWrite(EEPROMbyte,led, state);
EEPROM.update(EEPROMaddress,EEPROMbyte);
delay(50);
}
break;
case 0x1FED827:
if (previousState1 == LOW)
{state1=HIGH;
digitalWrite(led1,state1);
previousState1=state1;
bitWrite(EEPROMbyte1,led1, state1);
delay(50);}
else
{state1=LOW;
digitalWrite(led1,state1);
previousState1=state1;
bitWrite(EEPROMbyte1,led1,state1);
delay(50);}
break;
}
irrecv.resume();
}
}