### Author Topic: Translate acceleration in G's to textual states.  (Read 70 times)

#### Junkboy

• Newbie
• Posts: 11
##### Translate acceleration in G's to textual states.
« on: July 09, 2018, 03:10:42 pm »
Hello community of McThings, I am developing a project, in which I am using a module Mc120, which currently transmits via MQTT the angles of inclination and the acceleration of all its axes, all this information is sent every 3 seconds, since it is Very fast, a battery that in "theory" should last up to 5 years lasts no more than 2 weeks.

What is currently done is to receive the acceleration and tilt of the device in an MQTT server, the information is analyzed to translate the states to a person for example "Walking" or "Running" etc.

What I want to do to save battery is the following:

I think to use the function:
accel.ConfigureMotionInterrupt (1.15, 20.0)

This would cause an interruption when there is an acceleration equal to or greater than 1.15G for more than 2 ms, this is just an example in practice those parameters would change.

The idea would be to set the parameters so that when there is some acceleration the device wakes up and knows that there is movement, then it would have to verify in which case it is.

In my personal experience I know a lot more about the C ++ language so I can imagine it in this way in C ++:

if (accel> = 1.15)
{
state = ON;
}

if (accel> = 1.15 && accel <= 1.
{
printf ("Walking"),
}
if (accel> = 1.81 && accel <= 2.2)
{
printf ("Runing"),
}
if (accel <= 1.15)
{
printf ("Stopped"),
}

With these conditions I seek to make instead of every 3 seconds send me the acceleration etc, better the device stays off until there is some acceleration and send me the message that is what you are doing, in the case of "Stopped" is only to put it because in reality if there is no acceleration greater than 1.15 will not turn on, that's the idea and in fact I also have to do some condition or something so that as long as it is lower than 1.15 send the message "Stopped" but. I do not want them to repeat either, that is if the current state is "Stopped" that sends it only once, if it starts to walk then it sends "Walking" but if it kept walking 15 minutes, do not send me that message again until it change of state

I hope to be explaining, the truth is a bit complicated programming in McStudio for me, but I would like to know if someone can help me to translate this to the language used in McStudio because for example I do not know how to put a conditional with intervals, in the case of "if (accel > = 1.15 && accel <= 1." I do not know how to do it in McStudio, nor am I sure how to make the data not repeat.

I would really appreciate very much if someone could support me a little with this.

Beforehand thank you very much.