EEPROM WITH 2 ADDRESS

eeprom2

The code can be downloaded at : https://github.com/triantara/ARDUINO-TRIANTARA/blob/main/Eeprom%20two%20address.zip

#include <avr/interrupt.h>
#include <avr/eeprom.h>
int addr1 = 1;
int addr2 = 9;//avoid to use address 2
int readValue1;
int readValue2;
int a;
int b;
//int encoder_pin = 5;
const int buttonPin1 = 4;
int buttonState1 = 0;
const int buttonPin2 = 3;
int buttonState2 = 0;
void setup()
{
Serial.begin(9600);
//pinMode(encoder_pin, INPUT);
pinMode(buttonPin1, INPUT);
pinMode(buttonPin2, INPUT);
digitalWrite(buttonPin1, HIGH);
digitalWrite(buttonPin2, HIGH);

}

void loop() {
buttonState1 = digitalRead(buttonPin1);
buttonState2 = digitalRead(buttonPin2);
if (buttonState1 == LOW) {
a = analogRead(A0);
while (!eeprom_is_ready());
cli();
if(eeprom_read_word((uint16_t*)addr1) != a) {
eeprom_write_word((uint16_t*)addr1, a);
}
sei();

}
else if (buttonState2 == LOW) {
a = analogRead(A0);
while (!eeprom_is_ready());
//cli();
if(eeprom_read_word((uint16_t*)addr2) != a) {
eeprom_write_word((uint16_t*)addr2, a);
}
sei();

}
else{
readValue1 = eeprom_read_word((uint16_t*)addr1);
readValue2 = eeprom_read_word((uint16_t*)addr2);
a = analogRead(A0);
Serial.print(readValue1);
Serial.print(” “);
Serial.print(readValue2);
Serial.print(” “);
Serial.println(a);

}

}

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s