Mac Lobdell / Mbed 2 deprecated FXOS8700CQ_Int_example

Dependencies:   FXOS8700CQ mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 #include "FXOS8700CQ.h"
00003 
00004 DigitalOut led(LED_RED);
00005 InterruptIn accel_int_pin(PTC13);  //FRDM-K64F
00006 Serial pc(USBTX, USBRX);
00007 FXOS8700CQ fxos(PTE25, PTE24, FXOS8700CQ_SLAVE_ADDR1); //FRDM-K64F
00008 
00009 uint8_t motion_detected;
00010 
00011 void accel_interrupt(void)
00012 {
00013        led = 0;  //turn led on
00014         motion_detected = 1;
00015        fxos.clear_int();
00016 }
00017 
00018 int main()
00019 {
00020     pc.baud(9600);
00021     
00022     pc.printf("ready to rock!\n");
00023    
00024     motion_detected = 0;
00025     accel_int_pin.fall(&accel_interrupt);
00026     accel_int_pin.mode(PullUp);
00027        
00028     led = 1;  //turn led off
00029 
00030     fxos.config_int();      //enabled interrupts from accelerometer
00031     fxos.config_feature();  //turn on motion detection
00032     fxos.enable();          //enable accelerometer
00033 
00034     while (true) {
00035     
00036         if(motion_detected == 1)
00037         {
00038            wait(1);
00039         
00040             led = 1;  //turn led off
00041             motion_detected = 0;
00042         
00043             sleep();            
00044         }
00045    }
00046 }