# Trying to determine if my NANO 33BLE is stationary at any time for a designated time frame

Below is the latest try with no luck. If anyone can help. I am using an NANO 33BLE board and have completed one part of my program which does all the functions with delivering
outputs for buzzers, lights and motor.
I thought this second part would be easier, four days of trying and I have to ask for help. This is my first Arduino project but I have a background in PLC logic programming.

What I am trying to achieve is: (this is only for one ACC value but I will need to repeat the same for ACC x, y, z and GYRO x, y , z) all with the same function of determining when the board is stationary for a set period.

In this code I am testing that ACC axis value of x is equal to itself for a set loop period. If true then print no movement and set a bool function for x axis ( so I can start another function when the board is determined as moving). This code needs to be continually checking to determine if the code x = x is true.
I hope I have clearly explained.

The part I haven't been able to achieve is:

#include <Arduino_LSM9DS1.h>

//#define MAX_COUNT 20
//int loop_count = 0;
int degreesX = 0;
int degreesY = 0;
int degreesZ = 0;
float x, y, z;
int a = x+1; // a used to compare ACC x axis as the previous value
int b = x; // b is equal to be for comparison equation

void setup() {
Serial.begin(9600);
while (!Serial);
Serial.println("Started");

if (!IMU.begin()) {
Serial.println("Failed to initialize IMU!");
while (1);
}

Serial.print("Accelerometer sample rate = ");
Serial.print(IMU.accelerationSampleRate());
Serial.println("Hz");

}

void loop() {

if (IMU.accelerationAvailable()) {
}
{ if // Read IMU, here value for x, checks it within a
(x > -0.3) // threshold, and if true will print, Tilting Up or Down,
{
x = 100*x;
degreesX = map(x, 0, 97, 0, 90); // This part of the code works and prints the
Serial.print(" Tilting up "); // angle of the board in degrees
Serial.print(degreesX);
Serial.println(" degrees");
delay(1000);}

if(x < -0.3)
{
x = 100*x;
degreesX = map(x, 0, -100, 0, 90);
Serial.print("Tilting down "); // This part of the code works and prints the
Serial.print(degreesX); // angle of the board in degrees
Serial.println(" degrees");
delay(100);
}

else { (b == (a-1)); //This is the part I can't work out
delay(1000); //compare (b == (a-1)) which should be
for (int n=0;n>=10; n++){ // true if the board is stationary at any
Serial.print(" No Movement "); // angle for a count of 10 loops
bool (xaxis) = false // if true print No Movement
// bool set to false so I can use it to start
} // another part of the program
}
}

}

disregard that part, it isn't needed, it was a left over of a previous try of comparing ACCx == ACCx for twenty counts before declaring "No movement"

@bartman74, your topic has been moved to a more suitable location on the forum; see About the Installation & Troubleshooting category

can i suggest it would be helpful if you gave the topic a meaningful title?
and perhaps tell us what it SHOULD do?

Sorry thought I did.

I am trying to determine if the NANO 33BLE is stationary for a allocated period if so don't progress with anything until this is false.
I need to do this for each ACC axis and all GYRO axis.

I was trying to use ACC axis 'x' and have x = = x or degreesX == degreesX for my code. For example: if board is stationary within a set threshhold of say + or - 6 degrees and this occurs for a count of 10 loops or for 3 seconds, if true print 'No Movement'. If board is determined moving allow another part of the code to start.
I tried using a compare to previous sketch .
I did find this sketch, when I added it into my code I couldn't get it to work.

unsigned long prevValue = 0;
unsigned long currValue = mySwitch.getReceivedValue();

if(currValue != prevValue)
{
// Got a new value
}
else
{
// Same old same old
}
prevValue = currValue;

I appreciate any help and say thank you in advance.

Thanks, sorry.

Welcome,

Something like this (untested)

``````void loop()
{
if (IMU.accelerationAvailable())
{
float fx = 0, fy = 0, fz = 0;
IMU.readAcceleration( fx, fy, fz );

int x = fx * 100;
static int x_previous = x;
static bool x_changed = true;

if ( x_previous != x )
{
x_previous = x;
x_changed = true;
}

static bool degreesX_changed = true;
static uint32_t degreesX_changed_millis = 0;

if ( x_changed )
{
x_changed = false;

int degreesX = 0;

if ( x > -30 )
{
degreesX = map(x, 0, 97, 0, 90);
Serial.print(" Tilting up ");
Serial.print(degreesX);
Serial.println(" degrees");
}

else if ( x < -30 )
{
degreesX = map(x, 0, -100, 0, 90);
Serial.print("Tilting down ");
Serial.print(degreesX);
Serial.println(" degrees");
}

static int degreesX_previous = degreesX;
if ( degreesX_previous != degreesX )
{
degreesX_previous = degreesX;
degreesX_changed = true;
degreesX_changed_millis = millis();
}
}

if ( degreesX_changed && millis() - degreesX_changed_millis >= 10000 )
{
degreesX_changed = false;
Serial.println("degreesX didn't change since at least 10 seconds.");
}
}
}
``````

