#include <EEPROM.h>
int zpin = A1; //specify pins
int accelerometer_z;
int eeAddress = 0;
bool isFilled = false;
bool data = false;
float f = 0.00f;
void setup() {
// put your setup code here, to run once:
delay(500); // Delay for 10 minutes here
Serial.begin(9600);
while (!Serial) { // Wait for port to connect, only needed for USB connection. REMOVE FOR REAL
;
}
// EEPROM.put(252, 0.00f); // MAKE THIS NOT 9.99 TO START RECORDING Initialization: Only have this to reset variable. Actual: Remove this code
if (EEPROM.get(252, f) == 9.99f){
isFilled = true;
}
Serial.println(isFilled);
Serial.println(EEPROM.get(252, f));
delay(600000); // 10 minute timer for actual thing. 600000
}
void loop() {
accelerometer_z = analogRead(zpin); //reads values from Z-pin & measures acceleration in Z direction
int z = map(accelerometer_z, 289, 430, -100, 100); //maps the extreme ends analog values from -100 to 100 for our understanding
//calibrate and change the 272 and 403 here!!!
float zg = (float)z/(100.00); //converts the mapped value into acceleration in terms of "g"
Serial.print(zg); //prints value of acceleration in Z direction
Serial.print("g, "); //prints "g"
if (data == false && isFilled == false){
EEPROM.put(eeAddress, zg);
}
if (eeAddress == 252)
{
data = true;
EEPROM.put(252, 9.99f); // 9.99 says that there is a reading
eeAddress = 0;
}
Serial.print("EEPROM: ");
Serial.print(EEPROM.get(eeAddress, f));
Serial.print(" Memory Address:");
Serial.print(eeAddress);
Serial.println("; ");
eeAddress += sizeof(float); // Move past 4 bytes to next place
delay(750); // Change to time needed to read 0.75s
}
//