Device to measure angle and get IMU measurements.

Dependencies:   mbed commands BLE_API nRF51822

Committer:
dkester
Date:
Wed May 20 11:45:38 2015 +0000
Revision:
1:b44bd62c542f
Parent:
0:1c5088dae6e1
Child:
2:871b5efb2043
update;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
dkester 0:1c5088dae6e1 1 #include "mbed.h"
dkester 0:1c5088dae6e1 2 #include "Sensors.h"
dkester 1:b44bd62c542f 3 #include "Storage.h"
dkester 0:1c5088dae6e1 4
dkester 0:1c5088dae6e1 5 Serial pc(USBTX, USBRX);
dkester 0:1c5088dae6e1 6
dkester 0:1c5088dae6e1 7 DigitalOut led(p21);
dkester 0:1c5088dae6e1 8 InterruptIn button(p23);
dkester 0:1c5088dae6e1 9 Ticker ticker;
dkester 0:1c5088dae6e1 10
dkester 0:1c5088dae6e1 11 void printSensors(void)
dkester 0:1c5088dae6e1 12 {
dkester 0:1c5088dae6e1 13 Sensors* sensors = Sensors::getInstance();
dkester 0:1c5088dae6e1 14 sensors->updateIMU();
dkester 0:1c5088dae6e1 15 pc.printf("angle: %.2f\n", sensors->getAngle());
dkester 0:1c5088dae6e1 16 pc.printf("accelerometer x: %d y: %d z: %d\n",sensors->getAccelX(),sensors->getAccelY(),sensors->getAccelZ());
dkester 0:1c5088dae6e1 17 pc.printf("temperature: %.2f\n", sensors->getTemp());
dkester 0:1c5088dae6e1 18 pc.printf("gyroscope x: %d y: %d z: %d\n\n",sensors->getGyroX(),sensors->getGyroY(),sensors->getGyroZ());
dkester 0:1c5088dae6e1 19 }
dkester 0:1c5088dae6e1 20
dkester 0:1c5088dae6e1 21 void buttonInt( void )
dkester 0:1c5088dae6e1 22 {
dkester 0:1c5088dae6e1 23 led = !led;
dkester 0:1c5088dae6e1 24 }
dkester 0:1c5088dae6e1 25
dkester 1:b44bd62c542f 26 void motion(void)
dkester 1:b44bd62c542f 27 {
dkester 1:b44bd62c542f 28 //Sensors::getInstance()->setDMP(0x11);
dkester 1:b44bd62c542f 29 pc.printf("Checking motion -> ");
dkester 1:b44bd62c542f 30 if (Sensors::getInstance()->checkDMP()) {
dkester 1:b44bd62c542f 31 led = 1;
dkester 1:b44bd62c542f 32 pc.printf("MOTION! ");
dkester 1:b44bd62c542f 33 } else {
dkester 1:b44bd62c542f 34 led = 0;
dkester 1:b44bd62c542f 35 }
dkester 1:b44bd62c542f 36
dkester 1:b44bd62c542f 37 pc.printf("int enable: %d, ",Sensors::getInstance()->readRegister(0x38));
dkester 1:b44bd62c542f 38 pc.printf("th: %d, ",Sensors::getInstance()->readRegister(0x1f));
dkester 1:b44bd62c542f 39 pc.printf("status: %d ", Sensors::getInstance()->readRegister(0x61));
dkester 1:b44bd62c542f 40 pc.printf("int status: %d\n",Sensors::getInstance()->readRegister(0x3a));
dkester 1:b44bd62c542f 41
dkester 1:b44bd62c542f 42 printSensors();
dkester 1:b44bd62c542f 43
dkester 1:b44bd62c542f 44 }
dkester 1:b44bd62c542f 45
dkester 1:b44bd62c542f 46 void memory(void)
dkester 1:b44bd62c542f 47 {
dkester 1:b44bd62c542f 48 pc.printf("%d\n", Storage::getInstance()->setup());
dkester 1:b44bd62c542f 49 }
dkester 1:b44bd62c542f 50
dkester 0:1c5088dae6e1 51 int main(void)
dkester 0:1c5088dae6e1 52 {
dkester 0:1c5088dae6e1 53 pc.baud(19200);
dkester 0:1c5088dae6e1 54 led = 0;
dkester 1:b44bd62c542f 55
dkester 1:b44bd62c542f 56 Sensors::getInstance()->setDMP(0x1a);
dkester 1:b44bd62c542f 57
dkester 1:b44bd62c542f 58 ticker.attach(&motion,0.1);
dkester 1:b44bd62c542f 59 //button.fall(&buttonInt);
dkester 0:1c5088dae6e1 60
dkester 0:1c5088dae6e1 61 while(true) {
dkester 1:b44bd62c542f 62 wait(0.001);
dkester 0:1c5088dae6e1 63 }
dkester 0:1c5088dae6e1 64 }
dkester 0:1c5088dae6e1 65
dkester 0:1c5088dae6e1 66