I have a question concerning code I am trying to develop for a motion sensor of sorts.
I am using a Arduino to read from ADXL345. I want to take a "sample" of the XYZ two times a second and compare the two samples. Ideally storing each of the two samples in a variable. I want to add in a sensitivity slider on my app that will allow me to make it more or less sensitive. This is what I have so far. I am attempting to utilize Blynk for app control...my problem relates to the error I am receiving on compiling which is Exit Status 1, 'x' was not declared in this scope on the line "adxl.readAccel(&x,&y,&z); " . Can someone assist me? I built this on top of existing working code that sampled the xyz one time, but adding a second time may have caused issue. There may be a better way to sample twice and compare, but I am having issues finding any hints.
long sum1 = x1+y1+z1;
long sum2 = x1+y2+z2;
long total = sum1-sum2;
if (total > sliderValue);
My code is actually very long, and consists of 11 tabs in total...if you count all the Blynk Edgent tabs that control the OTA, the communication between devices, and the settings. I suppose my question would be. If you wanted to know if motion occurred and have the ability to adjust sensitivity from very sensitive(a light breeze perhaps) to not so sensitive(a decent shake or movement) is there a better way to pull from the ADXL? I am looking into averaging to avoid noise, that is a great idea.
I am wanting to get away from relational data computations that seems to be messing with our dashboard. Thinking that it might be more code, but simpler to compute. So I was hoping to basically know if the device moves and have a slider to adjust how much movement before triggering an event or buzzer.
int x1, y1, z1;
adxl.readAccel(&x1, &y1, &z1);
int x2, y2, z2;
adxl.readAccel(&x2, &y2, &z2);
// Deltas: Changes in acceleration
// Using 'long' because they will be squared soon
long dx = x1 - x2;
long dy = y1 - y2;
long dz = z1 - z2;
// Sum of the squares of the deltas
long movement = (dx * dx) + (dy * dy) + ( dz * dz);
if (movement > threshold)
// Something moved