123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778 |
-
-
- #include <unistd.h>
- #include <iostream>
- #include <signal.h>
- #include "adxl335.h"
-
- using namespace std;
-
- int shouldRun = true;
-
- void sig_handler(int signo)
- {
- if (signo == SIGINT)
- shouldRun = false;
- }
-
-
- int main ()
- {
- signal(SIGINT, sig_handler);
-
-
-
- upm::ADXL335* accel = new upm::ADXL335(0, 1, 2);
-
- cout << "Please make sure the sensor is completely still. Sleeping for"
- << " 2 seconds." << endl;
- sleep(2);
- cout << "Calibrating..." << endl;
-
- accel->calibrate();
-
- while (shouldRun)
- {
- int x, y, z;
- float aX, aY, aZ;
-
- accel->values(&x, &y, &z);
- cout << "Raw Values: X: " << x << " Y: " << y << " Z: " << z << endl;
-
- accel->acceleration(&aX, &aY, &aZ);
- cout << "Acceleration: X: " << aX << "g" << endl;
- cout << "Acceleration: Y: " << aY << "g" << endl;
- cout << "Acceleration: Z: " << aZ << "g" << endl;
- cout << endl;
-
- usleep(200000);
- }
-
-
- cout << "Exiting" << endl;
-
- delete accel;
- return 0;
- }
|