I would use something like this. It just compares the sum of the squares of the changes in acceleration against a threshold you choose.

``````#include <Arduino_LSM9DS1.h>

const unsigned long StandingStillInterval = 2000;

const float MagnitudeThreshold = 123.456;  // Determine by experiment

float x, y, z;
float oldX, oldY, oldZ;
bolean HasBeenStill = false;

void setup()
{
Serial.begin(9600);
while (!Serial);
Serial.println("Started");

if (!IMU.begin())
{
Serial.println("Failed to initialize IMU!");
while (1);
}

Serial.print("Accelerometer sample rate = ");
Serial.print(IMU.accelerationSampleRate());
Serial.println("Hz");
}

void loop()
{
static unsigned long timeLastMoved = 0;

if (HasMoved())
timeLastMoved = millis();

if (millis() - timeLastMoved >= StandingStillInterval)
HasBeenStill = true;
}

float square(const float f)
{
return f * f;
}

boolean HasMoved()
{
if (!IMU.accelerationAvailable())
return false;  // Can't tell if it has moved because data isn't available

float magnitudeOfChange = square(x - oldX) + square(y - oldY) + square(z - oldZ);

oldX = x;
oldY = y;
oldZ = z;

return magnitudeOfChange > MagnitudeThreshold;
}``````

Thanks I will try them both later today

Hi John,

I tried it out but got the following errors:

Arduino: 1.8.15 (Windows Store 1.8.49.0) (Windows 10), Board: "Arduino Nano 33 BLE"

libraries\Wire\Wire.cpp.o: In function `arduino::MbedI2C::receiveThd()':

C:\Users...........\ArduinoData\packages\arduino\hardware\mbed_nano\2.1.0\libraries\Wire/Wire.cpp:169: undefined reference to `yield'

libraries\Wire\Wire.cpp.o:(.rodata._ZTVN7arduino7MbedI2CE+0xc): undefined reference to `arduino::Print::write(unsigned char const*, unsigned int)'

C:\Users.......\AppData\Local\Temp\arduino_build_371097/core\core.a(Serial.cpp.o): In function `arduino::UART::operator bool()':

C:\Users..........\ArduinoData\packages\arduino\hardware\mbed_nano\2.1.0\cores\arduino\USB/PluggableUSBSerial.h:272: undefined reference to `delay'

C:\Users........\AppData\Local\Temp\arduino_build_371097/core\core.a(USBSerial.cpp.o): In function `arduino::USBSerial::operator bool()':

C:\Users.............\ArduinoData\packages\arduino\hardware\mbed_nano\2.1.0\cores\arduino\USB/PluggableUSBSerial.h:272: undefined reference to `delay'

C:\Users......\AppData\Local\Temp\arduino_build_371097/core\core.a(USBSerial.cpp.o): In function `waitForPortClose()':

C:\Users...........\ArduinoData\packages\arduino\hardware\mbed_nano\2.1.0\cores\arduino\USB/USBSerial.cpp:35: undefined reference to `millis'

C:\Users...........\ArduinoData\packages\arduino\hardware\mbed_nano\2.1.0\cores\arduino\USB/USBSerial.cpp:39: undefined reference to `delay'

C:\Users..........\ArduinoData\packages\arduino\hardware\mbed_nano\2.1.0\cores\arduino\USB/USBSerial.cpp:37: undefined reference to `millis'

C:\Users.......\ArduinoData\packages\arduino\hardware\mbed_nano\2.1.0\variants\ARDUINO_NANO33BLE/libs/libmbed.a(mbed_boot_gcc_arm.o): In function `__wrap_main':

