Hello
I am Having difficulty using the EEPROM commands for my project.
i have a accelerometor that is hooked up to my Arduino uno r3 the accelerometer is an adafruit MMA8541.
the code right now is simplified just for the z axis but once it works will be applied to x and y.
the code is meant to read acceleration in z. ( its on the table now so its about 9.81m/s^2 (1g)
then when i push a button it EEPROM.writes the current acceleration and remembered that number i.e 9.81 called valz ( in code this is event.acceleration)
then a for loop for 50 times that using the EEMPROM.put command will subtract the valz from any event.acceleration.z in the for loop.
when i move the accelerometer it doesn't do the subtraction i want it just makes new z = 0
right now i think the Float valz = event,acceloration.x is setting them equal to each other for the rest of the code when i just want valz to rememeber at button press. i tried == instead f = but this didn't work any help would be great than you
code and serial monitor screenshot below
Thank you
#include <Wire.h>
#include <Adafruit_MMA8451.h>
#include <Adafruit_Sensor.h>
Adafruit_MMA8451 mma = Adafruit_MMA8451();
#include <EEPROM.h>
int addr = 0;
const int buttonPin = 2;
int buttonState = 0;
int measurementCount =1;
void setup(void) {
Serial.begin(9600);
pinMode(buttonPin, INPUT_PULLUP);
Serial.println("Adafruit MMA8451 test!");
if (! mma.begin()) {
Serial.println("Couldnt start");
while (1);
}
Serial.println("MMA8451 found!");
}
void loop() {
/* Get a new sensor event */
sensors_event_t event;
mma.getEvent(&event);
/* Display the results (acceleration is measured in m/s^2) */
Serial.print("Z: \t"); Serial.print(event.acceleration.z); Serial.print("\t");
Serial.println("m/s^2 ");
buttonState = digitalRead(buttonPin);
Serial.println(buttonState);
if(buttonState == LOW){
float valz = event.acceleration.z;
EEPROM.write(addr, valz);
Serial.print("valz");
Serial.print(valz);
Serial.println();
for(measurementCount; measurementCount<100; measurementCount++) {
float NewZ; //NEW Z
NewZ == event.acceleration.z - EEPROM.get(addr, valz);
Serial.print("NewZ ");
Serial.print(NewZ);
Serial.println();
Serial.print("measurementcout");
Serial.println(measurementCount);
}
}
delay(500);
}