rookie
I am currently trying to make a program to write the data from a sensor to the EEPROM as I cannot have my computer near (water based environment). I am also trying to keep the data as int's for greater data accuracy/ range. therefore i have split the int into bytes (or attempted to). I tested the output through the serial monitor and i was getting a varying out put which was good, so hopefully these were all being written to the EEPROM.
The read program would only giving me a repeating value when viewed through the serial monitor. (frustrating).
Help would be greatly appreciated. There is probably something super obvious that I'm missing.
Write code:
#include <EEPROM.h>
int MuscleSensorPin = A1;
int p_address = 0; //what does this do???
int p_value;
void EEPROMWriteInt(int p_address, int p_value)
{
p_value = analogRead (MuscleSensorPin);
Serial.println(p_value);
byte lowByte = ((p_value >> 0) & 0xFF);
byte highByte = ((p_value >> 8) & 0xFF);
EEPROM.write(p_address, lowByte);
EEPROM.write(p_address + 1, highByte);
p_address=( p_address + 1);
}
void setup() {
Serial.begin(9600);
delay(4000);
}
void loop() {
EEPROMWriteInt(0 , p_value);
delay(250);
}
Read CODE:
#include <EEPROM.h>
int p_address = 0;
byte value;
unsigned int EEPROMReadInt(int p_address)
{
byte lowByte = EEPROM.read(p_address);
byte highByte = EEPROM.read(p_address + 1);
return ((lowByte << 0) & 0xFF) + ((highByte << 8) & 0xFF00);
p_address=( p_address + 1);
delay (500);
}
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for native USB port only
}
}
void loop()
{
Serial.println (EEPROMReadInt(p_address));
}