mbed_boot_gcc_arm.c:(.text.__wrap_main+0x0): undefined reference to `main'

collect2.exe: error: ld returned 1 exit status

exit status 1

Error compiling for board Arduino Nano 33 BLE.

I was getting a few of these when I tried a couple of different code variations that I wrote and others from examples I found. Not sure why it is giving these errors.

Hi guix,

I did try your suggestion, it did compile with no errors but the code didn't work. I made some changes and have got it so it is half working. I can see the values are calculating but the two boolean statements aren't working as should be. I have been trying for last few hours but can't seem to find a solution. Any suggestions would be greatly appreciated.

#include <Arduino_LSM9DS1.h>

int degreesX = 0;

void setup()
{
Serial.begin(9600);
while (!Serial);
Serial.println("Started");

if (!IMU.begin())
{
Serial.println("Failed to initialize IMU!");
while (1);
}

Serial.print("Accelerometer sample rate = ");
Serial.print(IMU.accelerationSampleRate());
Serial.println("Hz");
}

void loop()
{
if (IMU.accelerationAvailable())
{
float fx = 0, fy = 0, fz = 0;
IMU.readAcceleration( fx, fy, fz );

``````int x1 = fx * 100;
static int x1_previous = x1 + 1;
static bool x1_changed = true;
int x2 = fx * 100;
static int x2_previous = x2 + 1;
static bool x2_changed = true;
int i = 1;
int j = 1;
if (x1_previous)
{
(( x1_previous - 1) == x1  );
for(int i = 1; i <= 10; i++);
//x1_previous = x;
x1_changed = true;
Serial.print (i);
Serial.print ("  i value   ");
Serial.print ( x1 );
Serial.print (  " x1 value   "  );
Serial.print ( x1_previous );
Serial.print ("  x1_previous "  );
Serial.print  ("   X-axis no movement    ");
}
else (x1_changed = false);

if (x2_previous)
{
(( x2_previous - 1) != x2 );
for(int j = 1; j <= 10; j++);
//x2_previous = x;
x2_changed = true;
Serial.print (j);
Serial.print ("  j value   ");
Serial.print ( x2 );
Serial.print (  " x2 value   "  );
Serial.print ( x2_previous );
Serial.print ("  x2_previous "  );
Serial.print ("   X-axis has movement    ");
}
else (x2_changed = false);
``````

// static bool degreesX_changed = true;
// static uint32_t degreesX_changed_millis = 0;

// if ( x_changed )
// {
// x_changed = false;

``````//  int degreesX = 0;

if ( x1 > 0.3 )
{
degreesX = map(x1, 0, 97, 0, 90);
Serial.print(" Tilting up ");
Serial.print(degreesX);
Serial.println(" degrees");
delay (1000);
}

else if ( x2 < -0.3 )
{
degreesX = map(x2, 0, -100, 0, 90);
Serial.print("Tilting down ");
Serial.print(degreesX);
Serial.println(" degrees");
delay (1000);
}
``````

if (x1_changed)
{(x1_changed = true);
Serial.print(" Pepsi is sleeping " );
Serial.print (" Yes I done it!!! ");
}

if (x2_changed)
(x2_changed = true);
{Serial.print(" Pepsi is walking " );
Serial.print (" Yes I dont it again!!! ");
}

}

``````//  static int degreesX_previous = degreesX;
//  if ( degreesX_previous != degreesX )
// {
//    degreesX_previous = degreesX;
//    degreesX_changed = true;
//    degreesX_changed_millis = millis();
//  }
``````

// }

// if ( degreesX_changed && millis() - degreesX_changed_millis >= 10000 )
// {
// degreesX_changed = false;
// Serial.println("degreesX didn't change since at least 10 seconds.");
}

// }

Did you select the board:

`"Arduino Mbed OS Boards (nRF52840, STM32H747)" -> "Arduino Nano 33 BLE"`

`"Arduino Mbed OS Nano Boards" -> "Arduino 33 Nano BLE"`

When I installed the library and selected the newer Nano 33 BLE, I got no errors or warnings after I fixed my obvious typo of "bolean" instead of "boolean".

Hi John,

I had 1.9.1, updated to 2.0 and got rid of previous error. But I am stuck with a few more I haven't been able to work out yet.

#include <Arduino_LSM9DS1.h>

const unsigned long StandingStillInterval = 2000;

const float MagnitudeThreshold = 123.456; // Determine by experiment

float x, y, z;
float oldX, oldY, oldZ;
bool HasBeenStill = false;
bool HasMoved = false;
int degreesX = 0;

void setup()
{
Serial.begin(9600);
Serial.println("Started");

if (!IMU.begin())
{
Serial.println("Failed to initialize IMU!");

}

Serial.print("Accelerometer sample rate = ");
Serial.print(IMU.accelerationSampleRate());
Serial.println("Hz");
}

void loop(){

static unsigned long timeLastMoved = 0;

if (HasMoved())
timeLastMoved = millis());

if (millis() - timeLastMoved >= StandingStillInterval)
HasBeenStill = true;
}

float sqrt(const float f);
{
return f * f;
}

bool HasMoved()

if (!IMU.accelerationAvailable())
return false; // Can't tell if it has moved because data isn't available

{
}
{
float magnitudeOfChange = sqrt(x - oldX) + sqrt(y - oldY) + sqrt(z - oldZ);

oldX = x;
oldY = y;
oldZ = z;

return magnitudeOfChange > MagnitudeThreshold;
}

// if (IMU.accelerationAvailable()) {
// IMU.readAcceleration(x, y, z);
// }
{ if
(x > -0.3)
{
x = 100*x;
degreesX = map(x, 0, 97, 0, 90);
Serial.print(" Tilting up ");
Serial.print(degreesX);
Serial.println(" degrees");
delay(1000);}

if(x < -0.3)
{
x = 100*x;
degreesX = map(x, 0, -100, 0, 90);
Serial.print("Tilting down ");
Serial.print(degreesX);
Serial.println(" degrees");
delay(100);
}
}
}

The following is the current errors:

Arduino: 1.8.15 (Windows Store 1.8.49.0) (Windows 10), Board: "Arduino Nano 33 BLE"

C:\Users.......\Documents\Arduino\Test_compare_1\Test_compare_1.ino: In function 'void loop()':

Test_compare_1:37:17: error: 'HasMoved' cannot be used as a function

if (HasMoved())

``````             ^
``````

Test_compare_1:38:29: error: expected ';' before ')' token

`````` timeLastMoved = millis());

^
``````

C:\Users.....\Documents\Arduino\Test_compare_1\Test_compare_1.ino: At global scope:

Test_compare_1:44:25: error: 'float sqrt(float)' conflicts with a previous declaration

float sqrt(const float f);

``````                     ^
``````

In file included from c:\users......\documents\arduinodata\packages\arduino\tools\arm-none-eabi-gcc\7-2017q4\arm-none-eabi\include\c++\7.2.1\math.h:36:0,

``````             from C:\Users\.......Documents\ArduinoData\packages\arduino\hardware\mbed_nano\2.2.0\cores\arduino/api/ArduinoAPI.h:47,

from C:\Users\......\Documents\ArduinoData\packages\arduino\hardware\mbed_nano\2.2.0\cores\arduino/Arduino.h:30,

from sketch\Test_compare_1.ino.cpp:1:
``````

c:\users.......\documents\arduinodata\packages\arduino\tools\arm-none-eabi-gcc\7-2017q4\arm-none-eabi\include\c++\7.2.1\cmath:463:3: note: previous declaration 'constexpr float std::sqrt(float)'

sqrt(float __x)

^~~~

Test_compare_1:45:1: error: expected unqualified-id before '{' token

{

^

Test_compare_1:51:3: error: expected initializer before 'if'

if (!IMU.accelerationAvailable())

^~

Test_compare_1:54:2: error: expected unqualified-id before '{' token

{

^

Test_compare_1:57:1: error: expected unqualified-id before '{' token

{

^

Test_compare_1:72:2: error: expected unqualified-id before '{' token

{ if

^

Test_compare_1:93:1: error: expected declaration before '}' token

}

^

exit status 1

'HasMoved' cannot be used as a function

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

Looks like someone made a number of changes to the sketch. The ONLY change needed to the sketch I posted above is:
`bolean HasBeenStill = false;`
changes to:
`boolean HasBeenStill = false;`

All of the other changes break the sketch in various ways. Someone added a "bool HasMoved = false;" which conflicts with a function of the same name. Someone renamed the 'square()' function to 'sqrt()' which conflicts with the library function sqrt(). Someone mangled the 'HasMoved()' function very badly.

If you go back to the posted sketch and fix the one bad line you will have a much better chance of getting it to compile.

Thanks John,

Yes I was the bad programmer. Sorry. It does work but I am having issues integrating it with my other programs. They all work and tested with hardware.
I have two separate codes to incorporate. The one attacked below is just for being able see the IMU working and does nothing physically.
I have one other code which does all the physical functions, turning on motors, buzzers and leds.
Are you able to help me understand what I have done wrong in adding this part so then I should be able to add the other part. Thanks in advance.

I wanted to be able to turn this test code on when needed by a manual setting in the scope, boolean tester = false and true when needed. This saves unecessary code running for no use.
The third section of code does all the output functions and needs to run only when your code recognises the board as moving. I have read articles on FST and being able to combine multiple sketches but I am still a bit confused.

#include <Arduino_LSM9DS1.h>

const unsigned long StandingStillInterval = 2000;

const float MagnitudeThreshold = 123.456; // Determine by experiment
int degreesX = 0;
int degreesY = 0;
float x, y, z;
float oldX, oldY, oldZ;
boolean HasBeenStill = false;
boolean tester = true;
void setup()
{
Serial.begin(9600);
while (!Serial);
Serial.println("Started");

if (!IMU.begin())
{
Serial.println("Failed to initialize IMU!");
while (1);
}

Serial.print("Accelerometer sample rate = ");
Serial.print(IMU.accelerationSampleRate());
Serial.println("Hz");
}

void loop()
{
static unsigned long timeLastMoved = 0;

if (HasMoved())
timeLastMoved = millis();

if (millis() - timeLastMoved >= StandingStillInterval)
HasBeenStill = true;
}

float square(const float f)
{
return f * f;
}

boolean HasMoved()
{
if (!IMU.accelerationAvailable())
return false; // Can't tell if it has moved because data isn't available

float magnitudeOfChange = square(x - oldX) + square(y - oldY) + square(z - oldZ);

oldX = x;
oldY = y;
oldZ = z;

return magnitudeOfChange > MagnitudeThreshold;
}

void main(){ //I thought it would be best to separate the 3 codes
{ //loop, main, outcome for example
if (!IMU.accelerationAvailable())
return false; // Can't tell if it has moved because data isn't available

IMU.readAcceleration(x, y, z); //this test code will function when boolean = true;
} // set manually in scope
while boolean tester = true;
if(x > 0.3)
{
x = 100*x; //these just read and print degrees for x, y, z
degreesX = map(x, 0, 97, 0, 90);
Serial.print(" Tilting up "); //and orientation
Serial.print(degreesX);
Serial.println(" degrees");
delay(100);
}

if(x < -0.3)
{
x = 100*x;
degreesX = map(x, 0, -100, 0, 90);
Serial.print("Tilting down ");
Serial.print(degreesX);
Serial.println(" degrees");
delay(100);
}

if(y > 0.3)
{
y = 100*y;
degreesY = map(y, 0, 97, 0, 90);
Serial.print("Tilting left ");
Serial.print(degreesY);
Serial.println(" degrees");
delay(100);
}

if(y < -0.3)
{
y = 100*y;
degreesY = map(y, 0, -100, 0, 90);
Serial.print("Tilting right ");
Serial.print(degreesY);
Serial.println(" degrees");
delay(100);
}
return;
}

//while boolean HasBeenStill = true
//execute code here..........
// ??????????

Give this function a different name. If you call it 'main()' it will replace the part of the Arduino library that initializes the library and calls your setup() and loop() functions, making them useless.

This is not a valid statement. I can't tell what you intended to do. I think the closest valid statement makes no sense:
`while (tester == true) ;`
That means "while the variable 'tester' is set to 'true', repeat doing nothing." This will either do nothing (tester == false) or lock up the sketch and nothing further will be done. ?!?

You can't return a value from a function that returns 'void'.

Hi John,
I have been trying all day but just can't work it out.
The sketch compiles and uploads but does nothing.

Screenshot 80 is with my code in the sketch
Screenshot81 is with print STILL
Screenshot 82 your code

#include <Arduino_LSM9DS1.h>

const unsigned long StandingStillInterval = 2000;

const float MagnitudeThreshold = 123.456; // Determine by experiment
int degreesX = 0;
int degreesY = 0;
float x, y, z;
float oldX, oldY, oldZ;
boolean HasBeenStill = false;
int tester = 0; // set to 1 for test function to be active
void setup()
{
Serial.begin(9600);
while (!Serial);
Serial.println("Started");

if (!IMU.begin())
{
Serial.println("Failed to initialize IMU!");
while (1);
}

Serial.print("Accelerometer sample rate = ");
Serial.print(IMU.accelerationSampleRate());
Serial.println("Hz");
}

void loop()
{
static unsigned long timeLastMoved = 0;

if (HasMoved())
timeLastMoved = millis();

if (millis() - timeLastMoved >= StandingStillInterval)
HasBeenStill = true;
// Serial.print(" STILL ");

}

float square(const float f)
{
return f * f;
}

boolean HasMoved()
{
if (!IMU.accelerationAvailable())
return false; // Can't tell if it has moved because data isn't available

float magnitudeOfChange = square(x - oldX) + square(y - oldY) + square(z - oldZ);

oldX = x;
oldY = y;
oldZ = z;

return magnitudeOfChange > MagnitudeThreshold;
}

void testing(){
{
if (!IMU.accelerationAvailable())
//return false; // Can't tell if it has moved because data isn't available

//if (bool tester = 1)//I know this isn't how it should be coded but I haven't been able to get it right
(tester = 1); //(which is manually set to 1 above if needed otherwise it is set to 0 and sketch is off.
}

if (x > 0.3)
{
x = 100*x;
degreesX = map(x, 0, 97, 0, 90);
Serial.print(" Tilting up ");
Serial.print(degreesX);
Serial.println(" degrees");
delay(100);
}

if(x < -0.3)
{
x = 100*x;
degreesX = map(x, 0, -100, 0, 90);
Serial.print("Tilting down ");
Serial.print(degreesX);
Serial.println(" degrees");
delay(100);
}

if(y > 0.3)
{
y = 100*y;
degreesY = map(y, 0, 97, 0, 90);
Serial.print("Tilting left ");
Serial.print(degreesY);
Serial.println(" degrees");
delay(100);
}

if(y < -0.3)
{
y = 100*y;
degreesY = map(y, 0, -100, 0, 90);
Serial.print("Tilting right ");
Serial.print(degreesY);
Serial.println(" degrees");
delay(100);
}

//Here I need the function sketch here which will operate only
// while
//HasBeenStill = false;
// {Function sketch here}
// Sorry but I am unsure how to achieve it as it doesn't look like I achieved
// being able to turn on the testing sketch above
//while
//int tester = 1 (which is manually set to 1 in the sketch, if needed, otherwise it is set to 0
// and the testing sketch will be off.

}

Add `Serial.println(magnitudeOfChange);`" after that line to determine by experiment what the threshold should be.

But how do I add the second and third sketch in. As you can see above I have failed to be able to add the second one in. I am totally unsure what I am doing wrong. I know each sketch runs how it should by themselves.
.............
oldZ = z;

return magnitudeOfChange > MagnitudeThreshold;
}

void testing(){
{
if (!IMU.accelerationAvailable())
//return false; // Can't tell if it has moved because data isn't available

//if (bool tester = 1)//I know this isn't how it should be coded but I haven't been able to get it right
(tester = 1); //(which is manually set to 1 above if needed otherwise it is set to 0 and sketch is off.
}

if (x > 0.3)
............

degreesY = map(y, 0, -100, 0, 90);
Serial.print("Tilting right ");
Serial.print(degreesY);
Serial.println(" degrees");
delay(100);
}

//Here I need the function sketch here which will operate only
// while
//HasBeenStill = false;
// {Function sketch here}
// Sorry but I am unsure how to achieve it as it doesn't look like I achieved
// being able to turn on the testing sketch above
//while
//int tester = 1 (which is manually set to 1 in the sketch, if needed, otherwise it is set to 0
// and the testing sketch will be off.

}

I have combined the three separate sketches calling yours void loop, the second void sight, third void testing. You will see in the excerpt below there is an issue with each one the same - void sight() {
The other is now that the other sketches are added, 'HasMoved' was not declared in this scope, which wasn't an issue when it was just your code. Each separate code is intended to run by itself. Your sketch is to test movement and say 'Not Moving'. When Not Moving is declared, then the second sketch, which does all the external functions, LEDS, motor, buzzer. This code will run until, your code declares 'No Movement'.
The third sketch is purely standalone from the rest, it is to be manually turned on and off by changing a bool or int (not sure which is best to use) (int tester = 0) from 1 (on) to 0 (off) and just prints all IMU ACC and GYRO readings.

Errors:
Test_compare_5:130:14: error: a function-definition is not allowed here before '{' token
void sight() {
^
Test_compare_5:258:3: error: expected initializer before 'while'
while (bool T == 1) //(which is manually set to 1 above if needed otherwise it is set to 0 and sketch is off.
^~~
exit status 1
'HasMoved' was not declared in this scope
[8:08 PM]
I don't understand why the HasMoved is saying not declared in scope, as when the code runs on its own the fault isn't there.