But it only seems like the accelerometer is measuring tilt. When I am moving it in one direction and not tilting it in any way, the numbers don’t really change. If I then tilt the accelerometer, the values change.
How do you move the device. Accelerometers will not measure velocity but only acceleration.
In what manner do they change?
Accelerometers will usually always report the gravitational acceleration (g) so when you align any of the three axes vertically you should only read 1g in that one direction while the others should report 0g (when not accelerating horizontally).
This way you can test whether each individual axis does get detected correctly or not.
You are correct, I was outputting the serial output every 500ms, so if I decelerated too quickly, it didn't seem print the output. When I reduced the delay, I began to see values go up during acceleration and down during deceleration.
Thanks.
On a side note, related to the code, I simply added the following toggle function. When I toggle the function I just want the state variable to toggle. For some reason, when I publish the state variable in cloud, it always starts off as 1, even though I have initialized the state variable to start as 0. When I call the particle function to toggle the state variable, it goes to 0, but then it immediately goes back to 1. So I am a little confused about how global variables work here...
int ledToggle(String command);
int led = D7; int state = 0; int val = 0;
void setup()
{ Particle.function("ledstate", ledToggle);
pinMode(led, OUTPUT);
// Rest of accelerometer code...
}
void loop()
{ if (state = 1){readAccel();} }
int ledToggle(String command)
{ val = digitalRead(led);
if (val == 0) {
digitalWrite(led, HIGH);
state = 0;
return 0;
} else {
digitalWrite(led, LOW);
state = 1;
return 1;
}
}